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

From: Per Bothner <per>
Date: Wed Sep 20 14:22:24 2006

John Cowan wrote:
> However, we have more flexibility about the behavior of eqv? when both
> arguments are flonums. It could return #f if either argument is a NaN,
> as = does; or return #t iff the bit patterns being compared are the same;
> or return #t if both arguments are NaNs, whether the bit patterns are
> the same or different. (Chicken defers to =, and takes the first option.)

Agreed. I'd argue for "#t iff the bit patterns being compared are the
same". Not necessarily that R6RS shoudl require this, but it might
suggest/recommend this for implementations using IEEE floating-point.

>> Not as a binary operator. But you can use Double.doubleToLongBits to
>> convert a double to its bit representation (as a long), or you can use
>> Double.equals to compare two Double objects bit-for-bit.
>
> The former method works, but the latter does not: given two Doubles
> representing NaNs, Double.equals will return false.

That is incorrect:

$ bin/kawa
#|kawa:1|# (define NaN java.lang.Double:NaN)
#|kawa:2|# (NaN:equals NaN)
#t
-- 
	--Per Bothner
per_at_bothner.com   http://per.bothner.com/
Received on Wed Sep 20 2006 - 14:21:32 UTC

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