Questions about NCEG

Paul Eggert eggert at twinsun.com
Wed May 30 05:34:51 AEST 1990


O'Keefe makes several good points about IEEE floating point and ANSI C,
including:

|(1) If you stick to the letter of the IEEE 754 and IEEE 854 standards,
|    conversion of numeric literals from decimal to binary (or possibly,
|    in the case of 854, to internal decimal) is a *run* *time* operation,

No C compiler that I know of does this.  Does this mean that no C compiler can
claim conformance to both IEEE 754 and ANSI C?  I fear that if we ask either
standards committee for a ruling, they'll refer us to the other committee.

|(3) There are special numbers (+ and - infinity, -0, NaNs, Vax reserved
|    operands, &c) which have no standard syntax.

There are ways to say the IEEE numbers in ANSI C + IEEE 754:

	#define minus_0 (-0.0)
	#define infinity (1e300*1e300)
	#define NaN1 (infinity-infinity)
	#define minus_infinity (-infinity)
	#define minus_NaN1 (-NaN1)

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.
Unfortunately, many compilers (e.g. GCC) get this sort of thing wrong,
and these bugs are further arguments for hex floating constants.



More information about the Comp.std.c mailing list