Calculation returning NaN

Stephen Clamage steve at taumet.com
Wed Jan 30 03:12:12 AEST 1991


fineberg at caip.rutgers.edu (Adam B. Fineberg) writes:

>I was wondering if someone could point me to a source of information
>about the math error NaN (Not-a-Number).

This is a feature of IEEE floating-point, and can be found in
ANSI/IEEE Std 754-1985, "IEEE Standard for Binary Floating-Point Arithmetic".

In addition, the manuals for floating-point chips which implement IEEE
arithmetic (such as Motorola 68881/2 and Intel 80x87) will contain a
discussion of NaN. 

Briefly, an operation with an undefined result produces a NaN.  The result
of 0/0 or Infinity*0 is not defined, for example.  Almost any operation
involving a NaN, including comparison, results in a NaN, so that nonsense
does not later turn into something which looks reasonable.  The NaN result
lets you know that something went wrong earlier in the calculation.

NaN's are also used as the starting value of uninitialized variables.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list