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 todays pop culture with that of forty years ago: from High Noon to Robocop is a long descent.”
—Charles Krauthammer (b. 1950)
“All ye poets of the age,
All ye witlings of the stage,
Learn your jingles to reform,
Crop your numbers to conform.
Let your little verses flow
Gently, sweetly, row by row;
Let the verse the subject fit,
Little subject, little wit.
Namby-Pamby is your guide,
Albions joy, Hibernias pride.”
—Henry Carey (1693?1743)