Estimate standard deviation of b and expand range about b based
on that. */
sb = sqrt(s2 * W/V);
- if (sb > 0.0) {
+ if (sb > tol) {
incr = 3.0 * sb;
} else {
incr = 3.0 * tol;
bhi = b;
do {
+ /* Make sure incr is significant to blo and bhi */
+ while (bhi + incr == bhi || blo - incr == blo) {
+ incr *= 2;
+ }
+
blo -= incr;
bhi += incr;
eval_robust_residual(x + start, y + start, n_points, blo, &a, &rlo);
eval_robust_residual(x + start, y + start, n_points, bhi, &a, &rhi);
- } while (rlo * rhi > 0.0); /* fn vals have same sign, i.e. root not
- in interval. */
+ } while (rlo * rhi >= 0.0); /* fn vals have same sign or one is zero,
+ i.e. root not in interval (rlo, rhi). */
/* OK, so the root for b lies in (blo, bhi). Start bisecting */
do {
} else {
assert(0);
}
- } while ((bhi - blo) > tol);
+ } while ((bhi - blo) > tol && (bmid - blo) * (bhi - bmid) > 0.0);
*b0 = a;
*b1 = bmid;