Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.lisp Subject: Float/rational comparison Message-ID: <888@cresswell.quintus.UUCP> Date: 20 Apr 88 06:51:57 GMT Organization: Quintus Computer Systems, Mountain View, CA Lines: 50 There appears to be a contradiction between pages 197 and 194 of "Common Lisp the Language". Page 197 says very clearly that If the sequence of arguments satisfies a certain condition: = all the same /= all different < monotonically increasing ... then the predicate is true, and otherwise is false. It later says: With two arguments, these functions perform the usual arithmetic comparison tests. I took this to mean that any two non-complex numbers were to be ordered by these predicates as if they were injected into the real number line and compared there according to the rules of real arithmetic. For example, one could compare a rational number N/D with a floating point number F by comparing N with D*F, which can be computed exactly. However, today someone pointed out to me that page 194 says When rational and floating-point numbers are compared or ^^^^^^^^ combined by a numerical function, the rule of floating-point contagion is followed: when a rational meets a floating-point number, the rational is first converted to a floating-point number of the same format. Now, I haven't worked out the details, but it seems to me that if a rational number is converted to the closest floating-point number of the right format, this can cause (< Rat Flt) (> Rat Flt) or (/= Rat Flt) to fail when it should have succeeded according to "the usual arithmetic comparison tests" and can cause (<= Rat Flt) (>= Rat Flt) or (= Rat Flt) to succeed when it should have failed. For example, (= 1000000000000000000000000000000/2000000000000000000000000000001 0.5) might succeed. If the rational number is converted to floating-point by converting N and D separately and doing a floating-point division, any result is possible. So, (1) what _do_ Common Lisp systems do? (2) what _should_ they do? There is a similar question with respect to comparison of floating-point numbers of different precision. Page 193 says that When an operation combines a short floating-point number with a long one, the result will be a long floating-point number. but I can't find anything to say what conversion is done when a long and a short floating-point number are compared.