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

Per Bothner per at bothner.com
Wed Sep 20 14:21:32 EDT 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/



More information about the r6rs-discuss mailing list