-
Notifications
You must be signed in to change notification settings - Fork 244
Fix lower incomplete gamma functions with x = 0 #1251
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7503be4
Fix lower incomplete gamma functions with x = 0
cohomology 410f748
Implement suggestions by jzmaddock
cohomology 517212e
Merge branch 'develop' into mydevelop
cohomology 5a30520
Merge remote-tracking branch 'origin' into mydevelop
cohomology 0d6ff71
Incomplete Gamma: Restore previous overflow check
cohomology File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| // (C) Copyright Kilian Kilger 2025. | ||
| // Use, modification and distribution are subject to the | ||
| // Boost Software License, Version 1.0. (See accompanying file | ||
| // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
|
||
| #define BOOST_TEST_MAIN | ||
|
|
||
| #include <boost/test/unit_test.hpp> | ||
| #include <boost/test/tools/floating_point_comparison.hpp> | ||
| #include <boost/test/unit_test.hpp> | ||
| #include <boost/test/results_collector.hpp> | ||
| #include <boost/math/special_functions/gamma.hpp> | ||
| #include <boost/multiprecision/cpp_bin_float.hpp> | ||
|
|
||
| using namespace std; | ||
| using namespace boost::math; | ||
| using namespace boost::math::policies; | ||
| using namespace boost::multiprecision; | ||
|
|
||
| typedef policy< | ||
| policies::domain_error<errno_on_error>, | ||
| policies::pole_error<errno_on_error>, | ||
| policies::overflow_error<errno_on_error>, | ||
| policies::evaluation_error<errno_on_error> | ||
| > c_policy; | ||
|
|
||
| template<typename T> | ||
| struct test_lower | ||
| { | ||
| T operator()(T a, T x) const | ||
| { | ||
| return tgamma_lower(a, x, c_policy()); | ||
| } | ||
|
|
||
| T expected(T a) const | ||
| { | ||
| return T(0.0); | ||
| } | ||
| }; | ||
|
|
||
| template<typename T> | ||
| struct test_upper | ||
| { | ||
| T operator()(T a, T x) const | ||
| { | ||
| return tgamma(a, x, c_policy()); | ||
| } | ||
| T expected(T a) const | ||
| { | ||
| return tgamma(a, c_policy()); | ||
| } | ||
| }; | ||
|
|
||
| template<typename T> | ||
| struct test_gamma_p | ||
| { | ||
| T operator()(T a, T x) const | ||
| { | ||
| return gamma_p(a, x, c_policy()); | ||
| } | ||
| T expected(T) const | ||
| { | ||
| return T(0.0); | ||
| } | ||
| }; | ||
|
|
||
| template<typename T> | ||
| struct test_gamma_q | ||
| { | ||
| T operator()(T a, T x) const | ||
| { | ||
| return gamma_q(a, x, c_policy()); | ||
| } | ||
| T expected(T) const | ||
| { | ||
| return T(1.0); | ||
| } | ||
| }; | ||
|
|
||
| template<typename T, template<typename> class Fun> | ||
| void test_impl(T a) | ||
| { | ||
| Fun<T> fn; | ||
| errno = 0; | ||
| T x = T(0.0); | ||
| T result = fn(a, x); | ||
| int saveErrno = errno; | ||
|
|
||
| errno = 0; | ||
|
|
||
| T expected = fn.expected(a); | ||
|
|
||
| BOOST_CHECK(errno == saveErrno); | ||
| BOOST_CHECK_EQUAL(result, expected); | ||
| } | ||
|
|
||
| template<template<typename> class Fun, typename T> | ||
| void test_type_dispatch(T val) | ||
| { | ||
| if (val <= (std::numeric_limits<float>::max)()) | ||
| test_impl<float, Fun>(static_cast<float>(val)); | ||
| if (val <= (std::numeric_limits<double>::max)()) | ||
| test_impl<double, Fun>(static_cast<double>(val)); | ||
| #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS | ||
| test_impl<long double, Fun>(static_cast<long double>(val)); | ||
| #endif | ||
| test_impl<cpp_bin_float_50, Fun>(static_cast<cpp_bin_float_50>(val)); | ||
| } | ||
|
|
||
| template<template<typename> class Fun> | ||
| void test_impl() | ||
| { | ||
| test_type_dispatch<Fun, double>(1.0); | ||
| test_type_dispatch<Fun, double>(0.1); | ||
| test_type_dispatch<Fun, double>(0.5); | ||
| test_type_dispatch<Fun, double>(0.6); | ||
| test_type_dispatch<Fun, double>(1.3); | ||
| test_type_dispatch<Fun, double>(1.5); | ||
| test_type_dispatch<Fun, double>(2); | ||
| test_type_dispatch<Fun, double>(100); | ||
| test_type_dispatch<Fun, double>((std::numeric_limits<float>::max)()); | ||
| test_type_dispatch<Fun, double>((std::numeric_limits<double>::max)()); | ||
| #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS | ||
| test_type_dispatch<Fun, long double>((std::numeric_limits<long double>::max)()); | ||
| #endif | ||
| } | ||
|
|
||
| void test_derivative() | ||
| { | ||
| double derivative = 0; | ||
| double result = boost::math::detail::gamma_incomplete_imp(1.0, 0.0, | ||
| true, false, c_policy(), &derivative); | ||
| BOOST_CHECK(errno == 0); | ||
| BOOST_CHECK_EQUAL(derivative, 0); | ||
| BOOST_CHECK_EQUAL(result, 0); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_CASE( test_main ) | ||
| { | ||
| test_impl<test_lower>(); | ||
| test_impl<test_upper>(); | ||
| test_impl<test_gamma_p>(); | ||
| test_impl<test_gamma_q>(); | ||
| test_derivative(); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to let this line execute without the check for
x > 0, that way our root finder will get a derivative back: in this particular case, any arbitrary large value will do.... ah but there should be anelsebefore the*p_derivative /= x;.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I adjusted the coding. Is it okay now?
I also corrected some wrong ternary operators in the file which prevent using some functions with non-standard float/double T template parameters.