Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!nrl-cmf!cmcl2!phri!marob!djs!samperi From: samperi@djs.UUCP (Dominick Samperi) Newsgroups: comp.lang.fortran Subject: Re: Fortran versus C for numerical analysis Message-ID: <180@djs.UUCP> Date: 3 Sep 88 09:28:44 GMT References: <3535@s.cc.purdue.edu> <3183@lanl.gov> Reply-To: samperi@djs.UUCP (Dominick Samperi) Organization: Village Software Lines: 29 In article <3183@lanl.gov> jlg@lanl.gov (Jim Giles) writes: |The expression A+B+C may be evaluated as (A+B)+C, A+(B+C), or (A+C)+B. |Fortran is free to do the calculation in any of those orders. |J. Giles |Los Alamos I don't have a copy of the official FORTRAN standard handy, but there appears to be an inconsistency in the specifications. Specifically, most references on FORTRAN state that the primitive operators associate left to right, except for **, which associates right to left. This would imply that A+B+C will be evaluated as (A+B)+C. On the other hand, I have verified that the FORTRAN definition explicitly allows any FORTRAN implementation to rearrange the order of evaluation of an expression for optimization in any manner, provided that operator precedence rules are obeyed, and parentheses are respected. Does this not contradict the left-to-right/right-to-left rules mentioned above? I also checked into the aliasing example that was mentioned recently in this group, and the compilers I used could not detect that I was modifying the same array by two different aliases. Since rules like "functions may not have side effects that affect the result of expression evaluation" usually cannot be enforced by the compiler, they might more properly be called programming guidelines. -- Dominick Samperi samperi@acf8.nyu.edu uunet!hombre!samperi cmcl2!acf8!samperi rutgers!acf8.nyu.edu!samperi (^ ell)