| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Cube root |
Mike Fisher wrote in a message to RICHARD SKINNER: RS> I was wondering, in pascal, how do I return the Cube Root of a number? RS> I'm using BP7, I see a SQRT but I don't see anything for the cube root RS> and its been so long since school I just can't remember.:) RS> Any help would be appreciated, MF> The cube root of P is the antilogarithm of one-third of the MF> logarithm of P. MF> ie. in Pascal, to calculate the Qth root of P ... MF> root:=exp(ln(P)/Q); Am I really missing something here, or does Pascal have no support for direct exponentiation? The Qth root of P is equal to P raised to the 1/Q power. Using C, it is a heck of a lot more efficient to compute a Qth root as such: double P, Q, root; root = pow(P, 1.0 / Q); It is perfectly legal and valid to use logarithmic calculations, but why? root = exp(log(P) / Q); The direct exponentiation form uses a double precision special case division -- taking a reciprocal -- which corresponds to a machine instruction on the Intel math coprocessor, while the logarithmic form uses a double precision division that is not a special case. The direct exponentiation form also incurs one function call, while the logarithmic form incurs two. -- Mike ---* 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™.