andioop to Programming HorrorEnglish · edit-21 year agoGod I wish there was an easier way to do thisimagemessage-square55fedilinkarrow-up1216arrow-down121
arrow-up1195arrow-down1imageGod I wish there was an easier way to do thisandioop to Programming HorrorEnglish · edit-21 year agomessage-square55fedilink
minus-squareNullPointerlinkfedilinkarrow-up9·1 year agohere is somewhat less: return (number % 2) == 0;
minus-squareMuchPineapples@lemmy.worldlinkfedilinkarrow-up8·edit-21 year 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]AlinkfedilinkEnglisharrow-up5·edit-21 year agooh shit yo this comment chain is pretty awesome, I learned a lot from this thanks!
minus-squarehuf [he/him]@hexbear.netlinkfedilinkEnglisharrow-up4·1 year agojust check the last bit jesus christ, what is it with these expensive modulo operations?! return !(n&1);
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);