Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site ucla-cs.ARPA Path: utzoo!watmath!clyde!cbosgd!ukma!psuvm.bitnet!psuvax1!burdvax!sdcrdcf!ucla-cs!jimc From: jimc@ucla-cs.UUCP Newsgroups: net.lang.c Subject: Re: How to test for +/- INFINITY, etc. in C with IEEE Message-ID: <8040@ucla-cs.ARPA> Date: Fri, 13-Dec-85 13:20:02 EST Article-I.D.: ucla-cs.8040 Posted: Fri Dec 13 13:20:02 1985 Date-Received: Sun, 15-Dec-85 00:39:45 EST References: <993@turtlevax.UUCP> Reply-To: jimc@ucla-cs.UUCP (Jim Carter) Organization: UCLA Computer Science Department Lines: 24 Keywords: conversions are a pain in casts 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. > >Can anyone recommend a way to quickly compare a float against >INFINITY? I munged a "C" library with emulated floating point (Microsoft format) to use an 8087 (IEEE format), but having no sources for the compiler I couldn't hack the constant interpreter. I got around it this way: short pi[4] = {0x4008,0x1234,etc,etc}; double x, y; x = y * *(double *)pi A similar method should work for you. It's ugly but it works, and a #define macro neatens up the code a little. James F. Carter (213) 206-1306 UCLA-SEASnet; 2567 Boelter Hall; 405 Hilgard Ave.; Los Angeles, CA 90024 UUCP:...!{ihnp4,ucbvax,{hao!cepu}}!ucla-cs!jimc ARPA:jimc@locus.UCLA.EDU