What is the invertability of the IEEE 754 floating-point division? I mean is it guaranteed by the standard that if double y = 1.0 / x
then x == 1.0 / y
, i.e. x
can be restored precisely bit by bit?
The cases when y
is infinity
or NaN
are obvious exceptions.
IEEE Standard 754 floating point is the most common representation today for real numbers on computers, including Intel-based PC's, Macs, and most Unix platforms. This is as simple as the name. 0 represents a positive number while 1 represents a negative number.
Because JavaScript uses the IEEE 754 standard for Math, it makes use of 64-bit floating numbers. This causes precision errors when doing floating point (decimal) calculations, in short, due to computers working in Base 2 while decimal is Base 10.
Yes, there are IEEE 754 double-precision(*) values x
that are such x != 1.0 / (1.0 / x)
.
It is easy to build an example of a normal value with this property by hand: the one that's written 0x1.fffffffffffffp0
in C99's hexadecimal notation for floating-point values is such that 1.0 / (1.0 / 0x1.fffffffffffffp0) == 0x1.ffffffffffffep0
. It was natural to expect 0x1.fffffffffffffp0
to be a counter-example because 1.0 / 0x1.fffffffffffffp0
falls at the beginning of a binade, where floating-point numbers are less dense, so a larger relative error had to happen on the innermost division. More precisely, 1.0 / 0x1.fffffffffffffp0
falls just above the midpoint between 0.5
and its double-precision successor, so that 1.0 / 0x1.fffffffffffffp0
is rounded up to the successor of 0.5, with a large relative error.
In decimal %.16e
format, 0x1.fffffffffffffp0
is 1.9999999999999998e+00
and 0x1.ffffffffffffep0
is 1.9999999999999996e+00
.
(*) there is no reason for the inverse function to have the property in the question for any of the IEEE 754 format
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With