Questions about NCEG

James Salter jsalter at slo.uucp
Wed May 30 12:36:46 AEST 1990


In article <1990May29.193451.6533 at twinsun.com> eggert at twinsun.com (Paul Eggert) writes:
>|(3) There are special numbers (+ and - infinity, -0, NaNs, Vax reserved
>|    operands, &c) which have no standard syntax.

Nitpick: -0 is an integer and doesn't exist.  -0.0 is a floating-point value
and does exist.

>There are ways to say the IEEE numbers in ANSI C + IEEE 754:
>
>	#define minus_0 (-0.0)

But IEEE 754 (Sec. 5.7) says that when comparing the two, (-0.0 == +0.0)
so that can't be used for comparison.  The way I test this is to strip
off the sign bit and test that.  Thank Knuth for big/little-endian :-).

>	#define infinity (1e300*1e300)

This can be tricky.  The numbers you use are big enough, but I've run into
cases with the i387 where the two numbers multiplied together would give
infinity in 64 bit (double) precision, but because the i387 has an 80 bit
(extended precision) register, computations done, without restore into
memory, don't get the correct exceptional value.  This is especially true
when the above is combined with modifying rounding modes.  It's happened
on both IBM and MetaWare compilers.

And, I'm assuming it can/has happen/ed on other coprocessors, too.

>	#define NaN1 (infinity-infinity)
>	#define minus_infinity (-infinity)
>	#define minus_NaN1 (-NaN1)

Will be (correctly) 0.0 if the above condition occurs.

>This lets you say some things portably that you can't say with hex contants,
>e.g. ``the NaN that you get when you subtract infinity from itself'',
>which has a different hex value in different implementations of IEEE 754.

There aren't a lot of people who actually use the data that can be embedded
in NaNs, so it's not very worrysome.

>Unfortunately, many compilers (e.g. GCC) get this sort of thing wrong,
>and these bugs are further arguments for hex floating constants.

jim/jsalter   IBM AWD   T465/(415)855-4427    VNET: JSALTER at AUSVMQ
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.std.c mailing list