[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Q on NaN

From: Eli Zaretskii
Subject: Re: Q on NaN
Date: Fri, 24 Jun 2005 23:01:07 +0200

> From: "Drew Adams" <address@hidden>
> Date: Fri, 24 Jun 2005 12:33:53 -0700
>     (condition-case nil (setq foo (/ 0.0 0.0)) (arith-error nil))
>     In older versions of Emacs (at least prior to April 2005 CVS), 
>     this would evaluate to nil. Now, it evaluates to -0.0NaN.
>     I can modify the code like so:
>     (and (condition-case nil (setq foo (/ 0.0 0.0)) (arith-error nil))
>          (bar foo)) ; foo must be a number, not a NaN
>     What function do I use for bar? 
>     `numberp' doesn't work, since (numberp -0.0NaN) is non-nil. 
> To make the point simpler:
> (numberp (/0.0 0.0)) returns t. That seems like a bug to me.

Maybe it is, maybe it isn't.  (elisp)Arithmetic Operations says:

     If you divide an integer by 0, an `arith-error' error is signaled.
     (*Note Errors::.)  Floating point division by zero returns either
     infinity or a NaN if your machine supports IEEE floating point;
     otherwise, it signals an `arith-error' error.

So if the machine supports IEEE floating point (most modern machines
do), you aren't supposed to get `arith-error' in this case.  Maybe
this is a bit counter-intuitive for someone who never did futz with
NaNs, but at least Emacs behaves consistently with the docs.

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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]