From 6f1309c48af8fcd9b929b30445cc631120a63eb8 Mon Sep 17 00:00:00 2001
From: David Dorchies <david.dorchies@irstea.fr>
Date: Tue, 30 Jul 2019 11:36:15 +0200
Subject: [PATCH] Improving stop criteria of brent solver (related to #116 )

---
 src/dichotomie.ts | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/dichotomie.ts b/src/dichotomie.ts
index 0bc2f5d4..0233446f 100644
--- a/src/dichotomie.ts
+++ b/src/dichotomie.ts
@@ -517,7 +517,13 @@ export class Dichotomie extends Debug {
             tolAct = 1e-15 * Math.abs(b) + errorTol / 2;
             newStep = (c - b) / 2;
 
-            if (Math.abs(newStep) <= tolAct && Math.abs(fb) < 0.1) {
+            if (
+                Math.abs(newStep) <= tolAct
+                && (
+                    Math.abs(fb) < errorTol
+                    || Math.abs(fb / (Math.abs(fb) - Math.abs(fc))) < 1
+                )
+            ) {
                 return b; // Acceptable approx. is found
             }
 
-- 
GitLab