3 ms·
> you can determime whether a number is odd or even with a modulo Or you could check the lowest bit. Better to abstract away from that implementation decision.
by layer8 5y ago
> you can determime whether a number is odd or even with a modulo
Or you could check the lowest bit. Better to abstract away from that implementation decision. ;)
- smoldesu 5y agoThat too, but I get the feeling those kinds of operations aren't in Javascript's standard library...
- layer8 5y ago`my_number & 1 == 0` works.
- c0wb0yc0d3r 5y agoJavaScript does have bitwise operators. Something I was surprised by was that numbers are stored as 64 bit while all of the bitwise operators operate on 32 but numbers. This means that every operation results in a number conversion first.
- recursive 5y agoNot just 64 bit. 64 bit floating point. You can't just get the "low bit". You need to take the exponent into account to figure out which bit of the mantissa to grab. It's intrinsically more computationally difficult than is-odd on a real integer.