Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.lisp Subject: Re: Float/rational comparison Message-ID: <891@cresswell.quintus.UUCP> Date: 22 Apr 88 03:47:23 GMT References: <888@cresswell.quintus.UUCP> <20062@think.UUCP> Organization: Quintus Computer Systems, Mountain View, CA Lines: 24 In article <20062@think.UUCP>, barmar@think.COM (Barry Margolin) writes: > The reason for floating-point contagion is that floating point numbers > are not considered exact, while rationals are. It is therefore not > proper to automatically convert floats to rationals, because you would > be fooling yourself if you believe that the float actually represented > that exact rational. This is fair enough when one is talking about a computation delivering numeric results, such as (+ float rational). But a comparison doesn't do that. As I attempted to sketch in my first message on this topic, it is possible to do an exact rational/float comparison without fully converting the float to a rational. If we argue that a float X represents the interval {X-somewhat,X+somewhat} --I want to be vague about the boundaries--then converting a rational to the nearest float and doing a float gives you a spurious "=" comparison only if the rational is in that interval, so this result makes some sense. But my interest is not so much in rational/float comparison as such, but in having comparison functions which satisfy the axioms of a total order. It bothers me that there can be numbers X, Y, Z such that (= X Y) and (= Y Z) but (< X Z) so that a sorting routine could be "provably correct" and nevertheless deliver wrong answers.