Cubed root of a number

As far as I know there is no "formula" for finding the cube of a number, so here is a good guess algorythm.

Pass the number in "Number", followed by your "Best guess".

Your best guess can be anything (Number div 2) if you have no idea.



function CubedRoot(Number: Integer; BestGuess: Real): Real;

var

  G,

  LastGuess : Real;

begin

  LastGuess := 0;

  G := BestGuess;

  while (G*G*G <> Number) and (LastGuess <> G) do begin

    LastGuess := G;

    G := (2/3) *G + (1/3) * (Number / (G * G));

  end;

  CubedRoot := G;

end;

 

Share this article!

Follow us!

Find more helpful articles: