From: Richard M. Stallman Date: Sat, 25 Jun 2005 02:29:46 +0000 (+0000) Subject: (Float Basics): Explain how to test for NaN, and printing the sign of NaNs. X-Git-Tag: emacs-pretest-22.0.90~8657 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=32d4834cc6c76b53925edc5bf8db7079c8932413;p=emacs.git (Float Basics): Explain how to test for NaN, and printing the sign of NaNs. --- diff --git a/lispref/numbers.texi b/lispref/numbers.texi index 776251e4933..f7f88248ff1 100644 --- a/lispref/numbers.texi +++ b/lispref/numbers.texi @@ -183,21 +183,26 @@ there is no correct answer. For example, @code{(/ 0.0 0.0)} returns a NaN. For practical purposes, there's no significant difference between different NaN values in Emacs Lisp, and there's no rule for precisely which NaN value should be used in a particular case, so Emacs Lisp -doesn't try to distinguish them. Here are the read syntaxes for -these special floating point values: +doesn't try to distinguish them (but it does report the sign, if you +print it). Here are the read syntaxes for these special floating +point values: @table @asis @item positive infinity @samp{1.0e+INF} @item negative infinity @samp{-1.0e+INF} -@item Not-a-number -@samp{0.0e+NaN}. +@item Not-a-number +@samp{0.0e+NaN} or @samp{-0.0e+NaN}. @end table - In addition, the value @code{-0.0} is distinguishable from ordinary -zero in @acronym{IEEE} floating point (although @code{equal} and -@code{=} consider them equal values). + To test whether a floating point value is a NaN, compare it with +itself using @code{=}. That returns @code{nil} for a NaN, and +@code{t} for any other floating point value. + + The value @code{-0.0} is distinguishable from ordinary zero in +@acronym{IEEE} floating point, but Emacs Lisp @code{equal} and +@code{=} consider them equal values. You can use @code{logb} to extract the binary exponent of a floating point number (or estimate the logarithm of an integer):