Skip to content
Closed
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
7 changes: 6 additions & 1 deletion include/boost/math/tools/roots.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,12 @@ namespace detail {
BOOST_MATH_INSTRUMENT_VARIABLE(denom);
BOOST_MATH_INSTRUMENT_VARIABLE(num);

if ((fabs(num) < 1) && (fabs(denom) >= fabs(num) * tools::max_value<T>()))
// denom/num overflows if:
// |denom| >= |num| * max_value
// RHS may overflow on Apple M1, so rearrange:
// |denom| * 1/max_value >= |num|
static const T inv_max_value = 1.0 / tools::max_value<T>();
if ((fabs(num) < 1) && (inv_max_value * fabs(denom) >= fabs(num)))
{
// possible overflow, use Newton step:
delta = f0 / f1;
Expand Down