3 ms·
Numbers are IEEE 754 floating point. It's a separate standard which they just had to reference. I do agree that it's bad style, because it doesn't clearly comm
by ahoge 14y ago
Numbers are IEEE 754 floating point. It's a separate standard which they just had to reference.
I do agree that it's bad style, because it doesn't clearly communicate the intention. If you want something that returns true or false, you should return true or false.
- voyou 14y agoYeah, but -1 isn't represented in IEEE 754 floating point as all bits one, is it? The ECMAScript standard specifies that the bitwise operators work by first converting their arguments to 32-bit signed integers, but at least how I read it, it doesn't actually say anything about how these 32-bit signed integers are represented (which implies that they continue to be represented as IEEE 754, which isn't how browsers behave, and wouldn't be very useful).
- deafbybeheading 14y agoIt's not. And you're right, the spec isn't clear. On the other hand, the current behavior of pretending the bits are arranged in 32-bit two's-complement fashion for appropriate integer values when applying bitwise operators is really the only sensible interpretation (especially since a 64-bit float can represent all 32-bit ints).