Comparison tolerance cannot be set; it is fixed at 1e-13.
It is used in both conversion of floating-point numbers to integers and explicit comparisons, as in Equal to, Match, and Find.
The fundamental notion is to put a band around one of the comparands and see whether the other comparand falls within that band. Consider x=y, for instance. Roughly speaking, the equality holds if x is within (without tolerance, of course) the interval from y«1-1e-13 to y«1+1e-13. More precisely, the difference between the comparands must be less (without tolerance) than the tolerance times the smaller of them in absolute value: |x-y must be less than 1e-13«(|x)Ä|y. Because multiplication is involved, only zero is equal to zero within the comparison tolerance.
Comparison tolerance applies only to floating-point comparisons. The largest magnitude that can be represented in A+ in integer type is 2*31, which is |¢2*31. That times the tolerance, i.e., 1e-13«2*31, is only about 0.0002. Thus the tolerance could not have any effect on comparisons between two integers.
When examining the effect, or apparent effect, of comparison tolerance, you must take into account the printing precision (which may make two unequal numbers look equal) and the fact that the Equal to function itself uses comparison tolerance. As an intolerant check for equality of a and b, you can use 0=a-b.
Consider numbers shown in an example above, where their difference was approximated as 2:
12345678912345679 = 12345678912345678
1
Clearly, Equal to uses comparison tolerance to arrive at the result: A+ disregards the insignificant (and in fact inexact) difference it finds between them. But doesn't comparison tolerance apply only to floating-point numbers? Yes, but there are several ways to enter numbers for representation in floating point: e.g., with a decimal point (99. or 3.14, for instance), in exponential notation (6.023e-23), and with too many digits for it to be represented internally as an integer (12345678912345679). Each number entered is converted to its internal representation before anything else is done with it.
Comparison tolerance is used in:
- Ceiling, Floor, and Residue;
- Equal to, Greater than, Greater than or Equal to, Less than, Less than or Equal to, and Not equal to;
- Find, Match, and Member;
and no other functions.
When two floating-point numbers are equal within the comparison tolerance, they are called tolerably equal. This term is also used in a more general way, to mean equal within the tolerance for floating-point numbers and strictly equal where no floating-point number is involved.
Note that the term restricted whole number, as discussed above and in "Restricted Whole Numbers", involves even more toleration, since it includes numbers whose absolute value is less than 1e-13, whereas zero is not tolerably equal to any nonzero number.