in reply to Re: Square Root algorithm
in thread Square Root algorithm

I tried your solution on very small numbers such as .000000000323 and the accuracy was way off. I believe it is because you compare the radicand to the square of the guess instead of comparing the last guess to the current guess. At any rate, that is a very short solution, for sure.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot";
$nysus = $PM . $MCF;

Replies are listed 'Best First'.
Re: Square Root algorithm
by cLive ;-) (Prior) on Jun 25, 2001 at 12:27 UTC
    yep,

    Sort of. I think I just mis-read my comparison (got confused coz I was using guess and next guess...)

    Change this:

    while (abs($num - $guess**2) > 1e-13) {
    to the more accurate comparison (with 2 more decimal places of accuracy):
    while (abs($num/$guess - $guess) > 1e-15) {
    and it works fine :)

    cLive ;-)