Skip to content

Commit f495d48

Browse files
authored
fixes #958 (#1040)
1 parent 2eac0ef commit f495d48

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

xml/chapter1/section1/subsection7.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -708,23 +708,21 @@ function sqrt_iter(guess, x) {
708708
<REQUIRES>sqrt</REQUIRES>
709709
<REQUIRES>improve</REQUIRES>
710710
<REQUIRES>sqrt_iter</REQUIRES>
711+
<REQUIRES>square_definition</REQUIRES>
711712
<EXAMPLE>example_1.8</EXAMPLE>
712713
<JAVASCRIPT>
713-
const error_threshold = 0.01;
714+
const relative_tolerance = 0.0001;
714715
function is_good_enough(guess, x) {
715-
return relative_error(guess, improve(guess, x))
716-
&lt; error_threshold;
717-
}
718-
function relative_error(estimate, reference) {
719-
return abs(estimate - reference) / reference;
716+
return abs(square(guess) - x) &lt; guess * relative_tolerance;
720717
}
721718
</JAVASCRIPT>
722719
</SNIPPET>
723720
</SOLUTION>
724721
<SNIPPET HIDE="yes">
725722
<NAME>example_1.8</NAME>
726723
<JAVASCRIPT>
727-
sqrt(3);
724+
display(sqrt(0.0001));
725+
display(sqrt(4000000000000));
728726
</JAVASCRIPT>
729727
<SCHEME>
730728
</SCHEME>

0 commit comments

Comments
 (0)