From 9a5c5163e11a5d013098a7cc635a5198bd8d5fe7 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Thu, 26 May 2011 01:59:51 +0200 Subject: [PATCH] Fixed Visual Studio float math bug in debug --- base/base_tests/math_test.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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()