Skip to content
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

qinvgamma returns nan #22

Open
j-faria opened this issue Oct 8, 2020 · 1 comment
Open

qinvgamma returns nan #22

j-faria opened this issue Oct 8, 2020 · 1 comment

Comments

@j-faria
Copy link

j-faria commented Oct 8, 2020

For some inputs (apparently close to 1), qinvgamma is returning nan.
Example:

stats::qinvgamma(0.999551553841898, 2.0, 1.0)

Probably the result of overflow?

@j-faria
Copy link
Author

j-faria commented Oct 14, 2020

I was able to fix the issue by tracing the nan back to the incomplete_gamma_inv function in GCEM.
In the file gcem/include/gcem_incl/incomplete_gamma_inv.hpp changing

...
incomplete_gamma_inv_halley(const T ratio_val_1, const T ratio_val_2)
noexcept
{
    return( ratio_val_1 / max( T(0.8), min( T(1.2), T(1) - T(0.5)*ratio_val_1*ratio_val_2 ) ) );
}

to

...
incomplete_gamma_inv_halley(const T ratio_val_1, const T ratio_val_2)
noexcept
{
    return( ratio_val_1 / ( T(1) - T(0.5)*ratio_val_1*ratio_val_2 ) );
}

recovers the correct result.
All tests pass, although I'm not completely sure why the safeguards were there in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant