Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site alice.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!alice!ark From: ark@alice.UucP (Andrew Koenig) Newsgroups: net.lang.c Subject: Re: /-INFINITY and NaN Message-ID: <4745@alice.UUCP> Date: Wed, 25-Dec-85 10:04:58 EST Article-I.D.: alice.4745 Posted: Wed Dec 25 10:04:58 1985 Date-Received: Thu, 26-Dec-85 03:56:33 EST References: <978@brl-tgr.ARPA> Organization: Bell Labs, Murray Hill Lines: 21 > A question was raised as to how to compare a float (or double) to > the ANSI +/-infinity and Not-a-Number values. One suggestion was to > use a struct; another way (though arguably not elegant) is- > #define INFINITY (*(float*)"\177\200\0\0") > #define NaN (*(float*)"\177\277\377\377") > (I'm not certain of the bit patterns, however). The idea is to cast a > string, which is coerced into a char*, into a float*, thus interpreting > the string chars as elements of a float data value. > The same idea can be extended to doubles. > (This works on one compiler that I know of, running on an 8086). > >While this may not seem elegant, it has the advantage of not requiring >any structure initilizations. > > David R. Tribble It has the disadvantage of being extremely implementation-specific. In general, there may be variation from one implementation to another as to the location of the various bits within a word. There may also be alignment problems with this technique on some machines.