plasmacel plasmacel - 2 years ago 89
C++ Question

Invertability of IEEE 754 floating-point division

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
x == 1.0 / y
, i.e.
can be restored precisely bit by bit?

The cases when
are obvious exceptions.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download