Comment on I wish
257m@sh.itjust.works 1 year agonumber % 2 == 0 and // If integer (number & 0b1) == 0
Are the only sane ways to do this. No need to floor.
Comment on I wish
257m@sh.itjust.works 1 year agonumber % 2 == 0 and // If integer (number & 0b1) == 0
Are the only sane ways to do this. No need to floor.
homura1650@lemmy.world 1 year ago
If you are using floats, you really do not want to have an isEven function …
257m@sh.itjust.works 1 year ago
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.
homura1650@lemmy.world 1 year ago
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.
257m@sh.itjust.works 1 year ago
It does if it dosen’t have a decimal. If it has decimal then it automatically isn’t and the function will return false.