Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!whuxl!whuxlm!akgua!gatech!seismo!brl-tgr!tgr!tribble_acn%uta.csnet@csnet-relay.arpa From: tribble_acn%uta.csnet@csnet-relay.arpa (David Tribble) Newsgroups: net.lang.c Subject: /-INFINITY and NaN Message-ID: <978@brl-tgr.ARPA> Date: Mon, 23-Dec-85 05:13:18 EST Article-I.D.: brl-tgr.978 Posted: Mon Dec 23 05:13:18 1985 Date-Received: Wed, 25-Dec-85 03:56:08 EST Sender: news@brl-tgr.ARPA Lines: 15 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