to determine whether x is odd or even in isOdd. Doing the self-modification is left as an exercise.
This is good defensive programming. It avoids doing a tricky division by 2.0 that might be buggy (I don’t think https://en.wikipedia.org/wiki/Pentium_FDIV_bug was affected, but who knows what other FPUs do?)
The initial function should start with checking for special cases NaN, infinities, 0 and -0, then do (may not be valid JavaScript)
to handle cases over 2^54 or below -2^54, then do to determine whether x is odd or even in isOdd. Doing the self-modification is left as an exercise.This is good defensive programming. It avoids doing a tricky division by 2.0 that might be buggy (I don’t think https://en.wikipedia.org/wiki/Pentium_FDIV_bug was affected, but who knows what other FPUs do?)