[libc-commits] [libc] ed8982d - [libc][NFC] Switch math tests to the new ULP based tolerance.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Thu Aug 20 08:31:53 PDT 2020


Author: Siva Chandra Reddy
Date: 2020-08-20T08:31:31-07:00
New Revision: ed8982da3e3122ffe2de8801d6ca1e1bd1e3c10a

URL: https://github.com/llvm/llvm-project/commit/ed8982da3e3122ffe2de8801d6ca1e1bd1e3c10a
DIFF: https://github.com/llvm/llvm-project/commit/ed8982da3e3122ffe2de8801d6ca1e1bd1e3c10a.diff

LOG: [libc][NFC] Switch math tests to the new ULP based tolerance.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D86267

Added: 
    

Modified: 
    libc/test/src/math/ceil_test.cpp
    libc/test/src/math/ceilf_test.cpp
    libc/test/src/math/ceill_test.cpp
    libc/test/src/math/cosf_test.cpp
    libc/test/src/math/exp2f_test.cpp
    libc/test/src/math/expf_test.cpp
    libc/test/src/math/fabs_test.cpp
    libc/test/src/math/fabsf_test.cpp
    libc/test/src/math/fabsl_test.cpp
    libc/test/src/math/floor_test.cpp
    libc/test/src/math/floorf_test.cpp
    libc/test/src/math/floorl_test.cpp
    libc/test/src/math/round_test.cpp
    libc/test/src/math/roundf_test.cpp
    libc/test/src/math/roundl_test.cpp
    libc/test/src/math/sincosf_test.cpp
    libc/test/src/math/sinf_test.cpp
    libc/test/src/math/trunc_test.cpp
    libc/test/src/math/truncf_test.cpp
    libc/test/src/math/truncl_test.cpp
    libc/utils/MPFRWrapper/MPFRUtils.cpp
    libc/utils/MPFRWrapper/MPFRUtils.h

Removed: 
    


################################################################################
diff  --git a/libc/test/src/math/ceil_test.cpp b/libc/test/src/math/ceil_test.cpp
index e012655638ab..bed06d8c53bb 100644
--- a/libc/test/src/math/ceil_test.cpp
+++ b/libc/test/src/math/ceil_test.cpp
@@ -23,9 +23,6 @@ static const double nan = FPBits::buildNaN(1);
 static const double inf = FPBits::inf();
 static const double negInf = FPBits::negInf();
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
 TEST(CeilTest, SpecialNumbers) {
   EXPECT_FP_EQ(zero, __llvm_libc::ceil(zero));
   EXPECT_FP_EQ(negZero, __llvm_libc::ceil(negZero));
@@ -78,7 +75,6 @@ TEST(CeilTest, InDoubleRange) {
     if (isnan(x) || isinf(x))
       continue;
 
-    ASSERT_MPFR_MATCH(mpfr::Operation::Ceil, x, __llvm_libc::ceil(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Ceil, x, __llvm_libc::ceil(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/ceilf_test.cpp b/libc/test/src/math/ceilf_test.cpp
index 2ad3770fcb9a..4efc07ddd736 100644
--- a/libc/test/src/math/ceilf_test.cpp
+++ b/libc/test/src/math/ceilf_test.cpp
@@ -23,9 +23,6 @@ static const float nan = FPBits::buildNaN(1);
 static const float inf = FPBits::inf();
 static const float negInf = FPBits::negInf();
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
 TEST(CeilfTest, SpecialNumbers) {
   EXPECT_FP_EQ(zero, __llvm_libc::ceilf(zero));
   EXPECT_FP_EQ(negZero, __llvm_libc::ceilf(negZero));
@@ -78,7 +75,6 @@ TEST(CeilfTest, InFloatRange) {
     if (isnan(x) || isinf(x))
       continue;
 
-    ASSERT_MPFR_MATCH(mpfr::Operation::Ceil, x, __llvm_libc::ceilf(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Ceil, x, __llvm_libc::ceilf(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/ceill_test.cpp b/libc/test/src/math/ceill_test.cpp
index c1a385fff6ac..f6cb1819d9f4 100644
--- a/libc/test/src/math/ceill_test.cpp
+++ b/libc/test/src/math/ceill_test.cpp
@@ -23,9 +23,6 @@ static const long double nan = FPBits::buildNaN(1);
 static const long double inf = FPBits::inf();
 static const long double negInf = FPBits::negInf();
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
 TEST(CeillTest, SpecialNumbers) {
   EXPECT_FP_EQ(zero, __llvm_libc::ceill(zero));
   EXPECT_FP_EQ(negZero, __llvm_libc::ceill(negZero));
@@ -78,7 +75,6 @@ TEST(CeillTest, InLongDoubleRange) {
     if (isnan(x) || isinf(x))
       continue;
 
-    ASSERT_MPFR_MATCH(mpfr::Operation::Ceil, x, __llvm_libc::ceill(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Ceil, x, __llvm_libc::ceill(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/cosf_test.cpp b/libc/test/src/math/cosf_test.cpp
index ac6020e1a8f6..a8c5213676c1 100644
--- a/libc/test/src/math/cosf_test.cpp
+++ b/libc/test/src/math/cosf_test.cpp
@@ -32,11 +32,6 @@ using __llvm_libc::testing::sdcomp26094Values;
 
 namespace mpfr = __llvm_libc::testing::mpfr;
 
-// 12 additional bits of precision over the base precision of a |float|
-// value.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 12,
-                                           3 * 0x1000 / 4};
-
 TEST(CosfTest, SpecialNumbers) {
   llvmlibc_errno = 0;
 
@@ -81,7 +76,7 @@ TEST(CosfTest, InFloatRange) {
     float x = valueFromBits(v);
     if (isnan(x) || isinf(x))
       continue;
-    ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, __llvm_libc::cosf(x), tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, __llvm_libc::cosf(x), 1.0);
   }
 }
 
@@ -89,12 +84,12 @@ TEST(CosfTest, InFloatRange) {
 TEST(CosfTest, SmallValues) {
   float x = valueFromBits(0x17800000U);
   float result = __llvm_libc::cosf(x);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result, 1.0);
   EXPECT_EQ(BitPatterns::one, valueAsBits(result));
 
   x = valueFromBits(0x0040000U);
   result = __llvm_libc::cosf(x);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result, 1.0);
   EXPECT_EQ(BitPatterns::one, valueAsBits(result));
 }
 
@@ -103,6 +98,6 @@ TEST(CosfTest, SmallValues) {
 TEST(CosfTest, SDCOMP_26094) {
   for (uint32_t v : sdcomp26094Values) {
     float x = valueFromBits(v);
-    ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, __llvm_libc::cosf(x), tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, __llvm_libc::cosf(x), 1.0);
   }
 }

diff  --git a/libc/test/src/math/exp2f_test.cpp b/libc/test/src/math/exp2f_test.cpp
index fe9955f4cde4..1204de4770a0 100644
--- a/libc/test/src/math/exp2f_test.cpp
+++ b/libc/test/src/math/exp2f_test.cpp
@@ -28,11 +28,6 @@ using BitPatterns = __llvm_libc::fputil::BitPatterns<float>;
 
 namespace mpfr = __llvm_libc::testing::mpfr;
 
-// 12 additional bits of precision over the base precision of a |float|
-// value.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 12,
-                                           0xFFF};
-
 TEST(exp2fTest, SpecialNumbers) {
   llvmlibc_errno = 0;
 
@@ -93,27 +88,27 @@ TEST(ExpfTest, Borderline) {
 
   llvmlibc_errno = 0;
   x = valueFromBits(0x42fa0001U);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0x42ffffffU);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0xc2fa0001U);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0xc2fc0000U);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0xc2fc0001U);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0xc3150000U);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
   EXPECT_EQ(llvmlibc_errno, 0);
 }
 
@@ -125,12 +120,12 @@ TEST(ExpfTest, Underflow) {
 
   llvmlibc_errno = 0;
   float x = valueFromBits(0xc3158000U);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
   EXPECT_EQ(llvmlibc_errno, ERANGE);
 
   llvmlibc_errno = 0;
   x = valueFromBits(0xc3165432U);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
   EXPECT_EQ(llvmlibc_errno, ERANGE);
 }
 
@@ -150,7 +145,6 @@ TEST(exp2fTest, InFloatRange) {
     // wider precision.
     if (isnan(result) || isinf(result) || llvmlibc_errno != 0)
       continue;
-    ASSERT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
   }
 }

diff  --git a/libc/test/src/math/expf_test.cpp b/libc/test/src/math/expf_test.cpp
index 577f5e40d82b..e7951a308278 100644
--- a/libc/test/src/math/expf_test.cpp
+++ b/libc/test/src/math/expf_test.cpp
@@ -28,11 +28,6 @@ using BitPatterns = __llvm_libc::fputil::BitPatterns<float>;
 
 namespace mpfr = __llvm_libc::testing::mpfr;
 
-// 12 additional bits of precision over the base precision of a |float|
-// value.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 12,
-                                           0xFFF};
-
 TEST(ExpfTest, SpecialNumbers) {
   llvmlibc_errno = 0;
 
@@ -110,19 +105,19 @@ TEST(ExpfTest, Borderline) {
 
   llvmlibc_errno = 0;
   x = valueFromBits(0x42affff8U);
-  ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), tolerance);
+  ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0x42b00008U);
-  ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), tolerance);
+  ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0xc2affff8U);
-  ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), tolerance);
+  ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0xc2b00008U);
-  ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), tolerance);
+  ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
   EXPECT_EQ(llvmlibc_errno, 0);
 }
 
@@ -142,6 +137,6 @@ TEST(ExpfTest, InFloatRange) {
     // wider precision.
     if (isnan(result) || isinf(result) || llvmlibc_errno != 0)
       continue;
-    ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
   }
 }

diff  --git a/libc/test/src/math/fabs_test.cpp b/libc/test/src/math/fabs_test.cpp
index 4c3f28f06d30..277ed604d7e8 100644
--- a/libc/test/src/math/fabs_test.cpp
+++ b/libc/test/src/math/fabs_test.cpp
@@ -23,10 +23,6 @@ static const double negInf = FPBits::negInf();
 
 namespace mpfr = __llvm_libc::testing::mpfr;
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::doublePrecision, 0,
-                                           0};
-
 TEST(FabsTest, SpecialNumbers) {
   EXPECT_FP_EQ(nan, __llvm_libc::fabs(nan));
 
@@ -45,6 +41,6 @@ TEST(FabsTest, InDoubleRange) {
     double x = FPBits(v);
     if (isnan(x) || isinf(x))
       continue;
-    ASSERT_MPFR_MATCH(mpfr::Operation::Abs, x, __llvm_libc::fabs(x), tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Abs, x, __llvm_libc::fabs(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/fabsf_test.cpp b/libc/test/src/math/fabsf_test.cpp
index 83425d7d2f8f..2a735510acce 100644
--- a/libc/test/src/math/fabsf_test.cpp
+++ b/libc/test/src/math/fabsf_test.cpp
@@ -23,10 +23,6 @@ static const float negInf = FPBits::negInf();
 
 namespace mpfr = __llvm_libc::testing::mpfr;
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
-
 TEST(FabsfTest, SpecialNumbers) {
   EXPECT_FP_EQ(nan, __llvm_libc::fabsf(nan));
 
@@ -45,7 +41,6 @@ TEST(FabsfTest, InFloatRange) {
     float x = FPBits(v);
     if (isnan(x) || isinf(x))
       continue;
-    ASSERT_MPFR_MATCH(mpfr::Operation::Abs, x, __llvm_libc::fabsf(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Abs, x, __llvm_libc::fabsf(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/fabsl_test.cpp b/libc/test/src/math/fabsl_test.cpp
index b2ceb0c6205c..86f1275d4dfe 100644
--- a/libc/test/src/math/fabsl_test.cpp
+++ b/libc/test/src/math/fabsl_test.cpp
@@ -23,10 +23,6 @@ static const long double negInf = FPBits::negInf();
 
 namespace mpfr = __llvm_libc::testing::mpfr;
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
-
 TEST(FabslTest, SpecialNumbers) {
   EXPECT_FP_EQ(nan, __llvm_libc::fabsl(nan));
 
@@ -45,7 +41,6 @@ TEST(FabslTest, InLongDoubleRange) {
     long double x = FPBits(v);
     if (isnan(x) || isinf(x))
       continue;
-    ASSERT_MPFR_MATCH(mpfr::Operation::Abs, x, __llvm_libc::fabsl(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Abs, x, __llvm_libc::fabsl(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/floor_test.cpp b/libc/test/src/math/floor_test.cpp
index 34b9bec11858..5f59c3c14c96 100644
--- a/libc/test/src/math/floor_test.cpp
+++ b/libc/test/src/math/floor_test.cpp
@@ -23,9 +23,6 @@ static const double nan = FPBits::buildNaN(1);
 static const double inf = FPBits::inf();
 static const double negInf = FPBits::negInf();
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
 TEST(FloorTest, SpecialNumbers) {
   EXPECT_FP_EQ(zero, __llvm_libc::floor(zero));
   EXPECT_FP_EQ(negZero, __llvm_libc::floor(negZero));
@@ -78,7 +75,6 @@ TEST(FloorTest, InDoubleRange) {
     if (isnan(x) || isinf(x))
       continue;
 
-    ASSERT_MPFR_MATCH(mpfr::Operation::Floor, x, __llvm_libc::floor(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Floor, x, __llvm_libc::floor(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/floorf_test.cpp b/libc/test/src/math/floorf_test.cpp
index 0eb6b1f3bda3..08c34638d125 100644
--- a/libc/test/src/math/floorf_test.cpp
+++ b/libc/test/src/math/floorf_test.cpp
@@ -23,9 +23,6 @@ static const float nan = FPBits::buildNaN(1);
 static const float inf = FPBits::inf();
 static const float negInf = FPBits::negInf();
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
 TEST(FloorfTest, SpecialNumbers) {
   EXPECT_FP_EQ(zero, __llvm_libc::floorf(zero));
   EXPECT_FP_EQ(negZero, __llvm_libc::floorf(negZero));
@@ -78,7 +75,6 @@ TEST(FloorfTest, InFloatRange) {
     if (isnan(x) || isinf(x))
       continue;
 
-    ASSERT_MPFR_MATCH(mpfr::Operation::Floor, x, __llvm_libc::floorf(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Floor, x, __llvm_libc::floorf(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/floorl_test.cpp b/libc/test/src/math/floorl_test.cpp
index 3ed2435f3f48..c6aea659635c 100644
--- a/libc/test/src/math/floorl_test.cpp
+++ b/libc/test/src/math/floorl_test.cpp
@@ -23,9 +23,6 @@ static const long double nan = FPBits::buildNaN(1);
 static const long double inf = FPBits::inf();
 static const long double negInf = FPBits::negInf();
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
 TEST(FloorlTest, SpecialNumbers) {
   EXPECT_FP_EQ(zero, __llvm_libc::floorl(zero));
   EXPECT_FP_EQ(negZero, __llvm_libc::floorl(negZero));
@@ -78,7 +75,6 @@ TEST(FloorlTest, InLongDoubleRange) {
     if (isnan(x) || isinf(x))
       continue;
 
-    ASSERT_MPFR_MATCH(mpfr::Operation::Floor, x, __llvm_libc::floorl(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Floor, x, __llvm_libc::floorl(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/round_test.cpp b/libc/test/src/math/round_test.cpp
index 0cfaead1dc3b..0ff1fde3c2f3 100644
--- a/libc/test/src/math/round_test.cpp
+++ b/libc/test/src/math/round_test.cpp
@@ -23,9 +23,6 @@ static const double nan = FPBits::buildNaN(1);
 static const double inf = FPBits::inf();
 static const double negInf = FPBits::negInf();
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
 TEST(RoundTest, SpecialNumbers) {
   EXPECT_FP_EQ(zero, __llvm_libc::round(zero));
   EXPECT_FP_EQ(negZero, __llvm_libc::round(negZero));
@@ -78,7 +75,6 @@ TEST(RoundTest, InDoubleRange) {
     if (isnan(x) || isinf(x))
       continue;
 
-    ASSERT_MPFR_MATCH(mpfr::Operation::Round, x, __llvm_libc::round(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Round, x, __llvm_libc::round(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/roundf_test.cpp b/libc/test/src/math/roundf_test.cpp
index 6771b3fd2288..6ddd122d7e6f 100644
--- a/libc/test/src/math/roundf_test.cpp
+++ b/libc/test/src/math/roundf_test.cpp
@@ -23,9 +23,6 @@ static const float nan = FPBits::buildNaN(1);
 static const float inf = FPBits::inf();
 static const float negInf = FPBits::negInf();
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
 TEST(RoundfTest, SpecialNumbers) {
   EXPECT_FP_EQ(zero, __llvm_libc::roundf(zero));
   EXPECT_FP_EQ(negZero, __llvm_libc::roundf(negZero));
@@ -78,7 +75,6 @@ TEST(RoundfTest, InFloatRange) {
     if (isnan(x) || isinf(x))
       continue;
 
-    ASSERT_MPFR_MATCH(mpfr::Operation::Round, x, __llvm_libc::roundf(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Round, x, __llvm_libc::roundf(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/roundl_test.cpp b/libc/test/src/math/roundl_test.cpp
index ff5d799319f4..e032f5145af4 100644
--- a/libc/test/src/math/roundl_test.cpp
+++ b/libc/test/src/math/roundl_test.cpp
@@ -23,9 +23,6 @@ static const long double nan = FPBits::buildNaN(1);
 static const long double inf = FPBits::inf();
 static const long double negInf = FPBits::negInf();
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
 TEST(RoundlTest, SpecialNumbers) {
   EXPECT_FP_EQ(zero, __llvm_libc::roundl(zero));
   EXPECT_FP_EQ(negZero, __llvm_libc::roundl(negZero));
@@ -78,7 +75,6 @@ TEST(RoundlTest, InLongDoubleRange) {
     if (isnan(x) || isinf(x))
       continue;
 
-    ASSERT_MPFR_MATCH(mpfr::Operation::Round, x, __llvm_libc::roundl(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Round, x, __llvm_libc::roundl(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/sincosf_test.cpp b/libc/test/src/math/sincosf_test.cpp
index 2211ef1dc6e2..9e5ee062cc8d 100644
--- a/libc/test/src/math/sincosf_test.cpp
+++ b/libc/test/src/math/sincosf_test.cpp
@@ -32,11 +32,6 @@ using __llvm_libc::testing::sdcomp26094Values;
 
 namespace mpfr = __llvm_libc::testing::mpfr;
 
-// 12 additional bits of precision over the base precision of a |float|
-// value.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 12,
-                                           3 * 0x1000 / 4};
-
 TEST(SinCosfTest, SpecialNumbers) {
   llvmlibc_errno = 0;
   float sin, cos;
@@ -96,8 +91,8 @@ TEST(SinCosfTest, InFloatRange) {
 
     float sin, cos;
     __llvm_libc::sincosf(x, &sin, &cos);
-    ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, cos, tolerance);
-    ASSERT_MPFR_MATCH(mpfr::Operation::Sin, x, sin, tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, cos, 1.0);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Sin, x, sin, 1.0);
   }
 }
 
@@ -107,16 +102,16 @@ TEST(SinCosfTest, SmallValues) {
   float x = valueFromBits(bits);
   float result_cos, result_sin;
   __llvm_libc::sincosf(x, &result_sin, &result_cos);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result_cos, tolerance);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result_sin, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result_cos, 1.0);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result_sin, 1.0);
   EXPECT_EQ(BitPatterns::one, valueAsBits(result_cos));
   EXPECT_EQ(bits, valueAsBits(result_sin));
 
   bits = 0x00400000;
   x = valueFromBits(bits);
   __llvm_libc::sincosf(x, &result_sin, &result_cos);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result_cos, tolerance);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result_sin, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result_cos, 1.0);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result_sin, 1.0);
   EXPECT_EQ(BitPatterns::one, valueAsBits(result_cos));
   EXPECT_EQ(bits, valueAsBits(result_sin));
 }
@@ -128,7 +123,7 @@ TEST(SinCosfTest, SDCOMP_26094) {
     float x = valueFromBits(v);
     float sin, cos;
     __llvm_libc::sincosf(x, &sin, &cos);
-    EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, cos, tolerance);
-    EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, sin, tolerance);
+    EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, cos, 1.0);
+    EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, sin, 1.0);
   }
 }

diff  --git a/libc/test/src/math/sinf_test.cpp b/libc/test/src/math/sinf_test.cpp
index 17c66712fd02..67dca0072deb 100644
--- a/libc/test/src/math/sinf_test.cpp
+++ b/libc/test/src/math/sinf_test.cpp
@@ -32,11 +32,6 @@ using __llvm_libc::testing::sdcomp26094Values;
 
 namespace mpfr = __llvm_libc::testing::mpfr;
 
-// 12 additional bits of precision over the base precision of a |float|
-// value.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 12,
-                                           3 * 0x1000 / 4};
-
 TEST(SinfTest, SpecialNumbers) {
   llvmlibc_errno = 0;
 
@@ -81,13 +76,13 @@ TEST(SinfTest, InFloatRange) {
     float x = valueFromBits(v);
     if (isnan(x) || isinf(x))
       continue;
-    ASSERT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x), tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x), 1.0);
   }
 }
 
 TEST(SinfTest, SpecificBitPatterns) {
   float x = valueFromBits(0xc70d39a1);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x), 1.0);
 }
 
 // For small values, sin(x) is x.
@@ -95,13 +90,13 @@ TEST(SinfTest, SmallValues) {
   uint32_t bits = 0x17800000;
   float x = valueFromBits(bits);
   float result = __llvm_libc::sinf(x);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result, 1.0);
   EXPECT_EQ(bits, valueAsBits(result));
 
   bits = 0x00400000;
   x = valueFromBits(bits);
   result = __llvm_libc::sinf(x);
-  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result, 1.0);
   EXPECT_EQ(bits, valueAsBits(result));
 }
 
@@ -110,6 +105,6 @@ TEST(SinfTest, SmallValues) {
 TEST(SinfTest, SDCOMP_26094) {
   for (uint32_t v : sdcomp26094Values) {
     float x = valueFromBits(v);
-    EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x), tolerance);
+    EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x), 1.0);
   }
 }

diff  --git a/libc/test/src/math/trunc_test.cpp b/libc/test/src/math/trunc_test.cpp
index 855492ab4cb8..806f02cb2a22 100644
--- a/libc/test/src/math/trunc_test.cpp
+++ b/libc/test/src/math/trunc_test.cpp
@@ -23,9 +23,6 @@ static const double nan = FPBits::buildNaN(1);
 static const double inf = FPBits::inf();
 static const double negInf = FPBits::negInf();
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
 TEST(TruncTest, SpecialNumbers) {
   EXPECT_FP_EQ(zero, __llvm_libc::trunc(zero));
   EXPECT_FP_EQ(negZero, __llvm_libc::trunc(negZero));
@@ -78,7 +75,6 @@ TEST(TruncTest, InDoubleRange) {
     if (isnan(x) || isinf(x))
       continue;
 
-    ASSERT_MPFR_MATCH(mpfr::Operation::Trunc, x, __llvm_libc::trunc(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Trunc, x, __llvm_libc::trunc(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/truncf_test.cpp b/libc/test/src/math/truncf_test.cpp
index a87cb14b1503..99cb487c4a29 100644
--- a/libc/test/src/math/truncf_test.cpp
+++ b/libc/test/src/math/truncf_test.cpp
@@ -23,9 +23,6 @@ static const float nan = FPBits::buildNaN(1);
 static const float inf = FPBits::inf();
 static const float negInf = FPBits::negInf();
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
 TEST(TruncfTest, SpecialNumbers) {
   EXPECT_FP_EQ(zero, __llvm_libc::truncf(zero));
   EXPECT_FP_EQ(negZero, __llvm_libc::truncf(negZero));
@@ -78,7 +75,6 @@ TEST(TruncfTest, InFloatRange) {
     if (isnan(x) || isinf(x))
       continue;
 
-    ASSERT_MPFR_MATCH(mpfr::Operation::Trunc, x, __llvm_libc::truncf(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Trunc, x, __llvm_libc::truncf(x), 0.0);
   }
 }

diff  --git a/libc/test/src/math/truncl_test.cpp b/libc/test/src/math/truncl_test.cpp
index 2ea6fe58a63d..8f7668db5275 100644
--- a/libc/test/src/math/truncl_test.cpp
+++ b/libc/test/src/math/truncl_test.cpp
@@ -23,9 +23,6 @@ static const long double nan = FPBits::buildNaN(1);
 static const long double inf = FPBits::inf();
 static const long double negInf = FPBits::negInf();
 
-// Zero tolerance; As in, exact match with MPFR result.
-static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0,
-                                           0};
 TEST(TrunclTest, SpecialNumbers) {
   EXPECT_FP_EQ(zero, __llvm_libc::truncl(zero));
   EXPECT_FP_EQ(negZero, __llvm_libc::truncl(negZero));
@@ -78,7 +75,6 @@ TEST(TrunclTest, InLongDoubleRange) {
     if (isnan(x) || isinf(x))
       continue;
 
-    ASSERT_MPFR_MATCH(mpfr::Operation::Trunc, x, __llvm_libc::truncl(x),
-                      tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Trunc, x, __llvm_libc::truncl(x), 0.0);
   }
 }

diff  --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index c97e89ce9b2b..a3abfce08bf3 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -65,31 +65,6 @@ class MPFRNumber {
     mpfr_set_sj(value, x, MPFR_RNDN);
   }
 
-  template <typename XType> MPFRNumber(XType x, const Tolerance &t) {
-    mpfr_init2(value, mpfrPrecision);
-    mpfr_set_zero(value, 1); // Set to positive zero.
-    MPFRNumber xExponent(fputil::FPBits<XType>(x).getExponent());
-    // E = 2^E
-    mpfr_exp2(xExponent.value, xExponent.value, MPFR_RNDN);
-    uint32_t bitMask = 1 << (t.width - 1);
-    for (int n = -t.basePrecision; bitMask > 0; bitMask >>= 1) {
-      --n;
-      if (t.bits & bitMask) {
-        // delta = -n
-        MPFRNumber delta(n);
-
-        // delta = 2^(-n)
-        mpfr_exp2(delta.value, delta.value, MPFR_RNDN);
-
-        // delta = E * 2^(-n)
-        mpfr_mul(delta.value, delta.value, xExponent.value, MPFR_RNDN);
-
-        // tolerance += delta
-        mpfr_add(value, value, delta.value, MPFR_RNDN);
-      }
-    }
-  }
-
   template <typename XType,
             cpp::EnableIfType<cpp::IsFloatingPointType<XType>::Value, int> = 0>
   MPFRNumber(Operation op, XType rawValue) {
@@ -135,18 +110,6 @@ class MPFRNumber {
 
   ~MPFRNumber() { mpfr_clear(value); }
 
-  // Returns true if |other| is within the |tolerance| value of this
-  // number.
-  bool isEqual(const MPFRNumber &other, const MPFRNumber &tolerance) const {
-    MPFRNumber 
diff erence;
-    if (mpfr_cmp(value, other.value) >= 0)
-      mpfr_sub(
diff erence.value, value, other.value, MPFR_RNDN);
-    else
-      mpfr_sub(
diff erence.value, other.value, value, MPFR_RNDN);
-
-    return mpfr_lessequal_p(
diff erence.value, tolerance.value);
-  }
-
   std::string str() const {
     // 200 bytes should be more than sufficient to hold a 100-digit number
     // plus additional bytes for the decimal point, '-' sign etc.
@@ -234,13 +197,8 @@ void MPFRMatcher<T>::explainError(testutils::StreamWrapper &OS) {
   __llvm_libc::fputil::testing::describeValue(
       "   MPFR rounded: ", mpfrResult.as<T>(), OS);
   OS << '\n';
-  if (useULP) {
-    OS << "      ULP error: " << std::to_string(mpfrResult.ulp(matchValue))
-       << '\n';
-  } else {
-    MPFRNumber mpfrToleranceValue = MPFRNumber(matchValue, tolerance);
-    OS << "Tolerance value: " << mpfrToleranceValue.str() << '\n';
-  }
+  OS << "      ULP error: " << std::to_string(mpfrResult.ulp(matchValue))
+     << '\n';
 }
 
 template void MPFRMatcher<float>::explainError(testutils::StreamWrapper &);
@@ -248,20 +206,6 @@ template void MPFRMatcher<double>::explainError(testutils::StreamWrapper &);
 template void
 MPFRMatcher<long double>::explainError(testutils::StreamWrapper &);
 
-template <typename T>
-bool compare(Operation op, T input, T libcResult, const Tolerance &t) {
-  MPFRNumber mpfrResult(op, input);
-  MPFRNumber mpfrLibcResult(libcResult);
-  MPFRNumber mpfrToleranceValue(libcResult, t);
-
-  return mpfrResult.isEqual(mpfrLibcResult, mpfrToleranceValue);
-};
-
-template bool compare<float>(Operation, float, float, const Tolerance &);
-template bool compare<double>(Operation, double, double, const Tolerance &);
-template bool compare<long double>(Operation, long double, long double,
-                                   const Tolerance &);
-
 template <typename T>
 bool compare(Operation op, T input, T libcResult, double ulpError) {
   // If the ulp error is exactly 0.5 (i.e a tie), we would check that the result

diff  --git a/libc/utils/MPFRWrapper/MPFRUtils.h b/libc/utils/MPFRWrapper/MPFRUtils.h
index 633c67ff8570..3d94079e65d8 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.h
+++ b/libc/utils/MPFRWrapper/MPFRUtils.h
@@ -18,27 +18,6 @@ namespace __llvm_libc {
 namespace testing {
 namespace mpfr {
 
-struct Tolerance {
-  // Number of bits used to represent the fractional
-  // part of a value of type 'float'.
-  static constexpr unsigned int floatPrecision = 23;
-
-  // Number of bits used to represent the fractional
-  // part of a value of type 'double'.
-  static constexpr unsigned int doublePrecision = 52;
-
-  // The base precision of the number. For example, for values of
-  // type float, the base precision is the value |floatPrecision|.
-  unsigned int basePrecision;
-
-  unsigned int width; // Number of valid LSB bits in |value|.
-
-  // The bits in the tolerance value. The tolerance value will be
-  // sum(bits[width - i] * 2 ^ (- basePrecision - i)) for |i| in
-  // range [1, width].
-  uint32_t bits;
-};
-
 enum class Operation : int {
   Abs,
   Ceil,
@@ -54,9 +33,6 @@ enum class Operation : int {
 
 namespace internal {
 
-template <typename T>
-bool compare(Operation op, T input, T libcOutput, const Tolerance &t);
-
 template <typename T>
 bool compare(Operation op, T input, T libcOutput, double t);
 
@@ -66,23 +42,16 @@ template <typename T> class MPFRMatcher : public testing::Matcher<T> {
 
   Operation operation;
   T input;
-  Tolerance tolerance;
   T matchValue;
   double ulpTolerance;
-  bool useULP;
 
 public:
-  MPFRMatcher(Operation op, T testInput, Tolerance &t)
-      : operation(op), input(testInput), tolerance(t), useULP(false) {}
   MPFRMatcher(Operation op, T testInput, double ulpTolerance)
-      : operation(op), input(testInput), ulpTolerance(ulpTolerance),
-        useULP(true) {}
+      : operation(op), input(testInput), ulpTolerance(ulpTolerance) {}
 
   bool match(T libcResult) {
     matchValue = libcResult;
-    return (useULP
-                ? internal::compare(operation, input, libcResult, ulpTolerance)
-                : internal::compare(operation, input, libcResult, tolerance));
+    return internal::compare(operation, input, libcResult, ulpTolerance);
   }
 
   void explainError(testutils::StreamWrapper &OS) override;
@@ -92,9 +61,7 @@ template <typename T> class MPFRMatcher : public testing::Matcher<T> {
 
 template <typename T, typename U>
 __attribute__((no_sanitize("address")))
-typename cpp::EnableIfType<cpp::IsSameV<U, Tolerance> ||
-                               cpp::IsSameV<U, double>,
-                           internal::MPFRMatcher<T>>
+typename cpp::EnableIfType<cpp::IsSameV<U, double>, internal::MPFRMatcher<T>>
 getMPFRMatcher(Operation op, T input, U t) {
   static_assert(
       __llvm_libc::cpp::IsFloatingPointType<T>::Value,


        


More information about the libc-commits mailing list