diff scripts/specfun/betaincinv.m @ 29614:26ba91f0eea7 stable

betaincinv.m: Correctly handle small inputs (bug #60528) * betaincinv.m (newtons_method): if any value of x is less than zero, replace with eps() to make the value minimally positive. Add BIST test for bug #60528.
author Rik <rik@octave.org>
date Wed, 05 May 2021 14:12:23 -0700
parents 0a5b15007766
children f6151f915e3c 69b6b783a8ab
line wrap: on
line diff
--- a/scripts/specfun/betaincinv.m	Fri Apr 30 15:02:13 2021 +0200
+++ b/scripts/specfun/betaincinv.m	Wed May 05 14:12:23 2021 -0700
@@ -233,6 +233,7 @@
   while (any (todo) && (it < maxit))
     it++;
     x(todo) += res(todo);
+    x(x(todo) < 0) = eps;  # Avoid negative x in betainc() call, bug #60528
     res(todo) = -F(x(todo), a(todo), b(todo), y(todo)) ...
                 ./ JF (x(todo), a(todo), b(todo));
     todo = (abs(res) >= tol * abs (x));
@@ -278,6 +279,8 @@
 %!assert (class (betaincinv (int8 (0), single (1), 1)), "single")
 %!assert (class (betaincinv (single (0.5), int8 (1), 1)), "single")
 
+%!assert <*60528> (betaincinv (1e-6, 1, 3), 3.3333344444450657e-07, eps)
+
 ## Test input validation
 %!error betaincinv ()
 %!error betaincinv (1)