When the source text "6.25e-05" is interpreted as a decimal digit and converted to double, it is not accurately represented, since floating point values ββhave limited precision, and each bit has a value that is a force of two, not a decimal digit. The IEEE 754 double-precision value that is closest to 6.25e-5 is 6.25000000000000013010426069826053208089433610439300537109375e-05 or in hexadecimal floating point 0x1.0624dd2f1a9fcp-14.
When the converse is taken, the exact mathematical result is again not exactly representable, so it needs to be rounded up again. The closest double precision value is 16000 or 0x1.f4p + 13.
The C ++ standard allows implementations to evaluate floating point expressions with greater precision than the nominal type requires. Some implementations use advanced precision, in particular, the 80-bit version of Intel's floating point, which has 64-bit significance. (Regular double precision has 53-bit significance.) In this advanced precision, the inverse is 0xf.9ffffffffffff89p + 10 or 15999.99999999999966693309261245303787292949957275390625.
Obviously, when the result is truncated to an integer with extended precision, the result is 15999.
Rounding a double double result will result in 16000. (You can do this with an explicit cast to double, you do not need to assign an intermediate value to the double object.)
Eric Postpischil
source share