-
-
Notifications
You must be signed in to change notification settings - Fork 742
phobos#10826 improved handling of beta function edge cases #10846
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
Conversation
Use of rndtol to determine which domain x belongs to is replaced with trunc. rndtol depends on rounding mode. Depending on the mode, rndtol(-1.5) could be -2 or -1, which map to different domains with different signs. trunc doesn't depend on rounding mode. trunc(-1.5) is always -1.
Fix the large value method of computing std.mathspecial.beta so that it recovers the signs of gamma(x), gamma(y), and gamma(x+y).
Thanks for your pull request and interest in making D better, @tedgin! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
|
In prepration for handling the edge cases in beta, the logic that computes beta when gamma would overflow was moved to a separate function. This will allow the logic to be called from multiple places in beta.
The implemntation of beta was extend to handle the special cases of beta(x, y) where when using the main algorithm to compute beta, results in gamma(x), gamma(y), or gamma(x+y) not being finite, causing beta to appear to not be defined even when it is.
Is this able to be merged? |
Yes, sorry, was preoccupied with travel and Dconf. |
The implementation
std.mathspecial.beta(x, y)
of B(x,y) is extended to handle its edge cases that occur when using the main algorithmgamma(x) * gamma(y) / gamma(x + y)
to compute B(x,y). Theses cases happen in the regions of the (x,y) plane wheregamma(x)
,gamma(y)
, orgamma(x+y)
is not finite. These causebeta(x, y)
to return NaN in regions where B(x,y) exists. This PR extendsbeta
to cover the following cases.logGamma
is extended to every region where |Γ(x)|, |Γ(y)|, or |Γ(x+y)| is too large to be represented with areal
Extending
beta
in this way required the recent bug fixes tobeta
andsgnGamma
to be in place, so these where cherry picked from the stable branch into this PR.The resulting implementation of
beta
is no longer a few lines of code, so it was moved into a new eponymous function in the modulestd.internal.math.gammafunction
. This required the implementation ofsgnGamma
to be moved into an new eponymous function in the same module as well. I made this a separate commit, in case I shouldn't have done this.The larger value algorithm for compute B is used two times in the new implementation of
beta
, so I moved this logic out ofbeta
and into a new functionbetaLarge
. I made this a separate commit, in case I shouldn't have done this.