TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Patrick Annette
from: Russ Parks
date: 1995-12-18 22:53:04
subject: Cube root

Patrick Annette wrote in a message to David Noon:

 DN> uses 2**(y*LOG2(x)) in order to evaluate x**y; almost as
 DN> inefficient as EXP(y*LN(x)).

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

 Here's some old TurboPascal 6.0 code I've been using for quite a
while...it's a bit shorter than what you have (maybe faster?).

type Float = Extended;

function Power(Base, Exponent: Float): Float; Assembler;
 var OldCw, TempCw: Word;
asm
   fld          Exponent
   fld          Base
   fyl2x
   fld          st(0)
   fstcw        [OldCw]
   mov          ax, [OldCw]
   and          ax, 0F3FFh
   or           ax, 0C00h
   mov          [TempCw], ax
   fldcw        word ptr [TempCw]
   frndint
   fsubr        st, st(1)
   f2xm1
   fld1
   faddp        st(1), st
   fscale
   fstp         st(1)
   fldcw        [OldCw]
end;


Russ

..."Do you think God lets you plea bargain?" -- Calvin
--- EZQuote 4.0
* Origin: Linux: The choice of a GNU generation (1:170/200.12)
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: 170/200 400 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™.