Path: utzoo!attcan!uunet!portal!cup.portal.com!PLS From: PLS@cup.portal.com Newsgroups: comp.lang.fortran Subject: Re: Fortran versus C for numerical analysis Message-ID: <9181@cup.portal.com> Date: 17 Sep 88 02:01:18 GMT References: <893@amelia.nas.nasa.gov> <3064@lanl.gov> <820@cernvax.UUCP> Organization: The Portal System (TM) Lines: 34 XPortal-User-Id: 1.1001.3295 hjm@cernvax.UUCP (Hubert Matthews) writes >Consider the following cases: > > I = (5 / 4) * 5 (I gets 5) > > I = 5 / (4 * 5) (I gets 0) > > I = 5 / 4 * 5 (I gets 5 in F77, I gets something in C) Now just a minute. Surely you don't mean to say that the first two are both equivalent to the third except for a choice in order of operations? The second is a completely different formula. The two correct choices are I = (5 / 4) * 5 = 5 I = (5 * 5) / 4 = 6 I suspect there are very few compilers that do this kind of reordering. ++PLS onsider the following cases: I = (5 / 4) * 5 (I gets 5) I = 5 / (4 * 5) (I gets 0) I = 5 / 4 * 5 (I gets 5 in F77, I gets something in C) Personally, I wouldn't use case 3; I would always enforce an evaluation order by using parentheses. If this could be ambiguous in C, I wouldn't use it for numerical work. The same problem occurs when using mixed-mode arithmetic. Ev