Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!munnari.oz.au!goanna!ok From: ok@goanna.oz.au (Richard O'keefe) Newsgroups: comp.lang.c Subject: Re: Not A Number in IEEE Math Keywords: IEEE floating point Message-ID: <2889@goanna.oz.au> Date: 20 Feb 90 07:59:44 GMT References: <44@newave.UUCP> <1990Feb19.172558.29696@gpu.utcs.utoronto.ca> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 55 In article <1990Feb19.172558.29696@gpu.utcs.utoronto.ca>, sarathy@gpu.utcs.utoronto.ca (Rajiv Sarathy) writes: > In article <44@newave.UUCP> john@newave.UUCP (John A. Weeks III) writes: > >Well, while using MetaWare's HIGH-C compiler for the 80386 chip, I > >have discovered that: > > NaN / NaN = 1.0 > > 0.0 * NaN = 0.0. > >Is this correct behavior? I think HIGH-C is broken... > > As long as only very, VERY, large numbers (positive or negative) are defined > to be NaNs (ie. not results of division by zero, and other silly things), > then the above behaviour makes sense. > Unfortunately, NaNs encompass other floating-point exceptions as well, > on some machines. Rajiv Sarathy is confused. The IEEE 754 and IEEE 854 specify the following kinds of values: NUMBERS FINITE NUMBERS - minus zero (-0.0) - plus zero (+0.0) - denormalised numbers (numbers which are so small that the exponent field would underflow; the presence of these numbers means that an add or subtract of finite numbers cannot overflow - ordinary normalised numbers INFINITIES - minus infinity (1/(-0) = -infinity) - plus infinity (1/(+0) = +infinity) NOT-A-NUMBERS SIGNALLING NaNs - strange-fella-number-you-touch-im-e-cry QUIET NaNs - propagate quietly "very VERY large numbers" are mapped to plus or minus infinity. The infinities are NOT NaNs. Any machine which maps large numbers to NaNs is _not_ IEEE conforming. It is, however, the case that Infinity / Infinity = NaN Infinity * 0.0 = NaN Note that (contra Rajiv Sarathy) it does *NOT* make sense for Infinity/Infinity to yield 1.0, for then one would expect (3*Infinity)/Infinity to be the same as 3*(Infinity/Infinity). But the first would be 1.0 and the second 3.0. A NaN or an exception is all that makes sense here. One requirement of the IEEE standards which is _very_ commonly ignored is the requirement that the default behaviour for strange computations is to return the appropriate Infinity (instead of signalling Overflow), denormalised number (instead of signalling Underflow), or NaN (instead of signalling Divide by zero or Invalid operand). The IEEE standards are really quite short and not that hard to understand. (What they are like to _implement_ is someone else's problem, thankfully.)