nave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · 1 year agoI wishi.imgur.comimagemessage-square169fedilinkarrow-up1866arrow-down115
arrow-up1851arrow-down1imageI wishi.imgur.comnave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · 1 year agomessage-square169fedilink
minus-square257m@sh.itjust.workslinkfedilinkarrow-up5·edit-21 year agonumber % 2 == 0 and (number & 0b1) == 0 Are the only sane ways to do this. No need to floor. Although If its C and you can’t modulo floats then (number/2 == floor(number/2))
minus-squarehomura1650@lemmy.worldlinkfedilinkarrow-up1·1 year agoIf you are using floats, you really do not want to have an isEven function …
minus-square257m@sh.itjust.workslinkfedilinkarrow-up1·1 year agoWhats the alternative a macro? An inline function is perfectly fine for checking if a nunber is even. Compiler will probably optimize it to a single and instruction.
minus-squarehomura1650@lemmy.worldlinkfedilinkarrow-up2·edit-21 year agoNo. The alternative is to not use a float. Testing if a float is even simply does not make sense. Even testing two floats for equality rarely makes sense. What is the correct output of isEven((.2 + .4) ×10) Hint: (.2 + .4) x 10 != 6
number % 2 == 0 and (number & 0b1) == 0
Are the only sane ways to do this. No need to floor. Although If its C and you can’t modulo floats then (number/2 == floor(number/2))
If you are using floats, you really do not want to have an isEven function …
Whats the alternative a macro? An inline function is perfectly fine for checking if a nunber is even. Compiler will probably optimize it to a single and instruction.
No. The alternative is to not use a float. Testing if a float is even simply does not make sense.
Even testing two floats for equality rarely makes sense.
What is the correct output of isEven((.2 + .4) ×10)
Hint: (.2 + .4) x 10 != 6