[r6rs-discuss] [Formal] Unclear how equality predicates behave on NaN

From: Per Bothner <per>
Date: Wed Sep 20 02:00:25 2006

William D Clinger wrote:
> I am posting this as an individual member of the Scheme
> community. I am not speaking for the R6RS editors, and
> this message should not be confused with the editors'
> eventual formal response.
>
> Per Bothner wrote:
>> 9.10.2 Numerical operations p 39
>> Arithmetic operations
>> = explicitly specifies the behavior for +inf.0 and -inf.0, but not
>> for +nan.0. Implicitly, if any operand is +nan.0, then the result
>> should be #f, and this follows IEEE-754. However, it should be
>> stated explicitly.
>
> There are examples of this in section 16.4, but
> it would be nice to have an example in 9.10.2 also.

Also, while it is reasonable to assume to if (fl= +nan.0 +nan.0) ==> #f
implies that (= +nan.0 +nan.0) ==> #f does it follow from the
specification?

>> However, in that case the specification of eqv? (9.6 p 35) is wrong.
>> It says that (eqv? x y) implies that (= x y) for numbers.
>
> I don't see that implication in section 9.6.
> That section says eqv? returns #t "if" any of
> several things are true, and returns #f "if" any
> of several other things are true. There is no
> "only if" or "if and only if". It looks to me
> as though the behavior of eqv? on NaNs is not
> specified by section 9.6.

True. Still, I think a note about +nan.0 is appropriate.
It is something people have argued over - at least in the context
of R5RS (which I realize uses a different definition).

> I would argue that the behavior of eqv? on NaNs
> should not be fully specified. The basic reason
> for this is that the IEEE-754 standard does not
> say much about how the bits of a NaN are to be
> interpreted, and explicitly allows implementations
> of that standard to use most of a NaN's bits to
> encode implementation-dependent semantics. The
> implementors of a Scheme system will therefore
> have a better idea of how eqv? should interpret
> those bits than we do.

Do you have an actual system/example in mind where
something different than a bit-for-bit comparison
is preferable?

I'd go so far as to specify:

(eqv? obj1 obje2) is #t if:

obj1 and obj2 are flonums with the same representation
and are bit-for-bit equal.

(eqv? obj1 obje2) is #f if:

obj1 and obj2 are flonums with the same representation
and are not bit-for-bit equal.

This is a useful definition. It's hard to imagine a
case where you'd want anything else, assuming flonums
are they are actually used in today's software and
hardware.
-- 
	--Per Bothner
per_at_bothner.com   http://per.bothner.com/
Received on Wed Sep 20 2006 - 01:59:46 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC