Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!umich!yale!think!linus!bs From: bs@linus.UUCP (Robert D. Silverman) Newsgroups: comp.lang.c Subject: Re: Using distributive property to optimize. Message-ID: <94348@linus.UUCP> Date: 6 Feb 90 16:51:35 GMT References: <229@altos86.Altos.COM> <1020.nlhp3@oracle.nl> Reply-To: bs@linus.UUCP (Robert D. Silverman) Organization: The MITRE Corporation, Bedford MA Lines: 22 In article <1020.nlhp3@oracle.nl> bengsig@oracle.nl (Bjorn Engsig) writes: :Article <229@altos86.Altos.COM> by clp@altos86.Altos.COM (Chuck L. Peterson) says: :[is it valid to change] :| n = a - (b + c); :|To this: :| n = a - b - c; :It was valid according to K&R 1. It's not in ANSI. Nor should it be. Floating point addition is NOT associative. Presumably the programmer has a reason to group the computation the way he did. Note also that even with integer arithmetic, the rearrangement is not safe. If (say) b is a large negative number and c a large positive number a - (b+c) may not overflow. However, a-b most certainly can. Compilers should NEVER rearrange computations. -- Bob Silverman #include Internet: bs@linus.mitre.org; UUCP: {decvax,philabs}!linus!bs Mitre Corporation, Bedford, MA 01730