Skip to content

Commit 1290be6

Browse files
authored
Merge pull request #1259 from boostorg/scipy21725
Fix for inverse ibeta with large a,b.
2 parents a2fbc93 + deb4391 commit 1290be6

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

include/boost/math/special_functions/detail/ibeta_inverse.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,17 @@ BOOST_MATH_GPU_ENABLED T ibeta_inv_imp(T a, T b, T p, T q, const Policy& pol, T*
683683
}
684684
else
685685
y = 1;
686-
if(y > 1e-5)
686+
if((y > 1e-5) && (std::min)(a, b) < 1000)
687687
{
688688
x = temme_method_3_ibeta_inverse(a, b, p, q, pol);
689689
y = 1 - x;
690690
}
691+
else if ((y > 1e-5) && (std::min)(a, b) > 1000)
692+
{
693+
// All options have failed, use the saddle point as a starting location:
694+
x = (std::max)(a, b) / (a + b);
695+
y = (std::min)(a, b) / (a + b);
696+
}
691697
}
692698
}
693699
}

test/test_ibeta_inv.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,5 +320,14 @@ void test_spots(T)
320320
BOOST_CHECK((boost::math::isfinite)(boost::math::ibeta_inv(m, m, static_cast<T>(0.125))));
321321
}
322322
#endif
323+
//
324+
// scipy: https://github.com/scipy/scipy/issues/21725
325+
//
326+
BOOST_CHECK_CLOSE(
327+
::boost::math::ibeta_inv(
328+
static_cast<T>(1.0e11L),
329+
static_cast<T>(1.0e13L),
330+
static_cast<T>(0.995L)),
331+
static_cast<T>(0.0099010703473402885173268397418009652L), 5e-10);
323332
}
324333

0 commit comments

Comments
 (0)