How to test for +/- INFINITY, etc. in C with IEEE

Ken Turkowski ken at turtlevax.UUCP
Wed Dec 11 14:46:27 AEST 1985


I would like to be able to test for INFINITY, NaN, and other such
things within C.  Now, if I try to cast the value for INFINITY
(0x7F800000 in single) to a float,

	((float)(0x7F800000))

the C compiler changes it into 0x4EFF0000 which does not compare the
same as 0x7F800000.

Can anyone recommend a way to quickly compare a float against
INFINITY?  I can't use a subroutine, because the C compiler changes the
float to a double.

*STEAM follows*

The C compiler should assume that only decimal constants need be
converted from integer to floating point.

Octal and hexadecimal constants are used to represent bit patterns, not
numbers.  There is no reason that the compiler should assume that a
particular bit pattern represents an integer rather than a
floating-point number or something even more exotic.
-- 
Ken Turkowski @ CIMLINC, Menlo Park, CA
UUCP: {amd,decwrl,hplabs,seismo,spar}!turtlevax!ken
ARPA: turtlevax!ken at DECWRL.DEC.COM



More information about the Comp.lang.c mailing list