diff --git a/base/base_tests/math_test.cpp b/base/base_tests/math_test.cpp index 448fdeca58..36ec8c57af 100644 --- a/base/base_tests/math_test.cpp +++ b/base/base_tests/math_test.cpp @@ -66,12 +66,17 @@ namespace { // Returns the next representable floating point value without using conversion to integer. -template FloatT NextFloat(FloatT x, int dir = 1) +template FloatT NextFloat(FloatT const x, int dir = 1) { - FloatT d = numeric_limits::denorm_min(); - while (x + dir * d == x) + FloatT d = dir * numeric_limits::denorm_min(); + while (true) + { + FloatT y = x; + y += d; + if (x != y) + return y; d *= 2; - return x + dir * d; + } } template void TestMaxULPs()