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

Fix Issue 833 #835

Merged
merged 4 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@
first = 1;
ak -= 1;
second = 1 - z / b;
if (fabs(second) < 0.5)
second = (b - z) / b; // cancellation avoidance
}
else
{
Expand Down
7 changes: 6 additions & 1 deletion include/boost/math/special_functions/hypergeometric_1F1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,12 @@ namespace boost { namespace math { namespace detail {

// other checks:
if (a == -1)
return 1 - (z / b);
{
T r = 1 - (z / b);
if (fabs(r) < 0.5)
r = (b - z) / b;
return r;
}

const T b_minus_a = b - a;

Expand Down
2 changes: 1 addition & 1 deletion include/boost/math/tools/recurrence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace boost {
{
tie(a, b, c) = get_coefs(-static_cast<int>(k));

if ((log_scaling) &&
if ((log_scaling) && (second != 0) &&
( (fabs(tools::max_value<T>() * (a / b) / 2048) < fabs(second))
|| (fabs(tools::max_value<T>() * (a / c) / 2048) < fabs(first))
|| (fabs(tools::min_value<T>() * (a / b) * 2048) > fabs(second))
Expand Down
36 changes: 35 additions & 1 deletion test/test_1F1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void test_spots5(T, const char* type_name)
template <class T>
void test_spots6(T, const char* type_name)
{
static const std::array<std::array<T, 4>, 153> hypergeometric_1F1_bugs = { {
static const std::array<std::array<T, 4>, 183> hypergeometric_1F1_bugs = { {
{ { static_cast<double>(17955.561660766602), static_cast<double>(9.6968994205831605e-09), static_cast<double>(-82.406154185533524), SC_(6.98056008378736714088730927132364938220428678e-11) }},
{ { static_cast<double>(17955.561660766602), static_cast<double>(-9.6968994205831605e-09), static_cast<double>(-82.406154185533524), SC_(-6.98055306629610746072607353939306734740549551e-11) }},
{ { static_cast<double>(-17955.561660766602), static_cast<double>(-9.6968994205831605e-09), static_cast<double>(82.406154185533524), SC_(-42897094853118832762870100.8669248353530950866) }} ,
Expand Down Expand Up @@ -356,6 +356,40 @@ void test_spots6(T, const char* type_name)
{ { -28, -28, 23.5, SC_(1.3636649055777180973706533952884087e10) } },
{ { -29, -29, 23.5, SC_(1.4288921731123489919940015692546766e10) } },
{ { -30, -30, 23.5, SC_(1.4799868660144765261156243055282531e10) } },
//
// Special cases for 1F1[-n, n, n], recurrence relations explode for these
// so we need to take special care, see:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there supposed to be something after "see:"?

//
{ {-1, 1, 1, 0} },
{ { -2, 2, 2, SC_(-0.33333333333333333333333333333333333) } },
{ { -3, 3, 3, SC_(-0.20000000000000000000000000000000000) } },
{ { -4, 4, 4, SC_(-0.028571428571428571428571428571428571) } },
{ { -5, 5, 5, SC_(0.034391534391534391534391534391534392) } },
{ { -6, 6, 6, SC_(0.025974025974025974025974025974025974) } },
{ { -7, 7, 7, SC_(0.0055458430458430458430458430458430458) } },
{ { -8, 8, 8, SC_(-0.0034844168177501510834844168177501511) } },
{ { -9, 9, 9, SC_(-0.0032789269553975436328377504848093083) } },
{ { -10, 10, 10, SC_(-0.00090655818209997776561244053504115424) } },
{ { -11, 11, 11, SC_(0.00032882634672802494317065057641990169) } },
{ { -12, 12, 12, SC_(0.00040482026290537337976908770901425171) } },
{ { -13, 13, 13, SC_(0.00013693942490239899363731963133279724) } },
{ { -14, 14, 14, SC_(-0.000027114521961598289657552462032956946) } },
{ { -15, 15, 15, SC_(-0.000048914265972106416241933622562193726) } },
{ { -16, 16, 16, SC_(-0.000019682683030825726780784406799223748) } },
{ { -17, 17, 17, SC_(1.5839922420851958320021705281180291e-6) } },
{ { -18, 18, 18, SC_(5.7780970016822066007807309411610877e-6) } },
{ { -19, 19, 19, SC_(2.7286504926687308865490707120168935e-6) } },
{ { -20, 20, 20, SC_(3.0777012229800824850242341264747930e-8) } },
{ { -21, 21, 21, SC_(-6.6559501148858176979489331026765573e-7) } },
{ { -22, 22, 22, SC_(-3.6755193543651782101726439542497979e-7) } },
{ { -23, 23, 23, SC_(-3.2293485126433594872416984294551283e-8) } },
{ { -24, 24, 24, SC_(7.4437711540037326179190703001784924e-8) } },
{ { -25, 25, 25, SC_(4.8312843928329924033336815590280938e-8) } },
{ { -26, 26, 26, SC_(7.5047977770302588786691782818325643e-9) } },
{ { -27, 27, 27, SC_(-8.0223979804469656047588860706683494e-9) } },
{ { -28, 28, 28, SC_(-6.2125286411657869483728921158018766e-9) } },
{ { -29, 29, 29, SC_(-1.3521578972057573423569167878458172e-9) } },
{{ -30, 30, 30, SC_(8.2238878884841599031462003461115991e-10) } },
} };
static const std::array<std::array<T, 4>, 2> hypergeometric_1F1_big_bugs = { {
#if DBL_MAX_EXP == LDBL_MAX_EXP
Expand Down