From 9b0a6be371bbd8eb217849f3216e9f76c6ed9cc0 Mon Sep 17 00:00:00 2001 From: Nicholas McKibben Date: Sat, 4 Feb 2023 22:16:41 -0700 Subject: [PATCH] FIX: avoid overflow on overflow check in toms748_solve safe_div --- include/boost/math/tools/toms748_solve.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/math/tools/toms748_solve.hpp b/include/boost/math/tools/toms748_solve.hpp index 2de491a951..15599e8297 100644 --- a/include/boost/math/tools/toms748_solve.hpp +++ b/include/boost/math/tools/toms748_solve.hpp @@ -160,7 +160,8 @@ inline T safe_div(T num, T denom, T r) if(fabs(denom) < 1) { - if(fabs(denom * tools::max_value()) <= fabs(num)) + static const T inv_max_value = 1.0 / tools::max_value(); + if(fabs(denom) <= inv_max_value * fabs(num)) return r; } return num / denom;