diff --git a/language/types/float.xml b/language/types/float.xml index 2fc22d25b1..0230d987d7 100644 --- a/language/types/float.xml +++ b/language/types/float.xml @@ -66,10 +66,10 @@ EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM}) - So never trust floating number results to the last digit, and never compare - floating point numbers for equality. If higher precision is necessary, - the arbitrary precision math functions and - gmp functions are available. + So never trust floating number results to the last digit, and do not compare + floating point numbers directly for equality. If higher precision is + necessary, the arbitrary precision math functions + and gmp functions are available. @@ -88,6 +88,43 @@ EXPONENT_DNUM [+-]?(({LNUM} | {DNUM}) [eE][+-]? {LNUM}) + + + Comparing floats + + + As noted in the warning above, testing floating point values for equality is + problematic, due to the way that they are represented internally. However, + there are ways to make comparisons of floating point values that work around + these limitations. + + + + To test floating point values for equality, an upper bound on the relative + error due to rounding is used. This value is known as the machine epsilon, + or unit roundoff, and is the smallest acceptable difference in calculations. + + + + + $a and $b are equal to 5 digits of + precision. + + + +]]> + + + NaN