| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Cube root |
Quoting Brian Converse to Mike Bilow in a message dated 12/08
BC> One would hope that an optimizing compiler manages to reduce
BC> the log. form to the power form. Exp, log, and (I think) power
BC> are intrinsic Intel FPU functions
PMJI, but none of these are intrinsic to the FPU. The FPU has some
instructions to do things like raise 2 to a power (F2XM1, gives 2**x-1),
take a logarithm to base 2 (FYL2X gives y*log(base 2)_of_x), and raise 2
to a power. Power(y,x) can be calculated by combining these with other
FPU instructions. About 35 assembler instructions are needed to code it
using the formula
y**x=2**((x)*(base2log(y)).
BC> but are all done using
BC> a microcoded series and interpolation approach. Using the
BC> log form not only incurs more function calls, but also cascades
BC> errors in precision. One strives to avoid cascaded operations
BC> unless needed.
True, but if the function isn't included with the compiler (as it wasn't
with earlier versions of C and Fortran), there's not much choice.
BC> MB> Am I really missing something here, or does Pascal have no
BC> MB> support for direct exponentiation?
BC>
BC> From the $9 FIRST edition ('82) of Oh! Pascal!, one learns:
BC>
BC> "The logarithm functions help overcome a shortcoming in Pascal
BC> that often annoys programmers -- the lack of a specific
BC> exponentiation operator. There's no predefined function for
BC> raising a number (call it a) to some power (call it n), as
BC> in..." Cooper and Clancy recommend "exp(n*ln(a))" for this.
BC>
BC> So, the multiple operations are mandated. Perhaps, though,
BC> Pascal implementations seek out such forms and fix them up
BC> at the back end of the compiler...or perhaps the microproc.
BC> based versions, none of which I've used, add the missing
BC> power function.
AFAIK, most Pascals still don't have a power function. I can't say I've
felt the lack, but after seeing the discussion here of the missing power
function, being a masochist, I got out my copy of Richard Startz's book
on programming the 8087 and went to work coding power(y,x) using Virtual
Pascal's built-in assembler. Fun, fun, fun... well, maybe not, but it
works. There's no reason Pascal can't have a power function just as fast
and accurate as the one in C.
Quoting from the K & R book 'The C Programming Language'
"Since C has no exponentiation operator like the ** of Fortran or PL/I,
let us illustrate the mechanics of function definition by writing a
function power(m,n) to raise an integer m to a positive integer n." (page
22)
Apparently most C compilers now include a good power function in the
math library. No reason this can't happen in Pascal if enough people
want it.
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™.