Not A Number in IEEE Math

James Salter jsalter at slo.uucp
Wed Feb 28 08:07:14 AEST 1990


In article <MAC.90Feb19133844 at ben.ardent.com> mac at ardent.com (Michael McNamara) writes:
>
>  In article <44 at newave.UUCP> john at newave.UUCP (John A. Weeks III) writes:
>
>>  My understanding of the NaN (not a number) value in IEEE math is
>>  that once you get NaN, the operators +, -, /, *, and = are supposed
>>  to propagate the NaN value.  Is my understanding correct?
>>  
>>  Well, while using MetaWare's HIGH-C compiler for the 80386 chip, I
>>  have discovered that:
>>  			NaN / NaN = 1.0
>>  			      and
>>  			0.0 * NaN = 0.0.
>>  Is this correct behavior?  I think HIGH-C is broken...
>>  -john-
>	This behaviour is not correct.  Possibly the compiler has
>folied you by presubstituting 1.0 for A/A and 0.0 for 0.0 * A at
>compile time.

Metaware hasn't been very good about identifying and correctly dealing
with NaNs.  They generate code which does not have the jp (jump if parity)
instruction around the compare of doubles.  Because of the flag bits
which get set in the 386, if the jp instruction is placed after the normal
conditional jump, even if one of the args is a NaN, it may *still* not
reach the jump if parity instruction.

If you check the assembler code, this should reveal itself.  To be fair,
Metaware isn't alone in this, lots of compilers don't do this right.

>	Or, perhaps your hardware traps into the OS for IEEE exceptions
>and the OS's handling of source exceptions is broken.

Probably not.

>	Or, perhaps your hardware is not IEEE compliant....

Well, sorta.  Depending on what 80386 level of hardware you have, you
may have some microcode problems.  But those should be getting fixed soon.
Contact your local Intel dealer about errata sheets.  Especially if you
have an 80387 chip in there, too.

>Michael McNamara	(St)ardent, Inc.		mac at ardent.com


jim/jsalter   IBM AWD   T465/(415)855-4427    VNET: JSALTER at PALOALTO
UUCP: ..!uunet!ibmsupt!jsalter               Disc: Any opinions are mine.
IP: ibmsupt!jsalter at uunet.uu.net                 "PS/2 it, or DIE!"



More information about the Comp.lang.c mailing list