| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Cube root |
On Sunday, 95/12/17, Patrick Annette wrote to David Noon about "Cube root" as follows: PA> DN> GW> DN>took about 40% less time than using pow(). I think that pow() is PA> DN> GW> DN>implemented in the BCAF 3.1 run-time as PA> DN> GW> exp(log()) without any further PA> DN> GW> DN>thought on Borland's part. PA> DN> GW> PA> DN> GW> I've just looked, its coded in assembler in the run time library PA> DN> GW> source. PA> DN> PA> DN> I just took a look at the source too. It is in assembler, but it PA> DN> uses 2**(y*LOG2(x)) in order to evaluate x**y; almost as inefficient PA> DN> as EXP(y*LN(x)). PA> PA> Dave, given that it has to be computed using instructions PA> available to the FPU, how would you code it? AFAIK the method you PA> describe makes the best possible use of the FPU for this function. PA> The FPU has no general exponentiation instruction (only one for Hi Patrick, Firstly, there are extremely good (fast!) integer instructions that can get you close to the cube root, before the FPU is even involved. The first statement in your quote of my earlier message indicates that I do know a faster algorithm for calculating cube roots, which was the original gist of this message thread, PA> 2**(y*LOG2(x)) is all done in a single call to a FPU procedure, That is fine for general exponentiation, but that is less than optimal for calculating cube roots. Also, a negative number can have a cube root but not a general non-integer power. [At least not in the domain of real numbers. Of course, PL/I has native support for complex numbers. ... :-) I couldn't resist the plug.] I think we are talking apples and oranges here. I was on about cube roots, not x**y. PA> EXP(y*LN(x)) isn't just slower, it's more subject to errors. The Actually it isn't much slower, nor more error prone. You simply use the FPU instruction for log2(x) and multiply by ln(2), a constant, to get ln(x); similarly for exp(x). The rounding errors for the additional multiply are swamped by the conversion from 80-bit ST() registers back to 64-bit doubles. However, using base 2 logarithm and antilogarithm avoids the extra multiplication completely. Regards Dave * KWQ/2 1.2i * Program call to load Windows NT- "Here_piggy_piggy_piggy" --- Maximus/2 3.00* Origin: DoNoR/2,Woking UK (44-1483-725167) (2:440/4) 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: 440/4 141/209 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™.