[r6rs-discuss] [Formal] NaN is not a real number.

From: Aubrey Jaffer <agj>
Date: Wed Sep 20 22:11:34 2006

 | Date: Wed, 20 Sep 2006 16:42:01 -0400
 | From: John Cowan <cowan_at_ccil.org>
 |
 | Aubrey Jaffer scripsit:
 |
 | > (/ 0.0 0.0) is NaN because any finite number satisfies the equation:
 | >
 | > z * 0.0 = 0.0.
 | >
 | > And that includes any finite complex number! Restricting NaN to be
 | > real is wrong.
 |
 | This argument is quite sound theoretically, but will have unfortunate
 | performance consequences.

Using the approach described below, implementation of complex NaNs had
no measurable impact on SCM speed running its statistical benchmark.
This is not surprising considering that the (described) test for NaN
operates only on data already in the cache.

 | > In page 10, "2.4. Infinities and NaNs", I propose the sentence should
 | > be changed to read:
 | >
 | > A NaN is regarded as a complex number whose value is so
 | > indeterminate that it might represent any complex number.
 |
 | [snip]
 |
 | > Because it doesn't participate in the ordering, +nan.0 is not an
 | > acceptable argument to numerical-ordering predicates (<, <=, >, >=,
 | > negative?, positive?, etc).
 |
 | The IEEE standard already defines very specific behavior for these
 | (equality and ordering predicates return #f whenever a NaN is
 | involved, e.g.).

The universe of discourse for IEEE-754 was the real numbers. So it
treats everything as a real number. The name "not-a-number" indicates
they thought that treating NaN as real was not fully appropriate.

 | You would prevent a Scheme system from deferring directly to the
 | hardware until it had checked that no NaN was being compared.

Not so! Before returning a flonum, SCM code checks whether it is a
NaN. If so, it returns a complex (NaN) flonum. Numerical ordering
predicates already reject non-real (complex) numbers. So no extra
input checking is required.

Putting IEEE NaNs into both the real and imaginary parts of the
complex NaN assures that any mathematical operation upon it will
return a complex NaN.

As for praxis, comparing numbers which might be +inf.0 or -inf.0 is
entirely reasonable. But comparing with a NaN indicates a serious
flaw in program logic. A language does the programmer no favor by its
silence in this situation. If predicates can silently ignore non-real
arguments, it forces the conscientious programmer to write checks
before comparisons.
Received on Wed Sep 20 2006 - 22:11:00 UTC

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