[libc-commits] [libc] e4be4bc - [libc][NFC] Use a convenience macro to declare special floating point constants.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Tue Oct 27 16:55:44 PDT 2020


Author: Siva Chandra Reddy
Date: 2020-10-27T16:55:16-07:00
New Revision: e4be4bcf83d9ed4888e42940deb6b6c8dceefa46

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

LOG: [libc][NFC] Use a convenience macro to declare special floating point constants.

Reviewed By: lntue

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

Added: 
    

Modified: 
    libc/test/src/math/remquo_test.cpp
    libc/test/src/math/remquof_test.cpp
    libc/test/src/math/remquol_test.cpp
    libc/utils/FPUtil/TestHelpers.h

Removed: 
    


################################################################################
diff  --git a/libc/test/src/math/remquo_test.cpp b/libc/test/src/math/remquo_test.cpp
index 0ebbed7224b2..44812f1c1d53 100644
--- a/libc/test/src/math/remquo_test.cpp
+++ b/libc/test/src/math/remquo_test.cpp
@@ -19,11 +19,7 @@ using UIntType = FPBits::UIntType;
 
 namespace mpfr = __llvm_libc::testing::mpfr;
 
-static const double zero = FPBits::zero();
-static const double negZero = FPBits::negZero();
-static const double nan = FPBits::buildNaN(1);
-static const double inf = FPBits::inf();
-static const double negInf = FPBits::negInf();
+DECLARE_SPECIAL_CONSTANTS(double)
 
 TEST(RemquoTest, SpecialNumbers) {
   int exponent;

diff  --git a/libc/test/src/math/remquof_test.cpp b/libc/test/src/math/remquof_test.cpp
index 0c51d5f5324d..81c262f5320c 100644
--- a/libc/test/src/math/remquof_test.cpp
+++ b/libc/test/src/math/remquof_test.cpp
@@ -19,11 +19,7 @@ using UIntType = FPBits::UIntType;
 
 namespace mpfr = __llvm_libc::testing::mpfr;
 
-static const float zero = FPBits::zero();
-static const float negZero = FPBits::negZero();
-static const float nan = FPBits::buildNaN(1);
-static const float inf = FPBits::inf();
-static const float negInf = FPBits::negInf();
+DECLARE_SPECIAL_CONSTANTS(float)
 
 TEST(RemquofTest, SpecialNumbers) {
   int exponent;

diff  --git a/libc/test/src/math/remquol_test.cpp b/libc/test/src/math/remquol_test.cpp
index eab3a5fb1fa6..63500cb519a3 100644
--- a/libc/test/src/math/remquol_test.cpp
+++ b/libc/test/src/math/remquol_test.cpp
@@ -19,13 +19,9 @@ using UIntType = FPBits::UIntType;
 
 namespace mpfr = __llvm_libc::testing::mpfr;
 
-static const long double zero = FPBits::zero();
-static const long double negZero = FPBits::negZero();
-static const long double nan = FPBits::buildNaN(1);
-static const long double inf = FPBits::inf();
-static const long double negInf = FPBits::negInf();
+DECLARE_SPECIAL_CONSTANTS(long double)
 
-TEST(RemquoTest, SpecialNumbers) {
+TEST(RemquolTest, SpecialNumbers) {
   int exponent;
   long double x, y;
 
@@ -62,7 +58,7 @@ TEST(RemquoTest, SpecialNumbers) {
   EXPECT_FP_EQ(__llvm_libc::remquol(x, y, &exponent), negZero);
 }
 
-TEST(RemquofTest, SubnormalRange) {
+TEST(RemquolTest, SubnormalRange) {
   constexpr UIntType count = 1000001;
   constexpr UIntType step =
       (FPBits::maxSubnormal - FPBits::minSubnormal) / count;
@@ -77,7 +73,7 @@ TEST(RemquofTest, SubnormalRange) {
   }
 }
 
-TEST(RemquofTest, NormalRange) {
+TEST(RemquolTest, NormalRange) {
   constexpr UIntType count = 1000001;
   constexpr UIntType step = (FPBits::maxNormal - FPBits::minNormal) / count;
   for (UIntType v = FPBits::minNormal, w = FPBits::maxNormal;

diff  --git a/libc/utils/FPUtil/TestHelpers.h b/libc/utils/FPUtil/TestHelpers.h
index 941c4d64622b..8addb0c58db5 100644
--- a/libc/utils/FPUtil/TestHelpers.h
+++ b/libc/utils/FPUtil/TestHelpers.h
@@ -65,6 +65,13 @@ FPMatcher<T, C> getMatcher(T expectedValue) {
 } // namespace fputil
 } // namespace __llvm_libc
 
+#define DECLARE_SPECIAL_CONSTANTS(T)                                           \
+  static const T zero = __llvm_libc::fputil::FPBits<T>::zero();                \
+  static const T negZero = __llvm_libc::fputil::FPBits<T>::negZero();          \
+  static const T nan = __llvm_libc::fputil::FPBits<T>::buildNaN(1);            \
+  static const T inf = __llvm_libc::fputil::FPBits<T>::inf();                  \
+  static const T negInf = __llvm_libc::fputil::FPBits<T>::negInf();
+
 #define EXPECT_FP_EQ(expected, actual)                                         \
   EXPECT_THAT(                                                                 \
       actual,                                                                  \


        


More information about the libc-commits mailing list