TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: David Noon
from: Patrick Annette
date: 1995-12-17 15:08:12
subject: Cube root

Quoting David Noon to George White in a message dated 12/12

DN> On Monday, 95/12/11, George White wrote to David Noon about "Cube
DN> root" as follows:
DN> 
DN> GW> DN>took about 40% less time than using pow(). I think that pow() is
DN> GW> DN>implemented in the BCAF 3.1 run-time as exp(log())
without any further
DN> GW> DN>thought on Borland's part.
DN> GW> 
DN> GW> I've just looked, its coded in assembler in the run time library
DN> GW> source.
DN> 
DN> Hi George,
DN> 
DN> I just took a look at the source too. It is in assembler, but it
DN> uses 2**(y*LOG2(x)) in order to evaluate x**y; almost as inefficient
DN> as EXP(y*LN(x)). 

Dave, given that it has to be computed using instructions available to
the FPU, how would you code it?  AFAIK the method you describe makes the
best possible use of the FPU for this function.  The FPU has no general
exponentiation instruction (only one for raising 2 to a power) and the
only logarithms it does are to base 2.  If you know a more efficient
algorithm for the Intel FPU, I'd -love- to know about it, since I'm
using 2**(y*LOG2(x)) in an assembly language math unit I've started
writing for Virtual Pascal.  (so far power is the only thing done)

2**(y*LOG2(x)) is all done in a single call to a FPU procedure, and
errors from converting FPU temporary real numbers (80 bits) to C double
precision reals (64 bits) don't accumulate, only happening when the
result is returned.  Techniques are (or *should be*) used in the
procedure to attain an effective word length greater than 80 bits.

EXP(y*LN(x)) isn't just slower, it's more subject to errors.  The FPU
has no direct EXP or LN instruction.  There will be three calls to FPU
procedures (wasting time, of course): LN, then a multiplication, then
EXP.  Conversion errors occur at each return, and accumulate.  There are
inevitably errors in each procedure call as well.  

just my $.02 worth 

Patrick

___
 X KWQ/2 1.2i X I'm not young enough to know everything anymore...
--- Maximus/2 2.02
* Origin: OS/2 Online * Auburn, WA * 206-351-5998 * (1:343/212)
SEEN-BY: 270/101 620/243 711/401 409 410 413 430 808 809 934 955 712/407 515
SEEN-BY: 712/517 628 713/888 800/1 7877/2809
@PATH: 343/212 800 1 138/103 3615/50 396/1 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.