File tree Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -708,23 +708,21 @@ function sqrt_iter(guess, x) {
708
708
<REQUIRES >sqrt</REQUIRES >
709
709
<REQUIRES >improve</REQUIRES >
710
710
<REQUIRES >sqrt_iter</REQUIRES >
711
+ <REQUIRES >square_definition</REQUIRES >
711
712
<EXAMPLE >example_1.8</EXAMPLE >
712
713
<JAVASCRIPT >
713
- const error_threshold = 0.01 ;
714
+ const relative_tolerance = 0.0001 ;
714
715
function is_good_enough(guess, x) {
715
- return relative_error(guess, improve(guess, x))
716
- < error_threshold;
717
- }
718
- function relative_error(estimate, reference) {
719
- return abs(estimate - reference) / reference;
716
+ return abs(square(guess) - x) < guess * relative_tolerance;
720
717
}
721
718
</JAVASCRIPT >
722
719
</SNIPPET >
723
720
</SOLUTION >
724
721
<SNIPPET HIDE =" yes" >
725
722
<NAME >example_1.8</NAME >
726
723
<JAVASCRIPT >
727
- sqrt(3);
724
+ display(sqrt(0.0001));
725
+ display(sqrt(4000000000000));
728
726
</JAVASCRIPT >
729
727
<SCHEME >
730
728
</SCHEME >
You can’t perform that action at this time.
0 commit comments