IEEE 754-1985 - Comparing Floating-point Numbers

Comparing Floating-point Numbers

Every possible bit combination is either a NaN or a number with a unique value in the affinely extended real number system with its associated order, except for the two bit combinations negative zero and positive zero, which sometimes require special attention (see below). The binary representation has the special property that, excluding NaNs, any two numbers can be compared like sign and magnitude integers (although with modern computer processors this is no longer directly applicable): if the sign bit is different, the negative number precedes the positive number (except that negative zero and positive zero should be considered equal), otherwise, relative order is the same as lexicographical order but inverted for two negative numbers; endianness issues apply.

Floating-point arithmetic is subject to rounding that may affect the outcome of comparisons on the results of the computations.

Although negative zero and positive zero are generally considered equal for comparison purposes, some programming language relational operators and similar constructs might or do treat them as distinct. According to the Java Language Specification, comparison and equality operators treat them as equal, but Math.min and Math.max distinguish them (officially starting with Java version 1.1 but actually with 1.1.1), as do the comparison methods equals, compareTo and even compare of classes Float and Double.

Read more about this topic:  IEEE 754-1985

Famous quotes containing the words comparing and/or numbers:

    There is no comparing the brutality and cynicism of today’s pop culture with that of forty years ago: from High Noon to Robocop is a long descent.
    Charles Krauthammer (b. 1950)

    I had a feeling that out there, there were very poor people who didn’t have enough to eat. But they wore wonderfully colored rags and did musical numbers up and down the streets together.
    Jill Robinson (b. 1936)