Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

like image 418
plasmacel Avatar asked Aug 01 '16 22:08

plasmacel


People also ask

How does the IEEE 754 standard represent floating-point numbers?

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.

Why do computers mess up floating point math?

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.


1 Answers

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

like image 84
Pascal Cuoq Avatar answered Sep 27 '22 18:09

Pascal Cuoq