Article View: comp.lang.fortran
Article #4525Re: Wanted: folk theorems in Fortran Progra
From: Chris Flatters
Date: Wed, 27 Jan 1993 20:36
Date: Wed, 27 Jan 1993 20:36
29 lines
1682 bytes
1682 bytes
In article 199@comp.compilers, dodd@mycenae.cchem.berkeley.edu (Lawrence R. Dodd) writes: >"Steve" Stevenson <steve@hubcap.clemson.edu> writes: >> I am trying to make a catalog of folk wisdom in fortran programming. > >My personal favorite is the one discussed on page 137 of the 1st edition of >Numerical Recipes (Fortran edition, of course): > >BAD > >P = c(1) + c(2)*x + c(3)*x**2 + c(4)*x**3 + c(5)*x**4 > >GOOD > >P = c(1) + x*(c(2) + x*(c(3) + x*(c(4) + x*c(5)))) > >It is a little harder to read but you won't be `summarily executed' I hope that you don't mean folk wisdom in the sense of things that are widely believed without justification: there is a good reason for preferring the latter version. The former version requires 4 additions, 4 multipications and 3 applications of the power operator (should total 15 or 16 fp operations using an efficient algorithm for raising fp numbers to integer powers. The latter version does not require application of the power operator. Not only will it be approximately twice as fast but it will accumulate less rounding error. Chris Flatters cflatter@nrao.edu
Technical Details
Message-ID:
<1993Jan27.203653.23536@zia.aoc.nrao.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!opl.com!hri.com!spool.mu.edu!sdd.hp.com!cs.utexas.edu!swrinde!emory!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!lynx.unm.edu!zia.aoc.nrao.edu!laphroaig!cflatterReferences:
<93-01-199@comp.compilers>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!opl.com!hri.com!spool.mu.edu!sdd.hp.com!cs.utexas.edu!swrinde!emory!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!lynx.unm.edu!zia.aoc.nrao.edu!laphroaig!cflatter From: cflatter@nrao.edu (Chris Flatters) Newsgroups: comp.lang.fortran Subject: Re: Wanted: folk theorems in Fortran Progra Message-ID: <1993Jan27.203653.23536@zia.aoc.nrao.edu> Date: 27 Jan 93 20:36:53 GMT References: <93-01-199@comp.compilers> Sender: news@zia.aoc.nrao.edu Reply-To: cflatter@nrao.edu Organization: NRAO Lines: 29