...
Note that conversions from float
to double
can also lose information about the overall magnitude of the converted value (see rule NUM53-J. Use the strictfp modifier for floating-point calculation consistency across platforms for additional information).
...
This method could have unexpected results because of the loss of precision. In FP-strict mode, values of type float
have 23 mantissa bits, a sign bit, and an 8-bit exponent (see rule NUM53-J. Use the strictfp modifier for floating-point calculation consistency across platforms for more information about FP-strict mode). The exponent allows type float
to represent a larger range than that of type int
. However, the 23-bit mantissa means that float
supports exact representation only of integers whose representation fits within 23 bits; float
supports only approximate representation of integers outside that range.
...
Bibliography
[JLS 2005] | |
[Seacord 2015] | NUM13-J. Avoid loss of precision when converting primitive integers to floating-point LiveLesson |
...