diff --git a/include/boost/math/tools/roots.hpp b/include/boost/math/tools/roots.hpp index 6493e81228..5e4290703f 100644 --- a/include/boost/math/tools/roots.hpp +++ b/include/boost/math/tools/roots.hpp @@ -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())) + // 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(); + if ((fabs(num) < 1) && (inv_max_value * fabs(denom) >= fabs(num))) { // possible overflow, use Newton step: delta = f0 / f1;