what does NaN mean out of printf?

Andrew Koenig ark at alice.UUCP
Wed Aug 16 00:18:06 AEST 1989


In article <3876 at phri.UUCP>, roy at phri.UUCP (Roy Smith) writes:
> In article <20283 at adm.BRL.MIL> Leisner.Henr at xerox.com (Marty) writes:
> > What does NaN mean out of printf?
> 
> 	You're on a machine which supports IEEE-754 arithmetic (for
> example, a Sun, but there are many, many modern machines which fit this
> description).  NaN means Not A Number.  NaN is the result of some illegal
> arithmetic operation (division by zero, square root of a negative number,
> etc).

You're almost right.

IEEE-754 defines two different kinds of exceptional values: infinity
and NaN.

Infinity has a sign and obeys several sensible rules.  For example:

	+inf + +inf = +inf
	-inf + -inf = -inf
	- (+inf) = -inf
	- (-inf) = +inf
	+1 / +0 = +inf	[with a possible trap]
	+1 / +inf = +0  [no trap]
	+1 / -0 = -inf	[with a possible trap]

and so on.  However,

	0 / 0 = NaN
	+inf + -inf = NaN

and so on.  NaN is extremely infectious: just about any operation on
a Nan gives Nan as a result.
-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.unix.wizards mailing list