Mercurial > octave
changeset 25021:592db8745f26 stable
betainc.m: Use parentheses to control order of addition to reduce round-off error.
* betainc.m: Use parentheses around calculation of factor log(Beta(a,b)) so that
numbers of comparable magnitude are added and subtracted which reduces round-off
error.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 27 Mar 2018 09:25:33 -0700 |
parents | 3b08577e6816 |
children | fdff879d8ae8 20f7a4606348 |
files | scripts/specfun/betainc.m |
diffstat | 1 files changed, 2 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/specfun/betainc.m Mon Mar 26 21:15:42 2018 -0700 +++ b/scripts/specfun/betainc.m Tue Mar 27 09:25:33 2018 -0700 @@ -147,8 +147,8 @@ f = __betainc__ (x, a, b); ## Divide continued fraction by B(a,b) / (x^a * (1-x)^b) to obtain I_x(a,b). - y = a .* log (x) + b .* log1p (-x) + gammaln (a + b) - ... - gammaln (a) - gammaln (b) + log (f); + y = a .* log (x) + b .* log1p (-x) ... + + (gammaln (a + b) - gammaln (a) - gammaln (b)) + log (f); y = real (exp (y)); y(fflag) = 1 - y(fflag);