2 ms·
> converting the long value 0x7fffffffffffffff to the nearest double value: 0x8000000000000000 From what I understand from the spec it should be the nearest in
by raverbashing 7y ago
> converting the long value 0x7fffffffffffffff to the nearest double value: 0x8000000000000000
From what I understand from the spec it should be the nearest in value, no? Not the nearest in memory representation.
- eMSF 7y agoWho said anything about memory representations? The language spec (or at least a summary of it) is linked in the article, and it is pretty loose: nearest higher or nearest lower, chosen by the implementation (regardless of which is nearer). IEEE double-precision float cannot store LONG_MAX (which is 2^63-1 with 8-byte longs) precisely, so it gets converted to 2^63; which you cannot cast back to a long, because it doesn't fit (resulting in undefined behaviour).