Mercurial > octave
changeset 29616:69b6b783a8ab stable
betaincinv.m: Correctly handle inputs very close to 1.0 (bug #60528)
* betaincinv.m (newtons_method): if any value of x is greater than zero,
replace with 1-eps() to make the value minimally less than 1. Add BIST test
for bug #60528.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 05 May 2021 14:26:44 -0700 |
parents | 26ba91f0eea7 |
children | 69e701caf5f6 07dc3ad56d74 |
files | scripts/specfun/betaincinv.m |
diffstat | 1 files changed, 6 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/specfun/betaincinv.m Wed May 05 14:12:23 2021 -0700 +++ b/scripts/specfun/betaincinv.m Wed May 05 14:26:44 2021 -0700 @@ -233,10 +233,12 @@ while (any (todo) && (it < maxit)) it++; x(todo) += res(todo); - x(x(todo) < 0) = eps; # Avoid negative x in betainc() call, bug #60528 + ## Avoid intermediate values outside betainc() range of [0, 1], bug #60528 + x(x(todo) < 0) = eps; + x(x(todo) > 1) = 1-eps; res(todo) = -F(x(todo), a(todo), b(todo), y(todo)) ... ./ JF (x(todo), a(todo), b(todo)); - todo = (abs(res) >= tol * abs (x)); + todo = (abs (res) >= tol * abs (x)); endwhile x += res; endfunction @@ -279,7 +281,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) +%!assert <*60528> (betaincinv (1e-6, 1, 3), 3.3333344444450657e-07, 5*eps) +%!assert <*60528> (betaincinv (1-1e-6, 3, 1), 0.999999666666556, 5*eps) ## Test input validation %!error betaincinv ()