home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!mcsun!sun4nl!alchemy!jeroen
- From: jeroen@cs.ruu.nl (Jeroen Fokker)
- Subject: Re: Calculating a cube root
- Message-ID: <1992Jul21.085023.11890@cs.ruu.nl>
- Date: Tue, 21 Jul 1992 08:50:23 GMT
- References: <l624kmINN29e@girtab.usc.edu> <129360001@hpfcso.FC.HP.COM> <1992Jul20.123722.27958@cs.ruu.nl> <1992Jul20.160255.17562@organpipe.uug.arizona.edu>
- Organization: Utrecht University, Dept. of Computer Science
- Lines: 47
-
- dave@cs.arizona.edu (Dave Schaumann) had some remarks about my
- cuberoot-program.
-
- >> A faster function [than exp(log(x)/3.0)]
- >> uses Newton's method, using iteration
-
- > I don't think so [...]. Library routines like exp(), log(), and pow()
- > are generally defined using a polynomial expansion, which
- > require perhaps 5 floating point multiplies,
-
- This is correct. On my computer, iteration using Newton's method
- is about 5 times slower than using the exp/log method.
- However, I believe that it is slightly unfair to compare C-functions
- with higly-optimized library routines.
-
- >> #define EPSILON 0.00001
-
- > which of course limits the accuracy quite severly.
-
- The nice thing about #defined constants is that you can
- adapt them to your needs.
-
-
- About the approximate-equal-to-routine he comments:
-
- > There's also another advantage to using library routines.
- > Presumably, someone was paid to make sure they are correct.
-
- >> return( a-b<EPSILON && b-a<EPSILON );
-
- > This expression will always yield 0.
-
- Nice try for an insult, but not justified.
- Here is the "correctness proof":
-
- a lies within EPS from b <==>
- a<b+EPS && a>b-EPS <==>
- a<b+EPS && -a<EPS-b <==>
- a-b<EPS && b-a<EPS
-
- Speaking of correctness: try and calculate cubert(0.0)
- using exp(log(x)/3.0).
-
- --
- Jeroen Fokker | jeroen@cs.ruu.nl
- dept.of Computer Science, Utrecht University | tel.+31-30-534129
- PObox 80089, 3508TB Utrecht, the Netherlands | fax.+31-30-513791
-