Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!hc!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.fortran Subject: Re: Fortran versus C for numerical analysis Message-ID: <3349@lanl.gov> Date: 8 Sep 88 23:35:47 GMT References: <1421@ficc.uu.net> Organization: Los Alamos National Laboratory Lines: 17 From article <1421@ficc.uu.net>, by peter@ficc.uu.net (Peter da Silva): > The compiler is free to perform any optimisation it wants, so long as > it doesn't change the result. So (1.0+x)*2.0 can be evaluated as 2+2*x > if that's more efficient. Multiplying by 2 is an exact operation in > binary floating point. This was just a badly chosen example. Suppose the expression had been: (1.2345+x)*6.7890? Applying the distributive law to this doesn't produce the same computational result. The question is: should the optimization be allowed anyway? The rules of Fortran don't allow it, the rules of C (there are rules in C?) do. The problem with C is that it provides _no_ way to force a given order of expression evaluation (ANSI doesn't count - expression ordering of one kind or another has been proposed and removed so many times that there is no way of telling whether the final standard will have the feature or not). J. Giles Los Alamos