[libc-commits] [PATCH] D90262: [libc][NFC] Use a convenience macro to declare special floating point constants.
Siva Chandra via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Oct 27 13:13:54 PDT 2020
sivachandra created this revision.
sivachandra added a reviewer: lntue.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added a project: libc-project.
sivachandra requested review of this revision.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D90262
Files:
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
Index: libc/utils/FPUtil/TestHelpers.h
===================================================================
--- libc/utils/FPUtil/TestHelpers.h
+++ libc/utils/FPUtil/TestHelpers.h
@@ -65,6 +65,13 @@
} // 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, \
Index: libc/test/src/math/remquol_test.cpp
===================================================================
--- libc/test/src/math/remquol_test.cpp
+++ libc/test/src/math/remquol_test.cpp
@@ -19,13 +19,9 @@
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 @@
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, NormalRange) {
+TEST(RemquolTest, NormalRange) {
constexpr UIntType count = 1000001;
constexpr UIntType step = (FPBits::maxNormal - FPBits::minNormal) / count;
for (UIntType v = FPBits::minNormal, w = FPBits::maxNormal;
Index: libc/test/src/math/remquof_test.cpp
===================================================================
--- libc/test/src/math/remquof_test.cpp
+++ libc/test/src/math/remquof_test.cpp
@@ -19,11 +19,7 @@
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;
Index: libc/test/src/math/remquo_test.cpp
===================================================================
--- libc/test/src/math/remquo_test.cpp
+++ libc/test/src/math/remquo_test.cpp
@@ -19,11 +19,7 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90262.301090.patch
Type: text/x-patch
Size: 3374 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20201027/25168a70/attachment.bin>
More information about the libc-commits
mailing list