Skip to content

Commit

Permalink
fixes #958 (#1040)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-henz authored Jul 10, 2024
1 parent 2eac0ef commit f495d48
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions xml/chapter1/section1/subsection7.xml
Original file line number Diff line number Diff line change
Expand Up @@ -708,23 +708,21 @@ function sqrt_iter(guess, x) {
<REQUIRES>sqrt</REQUIRES>
<REQUIRES>improve</REQUIRES>
<REQUIRES>sqrt_iter</REQUIRES>
<REQUIRES>square_definition</REQUIRES>
<EXAMPLE>example_1.8</EXAMPLE>
<JAVASCRIPT>
const error_threshold = 0.01;
const relative_tolerance = 0.0001;
function is_good_enough(guess, x) {
return relative_error(guess, improve(guess, x))
&lt; error_threshold;
}
function relative_error(estimate, reference) {
return abs(estimate - reference) / reference;
return abs(square(guess) - x) &lt; guess * relative_tolerance;
}
</JAVASCRIPT>
</SNIPPET>
</SOLUTION>
<SNIPPET HIDE="yes">
<NAME>example_1.8</NAME>
<JAVASCRIPT>
sqrt(3);
display(sqrt(0.0001));
display(sqrt(4000000000000));
</JAVASCRIPT>
<SCHEME>
</SCHEME>
Expand Down

0 comments on commit f495d48

Please sign in to comment.