home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / programm / 2028 next >
Encoding:
Text File  |  1992-07-21  |  1.9 KB  |  58 lines

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!mcsun!sun4nl!alchemy!jeroen
  3. From: jeroen@cs.ruu.nl (Jeroen Fokker)
  4. Subject: Re: Calculating a cube root
  5. Message-ID: <1992Jul21.085023.11890@cs.ruu.nl>
  6. Date: Tue, 21 Jul 1992 08:50:23 GMT
  7. References: <l624kmINN29e@girtab.usc.edu> <129360001@hpfcso.FC.HP.COM> <1992Jul20.123722.27958@cs.ruu.nl> <1992Jul20.160255.17562@organpipe.uug.arizona.edu>
  8. Organization: Utrecht University, Dept. of Computer Science
  9. Lines: 47
  10.  
  11. dave@cs.arizona.edu (Dave Schaumann) had some remarks about my
  12. cuberoot-program.
  13.  
  14. >> A faster function [than exp(log(x)/3.0)] 
  15. >> uses Newton's method, using iteration
  16.  
  17. > I don't think so [...].  Library routines like exp(), log(), and pow()
  18. > are generally defined using a polynomial expansion, which
  19. > require perhaps 5 floating point multiplies, 
  20.  
  21. This is correct. On my computer, iteration using Newton's method 
  22. is about 5 times slower than using the exp/log method.
  23. However, I believe that it is slightly unfair to compare C-functions
  24. with higly-optimized library routines.
  25.  
  26. >> #define EPSILON 0.00001
  27.  
  28. >  which of course limits the accuracy quite severly.
  29.  
  30. The nice thing about #defined constants is that you can
  31. adapt them to your needs. 
  32.  
  33.  
  34. About the approximate-equal-to-routine he comments:
  35.  
  36. > There's also another advantage to using library routines.  
  37. > Presumably, someone was paid to make sure they are correct.
  38.  
  39. >> return( a-b<EPSILON && b-a<EPSILON );
  40.  
  41. > This expression will always yield 0.
  42.  
  43. Nice try for an insult, but not justified.
  44. Here is the "correctness proof":
  45.  
  46.      a lies within EPS from b  <==>
  47.      a<b+EPS && a>b-EPS        <==>
  48.      a<b+EPS && -a<EPS-b       <==>
  49.      a-b<EPS && b-a<EPS
  50.  
  51. Speaking of correctness: try and calculate cubert(0.0)
  52. using exp(log(x)/3.0).
  53.  
  54. --
  55. Jeroen Fokker                                 |  jeroen@cs.ruu.nl
  56. dept.of Computer Science, Utrecht University  |  tel.+31-30-534129
  57. PObox 80089, 3508TB Utrecht, the Netherlands  |  fax.+31-30-513791
  58.