From b63125be0b3c495df561dc6c36d1baa9ac1cfc6a Mon Sep 17 00:00:00 2001 From: henz Date: Mon, 1 Jul 2024 19:03:15 +0800 Subject: [PATCH] fixes #958 --- xml/chapter1/section1/subsection7.xml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/xml/chapter1/section1/subsection7.xml b/xml/chapter1/section1/subsection7.xml index 1e5808f73..efb7a524d 100644 --- a/xml/chapter1/section1/subsection7.xml +++ b/xml/chapter1/section1/subsection7.xml @@ -708,15 +708,12 @@ function sqrt_iter(guess, x) { sqrt improve sqrt_iter + square_definition example_1.8 -const error_threshold = 0.01; +const relative_tolerance = 0.0001; function is_good_enough(guess, x) { - return relative_error(guess, improve(guess, x)) - < error_threshold; -} -function relative_error(estimate, reference) { - return abs(estimate - reference) / reference; + return abs(square(guess) - x) < guess * relative_tolerance; } @@ -724,7 +721,8 @@ function relative_error(estimate, reference) { example_1.8 -sqrt(3); +display(sqrt(0.0001)); +display(sqrt(4000000000000));