Skip to content

BUG: special/cdflib: fix fatal loss of precision issues in cumfnc #7858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2017

Conversation

pv
Copy link
Member

@pv pv commented Sep 14, 2017

Replace gammaln(a+b)-gammaln(a)-gammaln(b) -> -betaln(a,b)
to avoid loss of precision in cancellations for large a, and
make use of gammaln(a+1) == gammaln(a) + log(a) for a > 0.

Whether the previous code worked correctly or not for very large values depends
on floating point issues --- it is dangerous to rely on
gammaln(a) and gammaln(a+b) returning exactly the same floating point
value when a==a+b up to fp precision, as this is apparently not
guaranteed by gfortran optimizations.

Fixes gh-7828

There in principle may be other issues with this function since
it does not appear to be properly tested, but this is at least one obviously
correct fix...

Replace gammaln(a+b)-gammaln(a)-gammaln(b) -> -betaln(a,b)
to avoid loss of precision in cancellations for large a, and
make use of gammaln(a+1) == gammaln(a) + log(a) for a > 0.

Whether the previous code worked correctly or not for very large values
depends on floating point issues --- it is dangerous to rely on
gammaln(a) and gammaln(a+b) returning exactly the same floating point
value when a==a+b up to fp precision, as this is apparently not
guaranteed by gfortran optimizations.
@rgommers rgommers added maintenance Items related to regular maintenance tasks scipy.special labels Sep 15, 2017
@rgommers rgommers added this to the 1.0.0 milestone Sep 15, 2017
@rgommers rgommers merged commit a5c4906 into scipy:master Sep 15, 2017
@rgommers
Copy link
Member

LGTM, merged. Thanks Pauli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Items related to regular maintenance tasks scipy.special
Projects
None yet
Development

Successfully merging this pull request may close these issues.

32-bit Linux test errors on TestCephes
2 participants