Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site hadron.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!cmcl2!seismo!rlgvax!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: net.lang.c Subject: Re: How to test for +/- INFINITY, etc. in C with IEEE Message-ID: <130@hadron.UUCP> Date: Wed, 18-Dec-85 03:22:31 EST Article-I.D.: hadron.130 Posted: Wed Dec 18 03:22:31 1985 Date-Received: Fri, 20-Dec-85 02:35:22 EST References: <993@turtlevax.UUCP> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Organization: Hadron, Inc., Fairfax, VA Lines: 30 Keywords: cast, conversion, int, float Summary: Numbers are numbers, hexed, octet, or whatever. In article <993@turtlevax.UUCP> ken@turtlevax.UUCP (Ken Turkowski) writes: >I would like to be able to test for INFINITY, NaN, and other such >things within C. Now, if I try to cast the value for INFINITY >(0x7F800000 in single) to a float, > ((float)(0x7F800000)) >the C compiler changes it into 0x4EFF0000 which does not compare the >same as 0x7F800000. > ... >The C compiler should assume that only decimal constants need be >converted from integer to floating point. The object 0x80000000 has data type integer, and means a particular (if somewhat indeterminate) integer. If I had a constant 0x1 or 01 or 1, I'd expect them all to equal 1. Their use as bit patterns on particular machines is wholy machine-dependent. Try it on Cottrell's ternary (trinary?) machine! >Can anyone recommend a way to quickly compare a float against >INFINITY? I can't use a subroutine, because the C compiler changes the >float to a double. union liffle { /* long int / float union is a liffle. */ long int lf_l; float lf_f; }; const union liffle inf = { 0x7f80000 }; /* initialises 1st elem */ #define INFINITY (inf.lf_f) -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}