andioop@programming.dev to Programming Horror@programming.devEnglish · edit-29 months agoGod I wish there was an easier way to do thisprogramming.devimagemessage-square53fedilinkarrow-up1214arrow-down121
arrow-up1193arrow-down1imageGod I wish there was an easier way to do thisprogramming.devandioop@programming.dev to Programming Horror@programming.devEnglish · edit-29 months agomessage-square53fedilink
minus-squareMac@programming.devlinkfedilinkarrow-up23·edit-29 months agowho needs modulo when you can get less characters out of while (number > 1) { number -= 2; } return number; very efficient edit: or theres the trusty iseven api
minus-squareNullPointer@programming.devlinkfedilinkarrow-up9·9 months agohere is somewhat less: return (number % 2) == 0;
minus-squareMuchPineapples@lemmy.worldlinkfedilinkarrow-up7·edit-29 months agoThis is the way. Modulo takes too long to compute, bitwise compare should be a lot faster. return !(number & 0x1);
minus-squarerecursive_recursion [they/them]@programming.devlinkfedilinkEnglisharrow-up4·edit-29 months agooh shit yo this comment chain is pretty awesome, I learned a lot from this thanks!
minus-squarehuf [he/him]@hexbear.netlinkfedilinkEnglisharrow-up4·9 months agojust check the last bit jesus christ, what is it with these expensive modulo operations?! return !(n&1);
minus-squareperviouslyiner@lemm.eelinkfedilinkEnglisharrow-up2·9 months agoare the negative numbers all even?
who needs modulo when you can get less characters out of
while (number > 1) { number -= 2; } return number;
very efficient
edit: or theres the trusty iseven api
here is somewhat less:
return (number % 2) == 0;
return !(number & 1);
This is the way. Modulo takes too long to compute, bitwise compare should be a lot faster.
return !(number & 0x1);
oh shit yo
this comment chain is pretty awesome, I learned a lot from this thanks!
just check the last bit jesus christ, what is it with these expensive modulo operations?!
return !(n&1);
are the negative numbers all even?
Yes