home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / fortran / 5215 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  1.6 KB

  1. Path: 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
  2. From: cflatter@nrao.edu (Chris Flatters)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: Wanted: folk theorems in Fortran Progra
  5. Message-ID: <1993Jan27.203653.23536@zia.aoc.nrao.edu>
  6. Date: 27 Jan 93 20:36:53 GMT
  7. References: <93-01-199@comp.compilers>
  8. Sender: news@zia.aoc.nrao.edu
  9. Reply-To: cflatter@nrao.edu
  10. Organization: NRAO
  11. Lines: 29
  12.  
  13. In article 199@comp.compilers, dodd@mycenae.cchem.berkeley.edu (Lawrence R. Dodd) writes:
  14. >"Steve" Stevenson <steve@hubcap.clemson.edu> writes:
  15. >> I am trying to make a catalog of folk wisdom in fortran programming.
  16. >
  17. >My personal favorite is the one discussed on page 137 of the 1st edition of
  18. >Numerical Recipes (Fortran edition, of course):
  19. >
  20. >BAD
  21. >
  22. >P = c(1) + c(2)*x + c(3)*x**2 + c(4)*x**3 + c(5)*x**4
  23. >
  24. >GOOD
  25. >
  26. >P = c(1) + x*(c(2) + x*(c(3) + x*(c(4) + x*c(5))))
  27. >
  28. >It is a little harder to read but you won't be `summarily executed'
  29.  
  30. I hope that you don't mean folk wisdom in the sense of things that are
  31. widely believed without justification: there is a good reason for
  32. preferring the latter version.  The former version requires 4
  33. additions, 4 multipications and 3 applications of the power operator
  34. (should total 15 or 16 fp operations using an efficient algorithm for
  35. raising fp numbers to integer powers.  The latter version does not
  36. require application of the power operator.  Not only will it be
  37. approximately twice as fast but it will accumulate less rounding
  38. error.
  39.  
  40.     Chris Flatters
  41.     cflatter@nrao.edu
  42.