| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Cube root |
MB> The Qth root of P is
MB> equal to P raised to the 1/Q power. Using C, it is a heck
MB> of a lot more efficient to compute a Qth root as such:
MB>
MB> double P, Q, root;
MB>
MB> root = pow(P, 1.0 / Q);
MB>
MB> It is perfectly legal and valid to use logarithmic calculations,
MB> but why?
MB>
MB> root = exp(log(P) / Q);
MB>
MB> The direct exponentiation form uses a double precision
MB> special case division -- taking a reciprocal -- which
MB> corresponds to a machine instruction on the Intel math
MB> coprocessor, while the logarithmic form uses a double
MB> precision division that is not a special case. The direct
MB> exponentiation form also incurs one function call, while
MB> the logarithmic form incurs two.
One would hope that an optimizing compiler manages to reduce
the log. form to the power form. Exp, log, and (I think) power
are intrinsic Intel FPU functions, but are all done using
a microcoded series and interpolation approach. Using the
log form not only incurs more function calls, but also cascades
errors in precision. One strives to avoid cascaded operations
unless needed.
MB> Am I really missing something here, or does Pascal have no
MB> support for direct exponentiation?
From the $9 FIRST edition ('82) of Oh! Pascal!, one learns:
"The logarithm functions help overcome a shortcoming in Pascal
that often annoys programmers -- the lack of a specific
exponentiation operator. There's no predefined function for
raising a number (call it a) to some power (call it n), as
in..." Cooper and Clancy recommend "exp(n*ln(a))" for this.
So, the multiple operations are mandated. Perhaps, though,
Pascal implementations seek out such forms and fix them up
at the back end of the compiler...or perhaps the microproc.
based versions, none of which I've used, add the missing
power function.
They then continue, "...Wirth decided not to define an
exponentiation operator to make Pascal more compact and to
encourage programmers to employ more efficient ways of
finding powers..." {Perhaps, say, 20MB of table look-up?}
"...Some people think he was penny wise and pound foolish."
which brings up (from my fortune cookie thrower):
"Niklaus Wirth has lamented that, whereas Europeans pronounce his
name correctly (Ni-klows Virt), Americans invariably mangle it
into (Nick-les Worth). Which is to say that Europeans call him by
name, but Americans call him by value."
___
X KWQ/2 1.2i X Free Avalonia! Back under North American control!
--- Maximus/2 3.00
* Origin: N1BEE BBS +1 401 944 8498 V.34/V.FC/V.32bis/HST16.8 (1:323/107)SEEN-BY: 270/101 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407 SEEN-BY: 712/515 517 628 713/888 800/1 7877/2809 @PATH: 323/107 150 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™.