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

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D90262
This commit is contained in:
Siva Chandra Reddy 2020-10-27 13:12:18 -07:00
parent d69ada30e2
commit e4be4bcf83
4 changed files with 13 additions and 18 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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, \