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

+0.0 vs. -0.0 vs. EQL



The Laser manual explains that the EQL function compares two numbers of the
same type using =.  This definition has been found wanting in the face of
"negative zero", which a Common Lisp is allowed to support.  

(= +0.0 -0.0) => T according to the IEEE standard, and thus it follows that 
(EQUALP +0.0 -0.0) => T as well.  It is also clear that (EQ +0.0 -0.0) => NIL.
The question is what about (EQL +0.0 -0.0) and (EQUAL +0.0 -0.0)?

EQUAL is defined to act like EQL on numbers (remember that
(EQUAL 3 3.0) => NIL in Common Lisp), so these two issues stand together.

A strict reading of the Laser manual, which currently says that two numbers
of the same type are EQL just in case they are =, would lead one to
conclude that (EQL +0.0 -0.0) => T.  Unfortunately this violates the
principles behind the original design of EQL.

We added EQL to Common Lisp because we felt that certain pairs of otherwise
indistinguishable objects failed to be EQ only for implementation dependent
reasons.  For example, two "different" 1000000000's on the CADR Lisp
Machines are possible only because of the word size of the machine.  On a
3600 Lisp Machine all such billions are EQ, but all trillions are not.  But
on both machines all billions, and all trillions, are EQL.  We might define
EQL by saying that two objects are EQL just in case there is a conceivable
Common Lisp implementation in which those "same" two objects would have to
be EQ.

That definition of EQL is in complete agreement with the one in the Laser
manual until one faces minus zero.  In no conceivable Common Lisp
implementation is -0.0 EQ to +0.0 (some implementations lack it altogether,
but that isn't the same thing).  EQL objects are intended to be
indistinguishable except perhaps by using EQ.  Yet -0.0 and +0.0 are
distinguishable, by PRINTing them, or by use of the FLOAT-SIGN function,
for example.

Additionally, having -0.0 be EQUAL to +0.0 would introduce a new twist into
the behavior of EQUAL.  +0.0 and -0.0 would become the ONLY pair of objects
that have distinct printed representations, yet are considered EQUAL.

I think we must conclude that the Laser manual is simply being imprecise
when it explains that EQL uses = to compare numbers, and that in fact we
want it to be the case that (EQL +0.0 -0.0) => NIL.