in reply to Square Root algorithm
Well, first up your regex fails on an integer.
And I usually shy away from ariels notation, because to me 1e-18 says e^-18 rather than 10^-18. That always bugged me. Personally I'd rather use 10**(-18).
As for your concern about calling new_guess twice, why not try this?
my $n=0; Hahaha: $guess = new_guess($guess, $x); # MAKE OLD GUESS THE NEW GUESS AND RUN + WHILE LOOP AGAIN $n=new_guess($guess, $x); goto Hahaha if get_accuracy($guess, $n) > .000000000000000001 { # CHE +CK DIFFERENCE BETWEEN OLD GUESS AND NEW GUESS
Actually this should work fine:
my ($guess, $x) = @_; my $n=0; while ( get_accuracy($guess, $n) > .000000000000000001) { # C +HECK DIFFERENCE BETWEEN OLD GUESS AND NEW GUESS $guess = $n; $n=new_guess($guess, $x); # MAKE OLD GUESS THE NEW GUESS AND RUN WHI +LE LOOP AGAIN }
____________________
Jeremy
I didn't believe in evil until I dated it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Square Root algorithm
by ariels (Curate) on Jun 25, 2001 at 13:42 UTC | |
by mamut (Sexton) on Jun 26, 2001 at 12:07 UTC | |
by ariels (Curate) on Jun 26, 2001 at 14:39 UTC | |
by Anonymous Monk on Dec 02, 2001 at 13:03 UTC |