[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Numerical Comparison: "required coercions"

Section 12.3 of CLtL, when speaking of the numerical comparison
functions -- =, /=, <, etc. --  says that each one works on all types 
of numbers (unless otherwise indicated), and that any "required
coercions" are performed when the arguments are of different type.

Which kind of coercion is appropriate for the following:
    (=  314159265358979383256 		;about 20 digits of pi, as integer
	3.1415925E20			; pi * 1.0E20, off by one lsb maybe
	314159265358979383250		;a different "20 digits" of pi

Some implementations I've looked at appear to do the coercion by the
usual rule of float-contagion.  I believe this to be sub-optimal in
that it prevents "=" from being a transitive operation (because
floating the two integers above will typically "lose" information).
Wouldn't it make more sense to consider the phrase "required coercions"
to mean that when a rational is compared to a float, it is the float
that is "coerced" rather than the rational?

In short, I don't think the original intent was that "=" be a "fuzzy" 
operation.  Rather it should be mathematically consistent, even if the 
interpretation of "precision" for floating-point numbers is open to 

-- JonL --