(nan? <obj>)
nan? returns #t if <obj> is a NaN.
(nan)
Returns a NaN}}} with an implementation defined chosen payload, implementations are free to return different {{{NaNs}}} for each `nan` invocation or not. The reader calls the `nan` function with no parameter each time it encounters a {{{NaN representation such as "+nan.0".
(nan <payload>)
Returns a NaN with the given payload as its content. Valid values for <payload> are implementation dependent.
(nan->payload <obj>)
Returns the payload content of <obj> if it is a NaN.
This library is about NaNs operation handling.
For IEEE Standard for Floating-Point Arithmetic (IEEE 754) implementation there is one NaN}}} concept but many differents {{{NaNs}}}. From the purpose of {{{NaNs}}} we have to be able to distinguish between {{{NaNs}}}. For that effect, {{{NaNs}}} carry a ''payload'' intended to put diagnosis information about what caused a {{{NaN to be produced.
When the reader reads "+nan.0", it has to choose one particular internal representation for it. It is free to choose one representation shared for all "+nan.0" or to choose a different one each time it encounters another "nan.0". This is what the following means:
(eqv? +nan.0 +nan.0) => unspecifiedHowever the identity of a particular NaN should not be questioned, I mean I think we should have this:
(let ((a +nan.0)) (eqv? a a)) => #tThe following is a desirable behaviour (however I would not push for it into the standard):
(let ((a (/ 0.0 0.0)) (b (sin +inf.0))) (eqv? a b)) => #fInstead of returning strange values such as 99999 which could be mistaken with real one and cause dramatic effects, sensors may use NaNs to report invalid values. A payload may be added to report an additional message.
In order to identify wrong usage of unitialased vector, one could fill vector with NaNs containing index in their payloads.
(define (make-reals-vector N) (if (>= N 0) (let ((result (make-vector N))) (let loop ((i 0)) (if (< i N) (begin (vector-set! result i (nan i)) (loop (+ i 1))) result ))) (error "make-float-vector: negative argument")))