]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
regress: fix robust regression
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 22 Jun 2017 13:35:37 +0000 (15:35 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 27 Jun 2017 13:29:01 +0000 (15:29 +0200)
The bisection always terminated after one iteration. Change the code to
check if the middle is different from the lower and upper limits as
suggested in the original recipe.

This fixes commit b14689d59b06ec21a9e079c65a0882b7bf457448.

regress.c

index cac0332de1211aef8099ce65e1c286916bf59de3..c4f8dd581189fc8fd7e31410d128ab919e61e193 100644 (file)
--- a/regress.c
+++ b/regress.c
@@ -594,6 +594,8 @@ RGR_FindBestRobustRegression
     /* OK, so the root for b lies in (blo, bhi). Start bisecting */
     do {
       bmid = 0.5 * (blo + bhi);
+      if (!(blo < bmid && bmid < bhi))
+        break;
       eval_robust_residual(x + start, y + start, n_points, bmid, &a, &rmid);
       if (rmid == 0.0) {
         break;
@@ -606,7 +608,7 @@ RGR_FindBestRobustRegression
       } else {
         assert(0);
       }
-    } while ((bhi - blo) > tol && (bmid - blo) * (bhi - bmid) > 0.0);
+    } while (bhi - blo > tol);
 
     *b0 = a;
     *b1 = bmid;