Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!seismo!rochester!pt.cs.cmu.edu!sei.cmu.edu!firth From: firth@sei.cmu.edu.UUCP Newsgroups: comp.lang.c Subject: Re: C and Floating Point (really parentheses) Message-ID: <908@aw.sei.cmu.edu.sei.cmu.edu> Date: Thu, 9-Apr-87 09:26:26 EST Article-I.D.: aw.908 Posted: Thu Apr 9 09:26:26 1987 Date-Received: Sat, 18-Apr-87 02:37:03 EST References: <1094@ius2.cs.cmu.edu> Sender: netnews@sei.cmu.edu Reply-To: firth@bd.sei.cmu.edu.UUCP (PUT YOUR NAME HERE) Organization: Carnegie-Mellon University, SEI, Pgh, Pa Lines: 28 In article <1094@ius2.cs.cmu.edu> edw@ius2.cs.cmu.edu (Eddie Wyatt) writes: >#define X 0 >#define Y 1 >#define _EPSILON .0002 >#define sqr(x) (x*x) >#define distance(x1,x2,y1,y2) (sqrt((double (sqr(x1-x2) + sqr(y1-y2))))) >#define approx_equal(x,y) (fabs(double (x - y)) < _EPSILON) >#define same_point(x1,x2,y1,y2) (approx_equal(distance(x1,x2,y1,y2),0)) > >. >. >. > >if (same_point(p1[X],0.0,p1[Y],0.0)) .... > > I trust that my C compiler is going to optimize the hell out of this >expression. Is this a good enough reason to allow reordering? Maybe I'm missing something obvious, but, no, I DON'T see why this is reason to allow reordering. Doesn't it expand to: ((fabs(double((sqrt(((p1[X]-0.0)*(p1[X]-0.0)) + \ ((p1[Y]-0.0)*(p1[Y]-0.0)))) - 0.0)) < 0.0002)) We can then elide "-0.0", replace "p1[X]*p1[X]" by "p1[X]*ibid", and remove the redundant coercions and parentheses. But I can't see any scope for serious reordering.