> return Double.longBitsToDouble(
> Double.doubleToRawLongBits(value) & 0x7fffffffffffffffL);
Technically, this will change NaN values into different ones. > return Double.longBitsToDouble(
> Double.doubleToRawLongBits(value) & 0x7fffffffffffffffL);
Technically, this will change NaN values into different ones.I don't know if anything does but it could certainly be useful. Imagine if a NaN said exactly where in your code it was created.
I'm not sure how that would be useful. A debugger should have better ways of identifying NaN creation and I don't see anything else using a pointer to code in production. It seems cool though.
It would also lead to problems like: x = 5.0 * y y is NaN with some address as the NaN type. NaN * 5.0 => NaN. Which address (the original or the * 5.0 line) is used?
If you log it, you could trace it back to the line of code at your leisure.
> It would also lead to problems like: x = 5.0 * y y is NaN with some address as the NaN type. NaN * 5.0 => NaN. Which address (the original or the * 5.0 line) is used?
I don't mean to be rude, but isn't the answer to that question extremely obvious?
The behavior that's much more useful and enshrined in the IEEE spec is that you keep the original NaN.
> The behavior that's much more useful and enshrined in the IEEE spec is that you keep the original NaN.
I didn't realize it was in the spec. I just checked, and you're right! That does however seem strange - X was never set by operation NNNN, Y was.
> That does however seem strange - X was never set by operation NNNN, Y was.
If you're using NaN payloads, it would almost never be helpful for 95% of your NaNs to turn into a generic "used a NaN in arithmetic" version.