Article View: comp.std.c
Article #1335Re: Questions about NCEG
From: James Salter
Date: Wed, 30 May 1990 02:36
Date: Wed, 30 May 1990 02:36
46 lines
2534 bytes
2534 bytes
In article <1990May29.193451.6533@twinsun.com> eggert@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@uunet.uu.net "PS/2 it, or DIE!"
Technical Details
Message-ID:
<5491@ibmpa.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!ibmpa!slo!jsalterReferences:
<15519@bfmny0.UU.NET> <73.UUL1.3#5109@pantor.UUCP> <3094@goanna.cs.rmit.oz.au> <1990May29.193451.6533@twinsun.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ibmpa!slo!jsalter From: jsalter@slo.uucp (James Salter) Newsgroups: comp.std.c Subject: Re: Questions about NCEG Message-ID: <5491@ibmpa.UUCP> Date: 30 May 90 02:36:46 GMT References: <15519@bfmny0.UU.NET> <73.UUL1.3#5109@pantor.UUCP> <3094@goanna.cs.rmit.oz.au> <1990May29.193451.6533@twinsun.com> Sender: news@ibmpa.UUCP Reply-To: jsalter@slo.UUCP (James Salter) Organization: IBM AWD, Palo Alto Lines: 46