Skip to content

Commit 9b0a6be

Browse files
committed
FIX: avoid overflow on overflow check in toms748_solve safe_div
1 parent f0933b4 commit 9b0a6be

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

include/boost/math/tools/toms748_solve.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ inline T safe_div(T num, T denom, T r)
160160

161161
if(fabs(denom) < 1)
162162
{
163-
if(fabs(denom * tools::max_value<T>()) <= fabs(num))
163+
static const T inv_max_value = 1.0 / tools::max_value<T>();
164+
if(fabs(denom) <= inv_max_value * fabs(num))
164165
return r;
165166
}
166167
return num / denom;

0 commit comments

Comments
 (0)