From d02e524326c06cb33ac7fef3130d423f30771d4f Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Thu, 15 Sep 2016 17:45:33 -0700 Subject: [PATCH] Fix math-test false positive Depending on the accuracy of the floating point division, the input of the test function could be 1ulp too large or too small. If it was too large the result of the test function wasn't within 4ulp and the test failed. Change-Id: Ia322b136d1db9b25c7c733e4067f927a4c77e372 --- src/gromacs/math/tests/functions.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gromacs/math/tests/functions.cpp b/src/gromacs/math/tests/functions.cpp index cbd80479e5..488a9bc80f 100644 --- a/src/gromacs/math/tests/functions.cpp +++ b/src/gromacs/math/tests/functions.cpp @@ -310,7 +310,7 @@ TEST(FunctionTest, ErfInvFloat) for (int i = 0; i < npoints; i++) { - float r = -1.0 + 2.0 * (float(i) + 0.5) / npoints; + float r = float(2*i - npoints + 1) / npoints; result.push_back(gmx::erfinv(r)); } @@ -326,7 +326,7 @@ TEST(FunctionTest, ErfInvDouble) for (int i = 0; i < npoints; i++) { - double r = -1.0 + 2.0 * (double(i) + 0.5) / npoints; + double r = double(2*i - npoints + 1) / npoints; result.push_back(gmx::erfinv(r)); } @@ -339,7 +339,7 @@ TEST(FunctionTest, ErfAndErfInvAreInversesFloat) for (int i = 0; i < npoints; i++) { - float r = -1.0 + 2.0 * (float(i) + 0.5) / npoints; + float r = float(2*i - npoints + 1) / npoints; EXPECT_FLOAT_EQ_TOL(r, std::erf(gmx::erfinv(r)), gmx::test::ulpTolerance(10)); } } @@ -350,7 +350,7 @@ TEST(FunctionTest, ErfAndErfInvAreInversesDouble) for (int i = 0; i < npoints; i++) { - double r = -1.0 + 2.0 * (double(i) + 0.5) / npoints; + double r = double(2*i - npoints + 1) / npoints; EXPECT_DOUBLE_EQ_TOL(r, std::erf(gmx::erfinv(r)), gmx::test::ulpTolerance(10)); } } -- 2.11.4.GIT