Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!rbutterworth From: rbutterworth@watmath.UUCP Newsgroups: comp.lang.c Subject: ANSI really does want you to == float values. Message-ID: <6909@watmath.UUCP> Date: Mon, 13-Apr-87 13:30:38 EST Article-I.D.: watmath.6909 Posted: Mon Apr 13 13:30:38 1987 Date-Received: Tue, 14-Apr-87 00:44:12 EST Distribution: comp Organization: U of Waterloo, Ontario Lines: 40 Since most people seem to be yelling into the wind and not noticing what the others are saying, this is probably a bad time to submit this, but anyway. The ANSI standard defines functions such as strtod() that return a double value, HUGE_VAL, upon failure. That seems to imply that the following pieces of code all should do the comparison the same way. if (HUGE_VAL == strtod(args)) ... val = strtod(args); if (val == HUGE_VAL) ... bad = HUGE_VAL; val = strtod(args); if (val == bad) ... Now does that mean that HUGE_VAL (and -HUGE_VAL) are defined so that the comparisons will work correctly regardless of registers, guard bits, optimization, etc.? If so, do such numbers really exist on all machines? Probably not. e.g. if "val" and "bad" above are registers with extra guard bits that aren't automatically zeroed when the values are loaded, they usually won't compare equal. On the other hand if there isn't supposed to be anything special about these numbers, does that mean that the compiler should generate correct code for all doubles? If so, is this even possible on all machines? Again, probably not. At least not unless you are willing to put up with some very inefficient code. (e.g. whenever any two floating values are compared they are first normalized and stored in temporary memory somewhere.) Or is the compiler itself supposed to know that HUGE_VAL is special and generate "correct" comparison code for that case? Or does any of this really matter? Who bothers to check error status returns anyway?