[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Q on NaN
From: |
Drew Adams |
Subject: |
RE: Q on NaN |
Date: |
Fri, 24 Jun 2005 14:49:04 -0700 |
> I didn't say above that (/0.0 0.0) should give `arith-error'.
Well, you seemed to: you complained that it did so in previous
versions.
No, I said "fair enough" to that change in behavior. I did not suggest it
was a bug. My question was about numberp's behavior:
> I suggested that perhaps `numberp' should return nil for
> a NaN argument, since "NaN"
> means "not a number" and "numberp" means "a number".
> NaN is a floating-point value, but is it a number?
Any floating-point value is a ``number'' as far as `numberp' is
concerned. The fact that NaN is a short for not-a-number does not
mean that Lisp should treat it like that.
I can see that from the behavior, but then perhaps it should be mentioned
explicitly in the doc. Since the names suggest something different, perhaps
a note of clarification should be added.
> As for a way to test for a NaN, try this:
> (= (/ 0.0 0.0) (/ 0.0 0.0))
> It should evaluate to nil, since a NaN is defined to fail _any_
> arithmetic comparison, even a comparison to itself.
>
> That doesn't tell me how to test if `foobar' is a NaN.
Exactly the same: (= foobar foobar). (Did you try that?)
Right. Got it; thanks. A couple of people replied with the same solution.
I am using (equal 0.0e+Nan), which also seems to work (and if equivalent,
would perhaps be clearer, since it mentions NaN: anything equal to NaN is
NaN). Does anyone know that these are not equivalent:
(equal 0.0e+NaN) <=?=> (and (numberp x) (/= x x))
That is, are there any objects equal to 0.0e+NaN that are not NaN?
It might also be useful to mention such an idiom - either expression - in
the doc, or else to provide a predicate.
> See my previous email: I knew I could test
> `(equal foo 0.0e+Nan)', but I thought I would
> need to test against all of the possible NaN values.
No need: the arithmetic equality trick takes care of all of the
possible values.
Right. All NaNs are `equal', but they are not `=', even to themselves.
Note that you should use `=', not `equal' (nor `eql', btw).
Yes, for testing a numberp to see if it is not NaN. However, I am testing an
arbitrary object. For that, (and (numberp x) (/= x x)) works and (equal x
0.0e+Nan) works. For the latter test, it must be `equal' or `eql', not `='
or `eq'.
- Q on NaN, Drew Adams, 2005/06/24
- RE: Q on NaN, Drew Adams, 2005/06/24
- Re: Q on NaN, Eli Zaretskii, 2005/06/24
- RE: Q on NaN, Drew Adams, 2005/06/24
- Re: Q on NaN, Luc Teirlinck, 2005/06/24
- Re: Q on NaN, Gaƫtan LEURENT, 2005/06/24
- Re: Q on NaN, Eli Zaretskii, 2005/06/24
- RE: Q on NaN,
Drew Adams <=
- Re: Q on NaN, Luc Teirlinck, 2005/06/24
- RE: Q on NaN, Drew Adams, 2005/06/24
- Re: Q on NaN, Richard M. Stallman, 2005/06/25
RE: Q on NaN, Drew Adams, 2005/06/24