Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.UUCP Newsgroups: comp.lang.c Subject: Re: Comments on ANSI public Oct 86 Public review draft. Message-ID: <5708@brl-smoke.ARPA> Date: Mon, 30-Mar-87 15:56:36 EST Article-I.D.: brl-smok.5708 Posted: Mon Mar 30 15:56:36 1987 Date-Received: Wed, 1-Apr-87 01:37:23 EST References: <4804@brl-adm.ARPA> <365@bms-at.UUCP> <704@mcgill-vision.UUCP> <5703@brl-smoke.ARPA> <341@zuring.mcvax.cwi.nl> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 35 In article <5703@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: > It occurs to me that we should not allow == with floating-point > operands. I'm serious! So far the only valid use for floating == that anyone has suggested to me is for branching to streamlined handling of cases where one variable is precisely 0.0 (or perhaps 1.0). It occurs to me that an example of why C floating == is not very useful might be in order (apart from the numerical analysis problems): #include int SameRatio( a, b, c, d ) /* return non-0 iff a/b == c/d */ register double a, b, c, d; { register double ab = a / b; /* `register' honored */ register double cd = c / d; /* `register' ignored */ return ab == cd; } int main() { static double a = 2.0, b = 3.0, c = 2.0, d = 3.0; (void)printf( "%s\n", SameRatio( a, b, c, d ) ? "ok" : "oops" ); return 0; } Now suppose that the machine has 5 available FP registers (other than the scratch accumulators), that they include some guard bits, and that no real optimization is done. Since `cd' will be stored in memory, for the ab == cd comparison it will be loaded into a scratch register with its guard bits set to zero, unlike `ab', and very likely the comparison will fail. "Oops."