Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!hc!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.fortran Subject: Re: Fortran versus C for numerical analysis Message-ID: <3182@lanl.gov> Date: 2 Sep 88 19:03:45 GMT References: <3534@s.cc.purdue.edu> Organization: Los Alamos National Laboratory Lines: 38 From article <3534@s.cc.purdue.edu>, by ags@s.cc.purdue.edu (Dave Seaman): > > On the contrary, Fortran's parentheses control only grouping and have > nothing to do with evaluation order. Consider the statement > > Y = A(X) + (B(X) + C(X)) > > where A, B and C are external functions. There are 3! = 6 possible orders > of evaluation for the three functions. All six of them are legal in > Fortran. For example, a perfectly legal code sequence would be the > following: > > 1. Evaluate C(X) and place the result in a temporary, t1. > 2. Evaluate A(X) and place the result in a temporary, t2. > 3. Evaluate B(X) and place the result in a temporary, t3. > 4. Add t3 to t2 and place the result in t3. > 5. Add t3 to t1 and store the result in Y. This is simply _not_ true. Read the standard before claiming things like this. ANSI X3.9-1978 FORTRAN 77, page 6-18, line 30: In addition to the parenthesis required to establish the desired interpretation, parenthesis may be included to restrict the alternative form that may be used by the processor in the actual evaluation of the expression. This is useful for controlling the magnitude and accuracy of intermediate values developed during the evaluation of an expression. For example, in the expression A+(B-C) the term (B-C) must be evaluated and then added to A. [...] This seems pretty clear. To be sure, the three function calls in your example can be evaluated in any order. But, the result of functions B and C _must_ be added first, then added to the result of function A. J. Giles Los Alamos