3 ms·
For doubles you don't even need to take over NaN. There is a huge range of unused bit patterns in IEEE floats that could be used instead.
by jnordwick 9y ago
For doubles you don't even need to take over NaN. There is a huge range of unused bit patterns in IEEE floats that could be used instead.
- kodablah 9y agoI don't think the JVM guarantees the bit pattern will be preserved when passing it around. I know this is the case for NaNs where I have experienced the bit pattern change [0]. 0 - https://stackoverflow.com/questions/43129365/javas-math-rint-not-behaving-as-expected-when-using-nan https://stackoverflow.com/questions/43129365/javas-math-rint...
- jnordwick 9y agoIt would be really depressing if java normalized NaNs, but i wouldn't put it past some author thinking it was a good idea.
- kodablah 9y agoIt's not that they normalize them per se, it's just that NaN bit patterns are mostly undefined behavior. I think the JVM spec (or JLS, I forget) implies that you can't really rely on the NaN bit patterns being retained. Double.longBitsToDouble mentions that some processors might not return a double in the same bit pattern as passed.
- spc476 9y agoSuch as? Reading up on the format [1] it seems that every value is defined, which includes a ton of possible NaN values [2]. [1] https://en.wikipedia.org/wiki/Double-precision_floating-point_format https://en.wikipedia.org/wiki/Double-precision_floating-poin... [2] If you read the actual IEEE 754 spec, one suggested use for a NaN value is the address of the offending instruction(s); otherwise there is no defined pattern for NaNs in IEEE-754.
- jnordwick 9y ago> it seems that every value is defined, > there is no defined pattern for NaNs ? I was referring to using a NaN value without a zeroed mantissa.
- spc476 9y ago? A NaN is defined as the maximum exponent (all ones) and a non-zero mantissa. By "no defined pattern for NaNs" I meant there was no fixed value for a single NaN.