Path: utzoo!attcan!utgpu!watmath!att!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!mcvax!ukc!dcl-cs!gdt!gdr!exspes From: exspes@gdr.bath.ac.uk (P E Smee) Newsgroups: comp.lang.c Subject: Re: Re^2: Turbo C 2.0 vs MSC 5.1 Message-ID: <1989Aug9.094742.20000@gdt.bath.ac.uk> Date: 9 Aug 89 09:47:42 GMT References: <644@octopus.UUCP> <3607@cps3xx.UUCP> <7368@cg-atla.UUCP> <527@tigger.planet.bt.co.uk> Reply-To: exspes@gdr.bath.ac.uk (P E Smee) Organization: University of Bristol c/o University of Bath Lines: 32 In article <527@tigger.planet.bt.co.uk> raph@tigger.planet.bt.co.uk (Raphael Mankin) writes: > >I a Coral 66 compiler that I wrote some 17 years ago I went to great >lengths to preserve arithmetic precision, including transforming >things like > a/b/c/d/e >into > a/(b*c*d*e) >and re-ordering factors so as to do division as late as possible. A bad move, I'd have said. It is not difficult to think of cases where 'a/b/c/d/e' would give a sensible answer, while 'a/(b*c*d*e)' will overflow computing the denominator '(b*c*d*e)' and so give nonsense. Further, the person writing that might have set up condition (or fault, or signal, take your pick) handlers to catch the hardware conditions that might result from the repeated division (at a higher level invisible to the compiler) based on knowledge of likely values/errors. The reordering changes the sorts of faults which are likely to occur. (Having both written and used compilers myself) I'd suggest that it is generally a bad idea for a compiler to 'rewrite' expressions unless the rewrite is both mathematically identical in an ideal world, and pragmatically identical given the range of numbers the machine can express, and the sorts of faults which will occur with any set of input values. (Although, being paranoid, I'd also suggest that the person writing a/b/c/d/e should inject lots of ()s to indicate that the ordering is really desired. I tend to parenthesize everything :-) Goes without saying that I strongly feel that languages should honor any order-of- evaluation requirements which the programmer specifies using parens.