# Board index » delphi » cube root

## cube root

does any one here know of a cube root algorithm?

## Re:cube root

##### Quote
leste...@tld.net wrote:

> does any one here know of a cube root algorithm?

Just raise the number to the power of a third.

E.g.

Y := X ^ (1/3)
--
_______________________________________________________

Daniel Dyer
_______________________________________________________

## Re:cube root

##### Quote
In article <34E80DBC.2...@ukc.ac.uk>, Daniel Dyer <d...@ukc.ac.uk> wrote:
> leste...@tld.net wrote:

> > does any one here know of a cube root algorithm?
> Just raise the number to the power of a third.

> E.g.

> Y := X ^ (1/3)

Just as a mathematical quibble- this will find only one of the three cube
roots of X. This may be important depending on the problem you are

Erik.

___________________________________________________________________
Dr. Erik Jensen                        tel. (250) 960-6463
Physics Programme                      fax: (250) 960-5545
University of Northern B.C.            email: ejen...@unbc.ca
3333 University Way
Prince George B.C. Canada V2N 4Z9
___________________________________________________________________

## Re:cube root

##### Quote
leste...@tld.net wrote:
>does any one here know of a cube root algorithm?

PROGRAM CubeRoots;
{  1/27/96    <clifp...@airmail.net>  Turbo Pascal 6.0
Using the Exp and Ln functions to perform the power function.
In QBasic you can do x^n but not in Turbo Pascal. In this version,
The entry and cube root are displayed rounded to 8 decimal places.
The two imaginary roots are not shown BUT the approximate error is
shown to 10 places.

Modified specifically for cube roots Mar 25, 1996. Works for both
positive and negative numbers }

VAR
n, root : Real;

FUNCTION CubeRoot(num: Real): Real;
VAR  tmp, x:Real;
positive:Boolean;

BEGIN
positive := num > 0;
num := Abs(num);  { num must be positive }
x := (1/3) * LN(num);   { x is the Ln of the cube root of num }
tmp := EXP(x);  { taking the anti-Ln of x }
If positive then CubeRoot := tmp
Else CubeRoot := -tmp;   {negative root if num was negative}
END;

BEGIN  { main  }
Writeln; Writeln; Writeln('*********** CUBE ROOTS *****************');
Writeln;

REPEAT
Write('Enter a number (0 quits): ');
If n <> 0 then
Begin
root := CubeRoot(n);
Writeln('The cube root of ', n:1:8, ' = ', root:1:8);
Writeln('Error is approx: ', (n - root * SQR(root)):1:10);
End;
Writeln;
UNTIL n = 0;

END.

## Re:cube root

##### Quote
In article <34E7BEFE.E17D0...@tld.net>,  <leste...@tld.net> wrote:

:does any one here know of a cube root algorithm?

Raise the variable to (1.0/3.0). As for the power function missing
from Pascals, see

tsfaqp.zip Common Turbo Pascal Questions and Timo's answers

All the best, Timo

P.S. Please do not post to the absolete comp.lang.pascal

....................................................................
Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/>  ; FIN-65101,  Finland

Spam foiling in effect.  My email filter autoresponder will return a
required email password to users not yet in the privileges database.

## Re:cube root

In article <34E80DBC.2...@ukc.ac.uk>, Daniel Dyer  <d...@ukc.ac.uk> wrote:

##### Quote
:leste...@tld.net wrote:

:> does any one here know of a cube root algorithm?
:E.g.
:Y := X ^ (1/3)

Sorry, it is not that simple. (Hint: no ^ in the usual Pascals)

All the best, Timo

....................................................................
Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/>  ; FIN-65101,  Finland

Spam foiling in effect.  My email filter autoresponder will return a
required email password to users not yet in the privileges database.

## Re:cube root

##### Quote
Daniel Dyer wrote:

> leste...@tld.net wrote:

> > does any one here know of a cube root algorithm?
> Just raise the number to the power of a third.

> E.g.

> Y := X ^ (1/3)
> --
> _______________________________________________________

> Daniel Dyer
> _______________________________________________________

Sorry I'm getting confused.  I've been playing around with too many
different languages and I've just got a huge mess of different stuff in
my head.  I forgot that pascal (TP6 at least) doesn't have the ^
operator (I think I'm confusing it with C64 BASIC and probably some
other languages.).

So for the soultion you need to use logarithms.  This little bit of code
will give you the real root of the number (I don't care about imaginary

PROGRAM Cube_Root;

USES Crt;

VAR
Number:Real;

BEGIN
ClrScr;
Write('Enter a number: ');
WriteLn('The Cube Root of ',Number:1:4,' is
',(Exp((1/3)*Ln(Number))):1:0);
REPEAT UNTIL KeyPressed;
END.
_______________________________________________________

Daniel Dyer
_______________________________________________________

## Re:cube root

Here a small program

program CRoot;

function Potenza(x, p: real): real; {gives you the value of x^p}
begin
Potenza := exp(p * ln (x));
end;

function CubeRoot(x: real): real;
begin
CubeRoot := Potenza(x, (1/3)); {3 means Cube Root, 2 means square
root and so on}
end;

begin
writeln(CubeRoot(8));
end.

##### Quote
leste...@tld.net wrote:
> does any one here know of a cube root algorithm?