[libc-commits] [libc] e7e71e9 - [libc][NFC] Remove few deprecated FPUtil header files and test patterns.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Wed Jun 30 15:10:17 PDT 2021
Author: Siva Chandra Reddy
Date: 2021-06-30T22:09:23Z
New Revision: e7e71e9454ed76c1b3d8140170b5333c28bef1be
URL: https://github.com/llvm/llvm-project/commit/e7e71e9454ed76c1b3d8140170b5333c28bef1be
DIFF: https://github.com/llvm/llvm-project/commit/e7e71e9454ed76c1b3d8140170b5333c28bef1be.diff
LOG: [libc][NFC] Remove few deprecated FPUtil header files and test patterns.
Few tests have been converted to the new test patterns to facilitate
this.
Added:
libc/test/src/math/FrexpTest.h
libc/test/src/math/LogbTest.h
libc/test/src/math/ModfTest.h
Modified:
libc/test/src/math/CMakeLists.txt
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/expm1f_test.cpp
libc/test/src/math/frexp_test.cpp
libc/test/src/math/frexpf_test.cpp
libc/test/src/math/frexpl_test.cpp
libc/test/src/math/logb_test.cpp
libc/test/src/math/logbf_test.cpp
libc/test/src/math/logbl_test.cpp
libc/test/src/math/modf_test.cpp
libc/test/src/math/modff_test.cpp
libc/test/src/math/modfl_test.cpp
libc/test/src/math/sdcomp26094.h
libc/test/src/math/sin_test.cpp
libc/test/src/math/sincosf_test.cpp
libc/test/src/math/sinf_test.cpp
libc/utils/FPUtil/CMakeLists.txt
Removed:
libc/utils/FPUtil/BitPatterns.h
libc/utils/FPUtil/ClassificationFunctions.h
libc/utils/FPUtil/FloatOperations.h
################################################################################
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index be0683932520..44cdb7afe089 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -656,6 +656,8 @@ add_fp_unittest(
libc_math_unittests
SRCS
frexp_test.cpp
+ HDRS
+ FrexpTest.h
DEPENDS
libc.include.math
libc.src.math.frexp
@@ -669,6 +671,8 @@ add_fp_unittest(
libc_math_unittests
SRCS
frexpf_test.cpp
+ HDRS
+ FrexpTest.h
DEPENDS
libc.include.math
libc.src.math.frexpf
@@ -682,6 +686,8 @@ add_fp_unittest(
libc_math_unittests
SRCS
frexpl_test.cpp
+ HDRS
+ FrexpTest.h
DEPENDS
libc.include.math
libc.src.math.frexpl
@@ -802,6 +808,8 @@ add_fp_unittest(
libc_math_unittests
SRCS
logbl_test.cpp
+ HDRS
+ LogbTest.h
DEPENDS
libc.include.math
libc.src.math.logbl
@@ -814,6 +822,8 @@ add_fp_unittest(
libc_math_unittests
SRCS
modf_test.cpp
+ HDRS
+ ModfTest.h
DEPENDS
libc.include.math
libc.src.math.modf
@@ -826,6 +836,8 @@ add_fp_unittest(
libc_math_unittests
SRCS
modff_test.cpp
+ HDRS
+ ModfTest.h
DEPENDS
libc.include.math
libc.src.math.modff
@@ -838,6 +850,8 @@ add_fp_unittest(
libc_math_unittests
SRCS
modfl_test.cpp
+ HDRS
+ ModfTest.h
DEPENDS
libc.include.math
libc.src.math.modfl
diff --git a/libc/test/src/math/FrexpTest.h b/libc/test/src/math/FrexpTest.h
new file mode 100644
index 000000000000..e6c31f2fc440
--- /dev/null
+++ b/libc/test/src/math/FrexpTest.h
@@ -0,0 +1,118 @@
+//===-- Utility class to test frexp[f|l] ------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "utils/FPUtil/BasicOperations.h"
+#include "utils/FPUtil/TestHelpers.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+#include "utils/UnitTest/Test.h"
+
+#include <math.h>
+
+namespace mpfr = __llvm_libc::testing::mpfr;
+
+template <typename T> class FrexpTest : public __llvm_libc::testing::Test {
+
+ DECLARE_SPECIAL_CONSTANTS(T)
+
+ static constexpr UIntType HiddenBit =
+ UIntType(1) << __llvm_libc::fputil::MantissaWidth<T>::value;
+
+public:
+ typedef T (*FrexpFunc)(T, int *);
+
+ void testSpecialNumbers(FrexpFunc func) {
+ int exponent;
+ ASSERT_FP_EQ(aNaN, func(aNaN, &exponent));
+ ASSERT_FP_EQ(inf, func(inf, &exponent));
+ ASSERT_FP_EQ(negInf, func(negInf, &exponent));
+
+ ASSERT_FP_EQ(0.0, func(0.0, &exponent));
+ ASSERT_EQ(exponent, 0);
+
+ ASSERT_FP_EQ(-0.0, func(-0.0, &exponent));
+ ASSERT_EQ(exponent, 0);
+ }
+
+ void testPowersOfTwo(FrexpFunc func) {
+ int exponent;
+
+ EXPECT_FP_EQ(T(0.5), func(T(1.0), &exponent));
+ EXPECT_EQ(exponent, 1);
+ EXPECT_FP_EQ(T(-0.5), func(T(-1.0), &exponent));
+ EXPECT_EQ(exponent, 1);
+
+ EXPECT_FP_EQ(T(0.5), func(T(2.0), &exponent));
+ EXPECT_EQ(exponent, 2);
+ EXPECT_FP_EQ(T(-0.5), func(T(-2.0), &exponent));
+ EXPECT_EQ(exponent, 2);
+
+ EXPECT_FP_EQ(T(0.5), func(T(4.0), &exponent));
+ EXPECT_EQ(exponent, 3);
+ EXPECT_FP_EQ(T(-0.5), func(T(-4.0), &exponent));
+ EXPECT_EQ(exponent, 3);
+
+ EXPECT_FP_EQ(T(0.5), func(T(8.0), &exponent));
+ EXPECT_EQ(exponent, 4);
+ EXPECT_FP_EQ(T(-0.5), func(T(-8.0), &exponent));
+ EXPECT_EQ(exponent, 4);
+
+ EXPECT_FP_EQ(T(0.5), func(T(16.0), &exponent));
+ EXPECT_EQ(exponent, 5);
+ EXPECT_FP_EQ(T(-0.5), func(T(-16.0), &exponent));
+ EXPECT_EQ(exponent, 5);
+
+ EXPECT_FP_EQ(T(0.5), func(T(32.0), &exponent));
+ EXPECT_EQ(exponent, 6);
+ EXPECT_FP_EQ(T(-0.5), func(T(-32.0), &exponent));
+ EXPECT_EQ(exponent, 6);
+ }
+
+ void testSomeIntegers(FrexpFunc func) {
+ int exponent;
+
+ EXPECT_FP_EQ(T(0.75), func(T(24.0), &exponent));
+ EXPECT_EQ(exponent, 5);
+ EXPECT_FP_EQ(T(-0.75), func(T(-24.0), &exponent));
+ EXPECT_EQ(exponent, 5);
+
+ EXPECT_FP_EQ(T(0.625), func(T(40.0), &exponent));
+ EXPECT_EQ(exponent, 6);
+ EXPECT_FP_EQ(T(-0.625), func(T(-40.0), &exponent));
+ EXPECT_EQ(exponent, 6);
+
+ EXPECT_FP_EQ(T(0.78125), func(T(800.0), &exponent));
+ EXPECT_EQ(exponent, 10);
+ EXPECT_FP_EQ(T(-0.78125), func(T(-800.0), &exponent));
+ EXPECT_EQ(exponent, 10);
+ }
+
+ void testRange(FrexpFunc func) {
+ using UIntType = typename FPBits::UIntType;
+ constexpr UIntType count = 10000000;
+ constexpr UIntType step = UIntType(-1) / count;
+ for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
+ T x = static_cast<T>(FPBits(v));
+ if (isnan(x) || isinf(x) || x == 0.0l)
+ continue;
+
+ mpfr::BinaryOutput<T> result;
+ result.f = func(x, &result.i);
+
+ ASSERT_TRUE(__llvm_libc::fputil::abs(result.f) < 1.0);
+ ASSERT_TRUE(__llvm_libc::fputil::abs(result.f) >= 0.5);
+ ASSERT_MPFR_MATCH(mpfr::Operation::Frexp, x, result, 0.0);
+ }
+ }
+};
+
+#define LIST_FREXP_TESTS(T, func) \
+ using LlvmLibcFrexpTest = FrexpTest<T>; \
+ TEST_F(LlvmLibcFrexpTest, SpecialNumbers) { testSpecialNumbers(&func); } \
+ TEST_F(LlvmLibcFrexpTest, PowersOfTwo) { testPowersOfTwo(&func); } \
+ TEST_F(LlvmLibcFrexpTest, SomeIntegers) { testSomeIntegers(&func); } \
+ TEST_F(LlvmLibcFrexpTest, InRange) { testRange(&func); }
diff --git a/libc/test/src/math/LogbTest.h b/libc/test/src/math/LogbTest.h
new file mode 100644
index 000000000000..e993eca35e07
--- /dev/null
+++ b/libc/test/src/math/LogbTest.h
@@ -0,0 +1,94 @@
+//===-- Utility class to test logb[f|l] -------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "utils/FPUtil/ManipulationFunctions.h"
+#include "utils/FPUtil/TestHelpers.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+#include "utils/UnitTest/Test.h"
+
+#include <math.h>
+
+namespace mpfr = __llvm_libc::testing::mpfr;
+
+template <typename T> class LogbTest : public __llvm_libc::testing::Test {
+
+ DECLARE_SPECIAL_CONSTANTS(T)
+
+ static constexpr UIntType HiddenBit =
+ UIntType(1) << __llvm_libc::fputil::MantissaWidth<T>::value;
+
+public:
+ typedef T (*LogbFunc)(T);
+
+ void testSpecialNumbers(LogbFunc func) {
+ ASSERT_FP_EQ(aNaN, func(aNaN));
+ ASSERT_FP_EQ(inf, func(inf));
+ ASSERT_FP_EQ(inf, func(negInf));
+ ASSERT_FP_EQ(negInf, func(0.0));
+ ASSERT_FP_EQ(negInf, func(-0.0));
+ }
+
+ void testPowersOfTwo(LogbFunc func) {
+ EXPECT_FP_EQ(T(0.0), func(T(1.0)));
+ EXPECT_FP_EQ(T(0.0), func(T(-1.0)));
+
+ EXPECT_FP_EQ(T(1.0), func(T(2.0)));
+ EXPECT_FP_EQ(T(1.0), func(T(-2.0)));
+
+ EXPECT_FP_EQ(T(2.0), func(T(4.0)));
+ EXPECT_FP_EQ(T(2.0), func(T(-4.0)));
+
+ EXPECT_FP_EQ(T(3.0), func(T(8.0)));
+ EXPECT_FP_EQ(T(3.0), func(T(-8.0)));
+
+ EXPECT_FP_EQ(T(4.0), func(T(16.0)));
+ EXPECT_FP_EQ(T(4.0), func(T(-16.0)));
+
+ EXPECT_FP_EQ(T(5.0), func(T(32.0)));
+ EXPECT_FP_EQ(T(5.0), func(T(-32.0)));
+ }
+
+ void testSomeIntegers(LogbFunc func) {
+ EXPECT_FP_EQ(T(1.0), func(T(3.0)));
+ EXPECT_FP_EQ(T(1.0), func(T(-3.0)));
+
+ EXPECT_FP_EQ(T(2.0), func(T(7.0)));
+ EXPECT_FP_EQ(T(2.0), func(T(-7.0)));
+
+ EXPECT_FP_EQ(T(3.0), func(T(10.0)));
+ EXPECT_FP_EQ(T(3.0), func(T(-10.0)));
+
+ EXPECT_FP_EQ(T(4.0), func(T(31.0)));
+ EXPECT_FP_EQ(T(4.0), func(T(-31.0)));
+
+ EXPECT_FP_EQ(T(5.0), func(T(55.0)));
+ EXPECT_FP_EQ(T(5.0), func(T(-55.0)));
+ }
+
+ void testRange(LogbFunc func) {
+ using UIntType = typename FPBits::UIntType;
+ constexpr UIntType count = 10000000;
+ constexpr UIntType step = UIntType(-1) / count;
+ for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
+ T x = static_cast<T>(FPBits(v));
+ if (isnan(x) || isinf(x) || x == 0.0l)
+ continue;
+
+ int exponent;
+ __llvm_libc::fputil::frexp(x, exponent);
+ ASSERT_FP_EQ(T(exponent), func(x) + T(1.0));
+ }
+ }
+};
+
+#define LIST_LOGB_TESTS(T, func) \
+ using LlvmLibcLogbTest = LogbTest<T>; \
+ TEST_F(LlvmLibcLogbTest, SpecialNumbers) { testSpecialNumbers(&func); } \
+ TEST_F(LlvmLibcLogbTest, PowersOfTwo) { testPowersOfTwo(&func); } \
+ TEST_F(LlvmLibcLogbTest, SomeIntegers) { testSomeIntegers(&func); } \
+ TEST_F(LlvmLibcLogbTest, InRange) { testRange(&func); }
diff --git a/libc/test/src/math/ModfTest.h b/libc/test/src/math/ModfTest.h
new file mode 100644
index 000000000000..4c8f519083af
--- /dev/null
+++ b/libc/test/src/math/ModfTest.h
@@ -0,0 +1,108 @@
+//===-- Utility class to test floor[f|l] ------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "utils/FPUtil/BasicOperations.h"
+#include "utils/FPUtil/NearestIntegerOperations.h"
+#include "utils/FPUtil/TestHelpers.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+#include "utils/UnitTest/Test.h"
+
+#include <math.h>
+
+namespace mpfr = __llvm_libc::testing::mpfr;
+
+template <typename T> class ModfTest : public __llvm_libc::testing::Test {
+
+ DECLARE_SPECIAL_CONSTANTS(T)
+
+public:
+ typedef T (*ModfFunc)(T, T *);
+
+ void testSpecialNumbers(ModfFunc func) {
+ T integral;
+
+ EXPECT_FP_EQ(zero, func(zero, &integral));
+ EXPECT_FP_EQ(integral, zero);
+ EXPECT_FP_EQ(negZero, func(negZero, &integral));
+ EXPECT_FP_EQ(integral, negZero);
+
+ EXPECT_FP_EQ(zero, func(inf, &integral));
+ EXPECT_FP_EQ(inf, integral);
+ EXPECT_FP_EQ(negZero, func(negInf, &integral));
+ EXPECT_FP_EQ(negInf, integral);
+
+ EXPECT_FP_EQ(aNaN, func(aNaN, &integral));
+ }
+
+ void testIntegers(ModfFunc func) {
+ T integral;
+
+ EXPECT_FP_EQ(T(0.0), func(T(1.0), &integral));
+ EXPECT_FP_EQ(T(1.0), integral);
+
+ EXPECT_FP_EQ(T(-0.0), func(T(-1.0), &integral));
+ EXPECT_FP_EQ(T(-1.0), integral);
+
+ EXPECT_FP_EQ(T(0.0), func(T(10.0), &integral));
+ EXPECT_FP_EQ(T(10.0), integral);
+
+ EXPECT_FP_EQ(T(-0.0), func(T(-10.0), &integral));
+ EXPECT_FP_EQ(T(-10.0), integral);
+
+ EXPECT_FP_EQ(T(0.0), func(T(12345.0), &integral));
+ EXPECT_FP_EQ(T(12345.0), integral);
+
+ EXPECT_FP_EQ(T(-0.0), func(T(-12345.0), &integral));
+ EXPECT_FP_EQ(T(-12345.0), integral);
+ }
+
+ void testFractions(ModfFunc func) {
+ T integral;
+
+ EXPECT_FP_EQ(T(0.5), func(T(1.5), &integral));
+ EXPECT_FP_EQ(integral, T(1.0));
+
+ EXPECT_FP_EQ(T(-0.5), func(T(-1.5), &integral));
+ EXPECT_FP_EQ(integral, T(-1.0));
+
+ EXPECT_FP_EQ(T(0.75), func(T(10.75), &integral));
+ EXPECT_FP_EQ(integral, T(10.0));
+
+ EXPECT_FP_EQ(T(-0.75), func(T(-10.75), &integral));
+ EXPECT_FP_EQ(integral, T(-10.0));
+
+ EXPECT_FP_EQ(T(0.125), func(T(100.125), &integral));
+ EXPECT_FP_EQ(integral, T(100.0));
+
+ EXPECT_FP_EQ(T(-0.125), func(T(-100.125), &integral));
+ EXPECT_FP_EQ(integral, T(-100.0));
+ }
+
+ void testRange(ModfFunc func) {
+ constexpr UIntType count = 10000000;
+ constexpr UIntType step = UIntType(-1) / count;
+ for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
+ T x = T(FPBits(v));
+ if (isnan(x) || isinf(x) || x == T(0.0))
+ continue;
+
+ T integral;
+ T frac = func(x, &integral);
+ ASSERT_TRUE(__llvm_libc::fputil::abs(frac) < 1.0l);
+ ASSERT_TRUE(__llvm_libc::fputil::trunc(x) == integral);
+ ASSERT_TRUE(integral + frac == x);
+ }
+ }
+};
+
+#define LIST_MODF_TESTS(T, func) \
+ using LlvmLibcModfTest = ModfTest<T>; \
+ TEST_F(LlvmLibcModfTest, SpecialNumbers) { testSpecialNumbers(&func); } \
+ TEST_F(LlvmLibcModfTest, RoundedNubmers) { testIntegers(&func); } \
+ TEST_F(LlvmLibcModfTest, Fractions) { testFractions(&func); } \
+ TEST_F(LlvmLibcModfTest, Range) { testRange(&func); }
diff --git a/libc/test/src/math/cosf_test.cpp b/libc/test/src/math/cosf_test.cpp
index debcfaf22365..e9439a784a9b 100644
--- a/libc/test/src/math/cosf_test.cpp
+++ b/libc/test/src/math/cosf_test.cpp
@@ -9,10 +9,8 @@
#include "src/math/cosf.h"
#include "test/src/math/sdcomp26094.h"
#include "utils/CPP/Array.h"
-#include "utils/FPUtil/BitPatterns.h"
-#include "utils/FPUtil/ClassificationFunctions.h"
-#include "utils/FPUtil/FloatOperations.h"
-#include "utils/FPUtil/FloatProperties.h"
+#include "utils/FPUtil/FPBits.h"
+#include "utils/FPUtil/TestHelpers.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
#include "utils/UnitTest/Test.h"
#include <math.h>
@@ -20,51 +18,31 @@
#include <errno.h>
#include <stdint.h>
-using __llvm_libc::fputil::isNegativeQuietNaN;
-using __llvm_libc::fputil::isQuietNaN;
-using __llvm_libc::fputil::valueAsBits;
-using __llvm_libc::fputil::valueFromBits;
-
-using BitPatterns = __llvm_libc::fputil::BitPatterns<float>;
-
using __llvm_libc::testing::sdcomp26094Values;
+using FPBits = __llvm_libc::fputil::FPBits<float>;
namespace mpfr = __llvm_libc::testing::mpfr;
+DECLARE_SPECIAL_CONSTANTS(float)
+
TEST(LlvmLibcCosfTest, SpecialNumbers) {
errno = 0;
- EXPECT_TRUE(
- isQuietNaN(__llvm_libc::cosf(valueFromBits(BitPatterns::aQuietNaN))));
- EXPECT_EQ(errno, 0);
-
- EXPECT_TRUE(isNegativeQuietNaN(
- __llvm_libc::cosf(valueFromBits(BitPatterns::aNegativeQuietNaN))));
- EXPECT_EQ(errno, 0);
-
- EXPECT_TRUE(isQuietNaN(
- __llvm_libc::cosf(valueFromBits(BitPatterns::aSignallingNaN))));
- EXPECT_EQ(errno, 0);
-
- EXPECT_TRUE(isNegativeQuietNaN(
- __llvm_libc::cosf(valueFromBits(BitPatterns::aNegativeSignallingNaN))));
+ EXPECT_FP_EQ(aNaN, __llvm_libc::cosf(aNaN));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::one,
- valueAsBits(__llvm_libc::cosf(valueFromBits(BitPatterns::zero))));
+ EXPECT_FP_EQ(1.0f, __llvm_libc::cosf(0.0f));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::one, valueAsBits(__llvm_libc::cosf(
- valueFromBits(BitPatterns::negZero))));
+ EXPECT_FP_EQ(1.0f, __llvm_libc::cosf(-0.0f));
EXPECT_EQ(errno, 0);
errno = 0;
- EXPECT_TRUE(isQuietNaN(__llvm_libc::cosf(valueFromBits(BitPatterns::inf))));
+ EXPECT_FP_EQ(aNaN, __llvm_libc::cosf(inf));
EXPECT_EQ(errno, EDOM);
errno = 0;
- EXPECT_TRUE(
- isQuietNaN(__llvm_libc::cosf(valueFromBits(BitPatterns::negInf))));
+ EXPECT_FP_EQ(aNaN, __llvm_libc::cosf(negInf));
EXPECT_EQ(errno, EDOM);
}
@@ -72,7 +50,7 @@ TEST(LlvmLibcCosfTest, InFloatRange) {
constexpr uint32_t count = 1000000;
constexpr uint32_t step = UINT32_MAX / count;
for (uint32_t i = 0, v = 0; i <= count; ++i, v += step) {
- float x = valueFromBits(v);
+ float x = float(FPBits(v));
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, __llvm_libc::cosf(x), 1.0);
@@ -81,22 +59,22 @@ TEST(LlvmLibcCosfTest, InFloatRange) {
// For small values, cos(x) is 1.
TEST(LlvmLibcCosfTest, SmallValues) {
- float x = valueFromBits(0x17800000U);
+ float x = float(FPBits(0x17800000U));
float result = __llvm_libc::cosf(x);
EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result, 1.0);
- EXPECT_EQ(BitPatterns::one, valueAsBits(result));
+ EXPECT_FP_EQ(1.0f, result);
- x = valueFromBits(0x0040000U);
+ x = float(FPBits(0x0040000U));
result = __llvm_libc::cosf(x);
EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result, 1.0);
- EXPECT_EQ(BitPatterns::one, valueAsBits(result));
+ EXPECT_FP_EQ(1.0f, result);
}
// SDCOMP-26094: check cosf in the cases for which the range reducer
// returns values furthest beyond its nominal upper bound of pi/4.
TEST(LlvmLibcCosfTest, SDCOMP_26094) {
for (uint32_t v : sdcomp26094Values) {
- float x = valueFromBits(v);
+ float x = float(FPBits(v));
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 ef37f0985b1b..977ef1bce63c 100644
--- a/libc/test/src/math/exp2f_test.cpp
+++ b/libc/test/src/math/exp2f_test.cpp
@@ -7,10 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/math/exp2f.h"
-#include "utils/FPUtil/BitPatterns.h"
-#include "utils/FPUtil/ClassificationFunctions.h"
-#include "utils/FPUtil/FloatOperations.h"
-#include "utils/FPUtil/FloatProperties.h"
+#include "utils/FPUtil/FPBits.h"
+#include "utils/FPUtil/TestHelpers.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
#include "utils/UnitTest/Test.h"
#include <math.h>
@@ -18,65 +16,40 @@
#include <errno.h>
#include <stdint.h>
-using __llvm_libc::fputil::isNegativeQuietNaN;
-using __llvm_libc::fputil::isQuietNaN;
-using __llvm_libc::fputil::valueAsBits;
-using __llvm_libc::fputil::valueFromBits;
-
-using BitPatterns = __llvm_libc::fputil::BitPatterns<float>;
-
namespace mpfr = __llvm_libc::testing::mpfr;
-TEST(LlvmLibcexp2fTest, SpecialNumbers) {
- errno = 0;
-
- EXPECT_TRUE(
- isQuietNaN(__llvm_libc::exp2f(valueFromBits(BitPatterns::aQuietNaN))));
- EXPECT_EQ(errno, 0);
+DECLARE_SPECIAL_CONSTANTS(float)
- EXPECT_TRUE(isNegativeQuietNaN(
- __llvm_libc::exp2f(valueFromBits(BitPatterns::aNegativeQuietNaN))));
- EXPECT_EQ(errno, 0);
-
- EXPECT_TRUE(isQuietNaN(
- __llvm_libc::exp2f(valueFromBits(BitPatterns::aSignallingNaN))));
- EXPECT_EQ(errno, 0);
+TEST(LlvmLibcExp2fTest, SpecialNumbers) {
+ errno = 0;
- EXPECT_TRUE(isNegativeQuietNaN(
- __llvm_libc::exp2f(valueFromBits(BitPatterns::aNegativeSignallingNaN))));
+ EXPECT_FP_EQ(aNaN, __llvm_libc::exp2f(aNaN));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::exp2f(valueFromBits(BitPatterns::inf))));
+ EXPECT_FP_EQ(inf, __llvm_libc::exp2f(inf));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::zero, valueAsBits(__llvm_libc::exp2f(
- valueFromBits(BitPatterns::negInf))));
+ EXPECT_FP_EQ(0.0f, __llvm_libc::exp2f(negInf));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::one,
- valueAsBits(__llvm_libc::exp2f(valueFromBits(BitPatterns::zero))));
+ EXPECT_FP_EQ(1.0f, __llvm_libc::exp2f(0.0f));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::one, valueAsBits(__llvm_libc::exp2f(
- valueFromBits(BitPatterns::negZero))));
+ EXPECT_FP_EQ(1.0f, __llvm_libc::exp2f(-0.0f));
EXPECT_EQ(errno, 0);
}
TEST(LlvmLibcExpfTest, Overflow) {
errno = 0;
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::exp2f(valueFromBits(0x7f7fffffU))));
+ EXPECT_FP_EQ(inf, __llvm_libc::exp2f(float(FPBits(0x7f7fffffU))));
EXPECT_EQ(errno, ERANGE);
errno = 0;
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::exp2f(valueFromBits(0x43000000U))));
+ EXPECT_FP_EQ(inf, __llvm_libc::exp2f(float(FPBits(0x43000000U))));
EXPECT_EQ(errno, ERANGE);
errno = 0;
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::exp2f(valueFromBits(0x43000001U))));
+ EXPECT_FP_EQ(inf, __llvm_libc::exp2f(float(FPBits(0x43000001U))));
EXPECT_EQ(errno, ERANGE);
}
@@ -86,44 +59,43 @@ TEST(LlvmLibcExpfTest, Borderline) {
float x;
errno = 0;
- x = valueFromBits(0x42fa0001U);
+ x = float(FPBits(0x42fa0001U));
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(errno, 0);
- x = valueFromBits(0x42ffffffU);
+ x = float(FPBits(0x42ffffffU));
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(errno, 0);
- x = valueFromBits(0xc2fa0001U);
+ x = float(FPBits(0xc2fa0001U));
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(errno, 0);
- x = valueFromBits(0xc2fc0000U);
+ x = float(FPBits(0xc2fc0000U));
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(errno, 0);
- x = valueFromBits(0xc2fc0001U);
+ x = float(FPBits(0xc2fc0001U));
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(errno, 0);
- x = valueFromBits(0xc3150000U);
+ x = float(FPBits(0xc3150000U));
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(errno, 0);
}
TEST(LlvmLibcExpfTest, Underflow) {
errno = 0;
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::exp2f(valueFromBits(0xff7fffffU))));
+ EXPECT_FP_EQ(0.0f, __llvm_libc::exp2f(float(FPBits(0xff7fffffU))));
EXPECT_EQ(errno, ERANGE);
errno = 0;
- float x = valueFromBits(0xc3158000U);
+ float x = float(FPBits(0xc3158000U));
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(errno, ERANGE);
errno = 0;
- x = valueFromBits(0xc3165432U);
+ x = float(FPBits(0xc3165432U));
EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), 1.0);
EXPECT_EQ(errno, ERANGE);
}
@@ -132,7 +104,7 @@ TEST(LlvmLibcexp2fTest, InFloatRange) {
constexpr uint32_t count = 1000000;
constexpr uint32_t step = UINT32_MAX / count;
for (uint32_t i = 0, v = 0; i <= count; ++i, v += step) {
- float x = valueFromBits(v);
+ float x = float(FPBits(v));
if (isnan(x) || isinf(x))
continue;
errno = 0;
diff --git a/libc/test/src/math/expf_test.cpp b/libc/test/src/math/expf_test.cpp
index bbf46ebfaef1..495475fd5d0a 100644
--- a/libc/test/src/math/expf_test.cpp
+++ b/libc/test/src/math/expf_test.cpp
@@ -7,10 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/math/expf.h"
-#include "utils/FPUtil/BitPatterns.h"
-#include "utils/FPUtil/ClassificationFunctions.h"
-#include "utils/FPUtil/FloatOperations.h"
-#include "utils/FPUtil/FloatProperties.h"
+#include "utils/FPUtil/FPBits.h"
+#include "utils/FPUtil/TestHelpers.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
#include "utils/UnitTest/Test.h"
#include <math.h>
@@ -18,82 +16,56 @@
#include <errno.h>
#include <stdint.h>
-using __llvm_libc::fputil::isNegativeQuietNaN;
-using __llvm_libc::fputil::isQuietNaN;
-using __llvm_libc::fputil::valueAsBits;
-using __llvm_libc::fputil::valueFromBits;
-
-using BitPatterns = __llvm_libc::fputil::BitPatterns<float>;
-
namespace mpfr = __llvm_libc::testing::mpfr;
+DECLARE_SPECIAL_CONSTANTS(float)
+
TEST(LlvmLibcExpfTest, SpecialNumbers) {
errno = 0;
- EXPECT_TRUE(
- isQuietNaN(__llvm_libc::expf(valueFromBits(BitPatterns::aQuietNaN))));
- EXPECT_EQ(errno, 0);
-
- EXPECT_TRUE(isNegativeQuietNaN(
- __llvm_libc::expf(valueFromBits(BitPatterns::aNegativeQuietNaN))));
- EXPECT_EQ(errno, 0);
-
- EXPECT_TRUE(isQuietNaN(
- __llvm_libc::expf(valueFromBits(BitPatterns::aSignallingNaN))));
- EXPECT_EQ(errno, 0);
-
- EXPECT_TRUE(isNegativeQuietNaN(
- __llvm_libc::expf(valueFromBits(BitPatterns::aNegativeSignallingNaN))));
+ EXPECT_FP_EQ(aNaN, __llvm_libc::expf(aNaN));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::expf(valueFromBits(BitPatterns::inf))));
+ EXPECT_FP_EQ(inf, __llvm_libc::expf(inf));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::expf(valueFromBits(BitPatterns::negInf))));
+ EXPECT_FP_EQ(0.0f, __llvm_libc::expf(negInf));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::one,
- valueAsBits(__llvm_libc::expf(valueFromBits(BitPatterns::zero))));
+ EXPECT_FP_EQ(1.0f, __llvm_libc::expf(0.0f));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::one, valueAsBits(__llvm_libc::expf(
- valueFromBits(BitPatterns::negZero))));
+ EXPECT_FP_EQ(1.0f, __llvm_libc::expf(-0.0f));
EXPECT_EQ(errno, 0);
}
TEST(LlvmLibcExpfTest, Overflow) {
errno = 0;
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::expf(valueFromBits(0x7f7fffffU))));
+ EXPECT_FP_EQ(inf, __llvm_libc::expf(float(FPBits(0x7f7fffffU))));
EXPECT_EQ(errno, ERANGE);
errno = 0;
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::expf(valueFromBits(0x42cffff8U))));
+ EXPECT_FP_EQ(inf, __llvm_libc::expf(float(FPBits(0x42cffff8U))));
EXPECT_EQ(errno, ERANGE);
errno = 0;
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::expf(valueFromBits(0x42d00008U))));
+ EXPECT_FP_EQ(inf, __llvm_libc::expf(float(FPBits(0x42d00008U))));
EXPECT_EQ(errno, ERANGE);
}
TEST(LlvmLibcExpfTest, Underflow) {
errno = 0;
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::expf(valueFromBits(0xff7fffffU))));
+ EXPECT_FP_EQ(0.0f, __llvm_libc::expf(float(FPBits(0xff7fffffU))));
EXPECT_EQ(errno, ERANGE);
errno = 0;
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::expf(valueFromBits(0xc2cffff8U))));
+ float x = float(FPBits(0xc2cffff8U));
+ EXPECT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
EXPECT_EQ(errno, ERANGE);
errno = 0;
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::expf(valueFromBits(0xc2d00008U))));
+ x = float(FPBits(0xc2d00008U));
+ EXPECT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
EXPECT_EQ(errno, ERANGE);
}
@@ -103,19 +75,19 @@ TEST(LlvmLibcExpfTest, Borderline) {
float x;
errno = 0;
- x = valueFromBits(0x42affff8U);
+ x = float(FPBits(0x42affff8U));
ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
EXPECT_EQ(errno, 0);
- x = valueFromBits(0x42b00008U);
+ x = float(FPBits(0x42b00008U));
ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
EXPECT_EQ(errno, 0);
- x = valueFromBits(0xc2affff8U);
+ x = float(FPBits(0xc2affff8U));
ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
EXPECT_EQ(errno, 0);
- x = valueFromBits(0xc2b00008U);
+ x = float(FPBits(0xc2b00008U));
ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), 1.0);
EXPECT_EQ(errno, 0);
}
@@ -124,7 +96,7 @@ TEST(LlvmLibcExpfTest, InFloatRange) {
constexpr uint32_t count = 1000000;
constexpr uint32_t step = UINT32_MAX / count;
for (uint32_t i = 0, v = 0; i <= count; ++i, v += step) {
- float x = valueFromBits(v);
+ float x = float(FPBits(v));
if (isnan(x) || isinf(x))
continue;
errno = 0;
diff --git a/libc/test/src/math/expm1f_test.cpp b/libc/test/src/math/expm1f_test.cpp
index d4b06c29c4bb..5fa51b4c9a5d 100644
--- a/libc/test/src/math/expm1f_test.cpp
+++ b/libc/test/src/math/expm1f_test.cpp
@@ -7,10 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/math/expm1f.h"
-#include "utils/FPUtil/BitPatterns.h"
-#include "utils/FPUtil/ClassificationFunctions.h"
-#include "utils/FPUtil/FloatOperations.h"
-#include "utils/FPUtil/FloatProperties.h"
+#include "utils/FPUtil/FPBits.h"
+#include "utils/FPUtil/TestHelpers.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
#include "utils/UnitTest/Test.h"
#include <math.h>
@@ -18,82 +16,56 @@
#include <errno.h>
#include <stdint.h>
-using __llvm_libc::fputil::isNegativeQuietNaN;
-using __llvm_libc::fputil::isQuietNaN;
-using __llvm_libc::fputil::valueAsBits;
-using __llvm_libc::fputil::valueFromBits;
-
-using BitPatterns = __llvm_libc::fputil::BitPatterns<float>;
-
namespace mpfr = __llvm_libc::testing::mpfr;
+DECLARE_SPECIAL_CONSTANTS(float)
+
TEST(LlvmLibcExpm1fTest, SpecialNumbers) {
errno = 0;
- EXPECT_TRUE(
- isQuietNaN(__llvm_libc::expm1f(valueFromBits(BitPatterns::aQuietNaN))));
- EXPECT_EQ(errno, 0);
-
- EXPECT_TRUE(isNegativeQuietNaN(
- __llvm_libc::expm1f(valueFromBits(BitPatterns::aNegativeQuietNaN))));
- EXPECT_EQ(errno, 0);
-
- EXPECT_TRUE(isQuietNaN(
- __llvm_libc::expm1f(valueFromBits(BitPatterns::aSignallingNaN))));
- EXPECT_EQ(errno, 0);
-
- EXPECT_TRUE(isNegativeQuietNaN(
- __llvm_libc::expm1f(valueFromBits(BitPatterns::aNegativeSignallingNaN))));
+ EXPECT_FP_EQ(aNaN, __llvm_libc::expm1f(aNaN));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::expm1f(valueFromBits(BitPatterns::inf))));
+ EXPECT_FP_EQ(inf, __llvm_libc::expm1f(inf));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::negOne, valueAsBits(__llvm_libc::expm1f(
- valueFromBits(BitPatterns::negInf))));
+ EXPECT_FP_EQ(-1.0f, __llvm_libc::expm1f(negInf));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::expm1f(valueFromBits(BitPatterns::zero))));
+ EXPECT_FP_EQ(0.0f, __llvm_libc::expm1f(0.0f));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::negZero, valueAsBits(__llvm_libc::expm1f(
- valueFromBits(BitPatterns::negZero))));
+ EXPECT_FP_EQ(-0.0f, __llvm_libc::expm1f(-0.0f));
EXPECT_EQ(errno, 0);
}
TEST(LlvmLibcExpm1fTest, Overflow) {
errno = 0;
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::expm1f(valueFromBits(0x7f7fffffU))));
+ EXPECT_FP_EQ(inf, __llvm_libc::expm1f(float(FPBits(0x7f7fffffU))));
EXPECT_EQ(errno, ERANGE);
errno = 0;
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::expm1f(valueFromBits(0x42cffff8U))));
+ EXPECT_FP_EQ(inf, __llvm_libc::expm1f(float(FPBits(0x42cffff8U))));
EXPECT_EQ(errno, ERANGE);
errno = 0;
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::expm1f(valueFromBits(0x42d00008U))));
+ EXPECT_FP_EQ(inf, __llvm_libc::expm1f(float(FPBits(0x42d00008U))));
EXPECT_EQ(errno, ERANGE);
}
TEST(LlvmLibcExpm1fTest, Underflow) {
errno = 0;
- EXPECT_EQ(BitPatterns::negOne,
- valueAsBits(__llvm_libc::expm1f(valueFromBits(0xff7fffffU))));
+ EXPECT_FP_EQ(-1.0f, __llvm_libc::expm1f(float(FPBits(0xff7fffffU))));
EXPECT_EQ(errno, ERANGE);
errno = 0;
- EXPECT_EQ(BitPatterns::negOne,
- valueAsBits(__llvm_libc::expm1f(valueFromBits(0xc2cffff8U))));
+ float x = float(FPBits(0xc2cffff8U));
+ EXPECT_FP_EQ(-1.0f, __llvm_libc::expm1f(x));
EXPECT_EQ(errno, ERANGE);
errno = 0;
- EXPECT_EQ(BitPatterns::negOne,
- valueAsBits(__llvm_libc::expm1f(valueFromBits(0xc2d00008U))));
+ x = float(FPBits(0xc2d00008U));
+ EXPECT_FP_EQ(-1.0f, __llvm_libc::expm1f(x));
EXPECT_EQ(errno, ERANGE);
}
@@ -103,19 +75,19 @@ TEST(LlvmLibcExpm1fTest, Borderline) {
float x;
errno = 0;
- x = valueFromBits(0x42affff8U);
+ x = float(FPBits(0x42affff8U));
ASSERT_MPFR_MATCH(mpfr::Operation::Expm1, x, __llvm_libc::expm1f(x), 1.0);
EXPECT_EQ(errno, 0);
- x = valueFromBits(0x42b00008U);
+ x = float(FPBits(0x42b00008U));
ASSERT_MPFR_MATCH(mpfr::Operation::Expm1, x, __llvm_libc::expm1f(x), 1.0);
EXPECT_EQ(errno, 0);
- x = valueFromBits(0xc2affff8U);
+ x = float(FPBits(0xc2affff8U));
ASSERT_MPFR_MATCH(mpfr::Operation::Expm1, x, __llvm_libc::expm1f(x), 1.0);
EXPECT_EQ(errno, 0);
- x = valueFromBits(0xc2b00008U);
+ x = float(FPBits(0xc2b00008U));
ASSERT_MPFR_MATCH(mpfr::Operation::Expm1, x, __llvm_libc::expm1f(x), 1.0);
EXPECT_EQ(errno, 0);
}
@@ -124,7 +96,7 @@ TEST(LlvmLibcExpm1fTest, InFloatRange) {
constexpr uint32_t count = 1000000;
constexpr uint32_t step = UINT32_MAX / count;
for (uint32_t i = 0, v = 0; i <= count; ++i, v += step) {
- float x = valueFromBits(v);
+ float x = float(FPBits(v));
if (isnan(x) || isinf(x))
continue;
errno = 0;
diff --git a/libc/test/src/math/frexp_test.cpp b/libc/test/src/math/frexp_test.cpp
index 2d8ae1c9ca1a..a44aefc7d8b4 100644
--- a/libc/test/src/math/frexp_test.cpp
+++ b/libc/test/src/math/frexp_test.cpp
@@ -6,145 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "src/math/frexp.h"
-#include "utils/FPUtil/BasicOperations.h"
-#include "utils/FPUtil/BitPatterns.h"
-#include "utils/FPUtil/ClassificationFunctions.h"
-#include "utils/FPUtil/FPBits.h"
-#include "utils/FPUtil/FloatOperations.h"
-#include "utils/FPUtil/FloatProperties.h"
-#include "utils/MPFRWrapper/MPFRUtils.h"
-#include "utils/UnitTest/Test.h"
-#include <math.h>
-
-using FPBits = __llvm_libc::fputil::FPBits<double>;
-using __llvm_libc::fputil::valueAsBits;
-using __llvm_libc::fputil::valueFromBits;
-
-namespace mpfr = __llvm_libc::testing::mpfr;
-
-using BitPatterns = __llvm_libc::fputil::BitPatterns<double>;
-using Properties = __llvm_libc::fputil::FloatProperties<double>;
-
-TEST(LlvmLibcFrexpTest, SpecialNumbers) {
- int exponent;
-
- EXPECT_EQ(BitPatterns::aQuietNaN,
- valueAsBits(__llvm_libc::frexp(
- valueFromBits(BitPatterns::aQuietNaN), &exponent)));
- EXPECT_EQ(BitPatterns::aNegativeQuietNaN,
- valueAsBits(__llvm_libc::frexp(
- valueFromBits(BitPatterns::aNegativeQuietNaN), &exponent)));
-
- EXPECT_EQ(BitPatterns::aSignallingNaN,
- valueAsBits(__llvm_libc::frexp(
- valueFromBits(BitPatterns::aSignallingNaN), &exponent)));
- EXPECT_EQ(
- BitPatterns::aNegativeSignallingNaN,
- valueAsBits(__llvm_libc::frexp(
- valueFromBits(BitPatterns::aNegativeSignallingNaN), &exponent)));
-
- EXPECT_EQ(BitPatterns::inf, valueAsBits(__llvm_libc::frexp(
- valueFromBits(BitPatterns::inf), &exponent)));
- EXPECT_EQ(BitPatterns::negInf,
- valueAsBits(__llvm_libc::frexp(valueFromBits(BitPatterns::negInf),
- &exponent)));
-
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::frexp(valueFromBits(BitPatterns::zero),
- &exponent)));
- EXPECT_EQ(exponent, 0);
- EXPECT_EQ(BitPatterns::negZero,
- valueAsBits(__llvm_libc::frexp(valueFromBits(BitPatterns::negZero),
- &exponent)));
- EXPECT_EQ(exponent, 0);
-}
-
-TEST(LlvmLibcFrexpTest, PowersOfTwo) {
- int exponent;
-
- EXPECT_EQ(valueAsBits(0.5), valueAsBits(__llvm_libc::frexp(1.0, &exponent)));
- EXPECT_EQ(exponent, 1);
- EXPECT_EQ(valueAsBits(-0.5),
- valueAsBits(__llvm_libc::frexp(-1.0, &exponent)));
- EXPECT_EQ(exponent, 1);
-
- EXPECT_EQ(valueAsBits(0.5), valueAsBits(__llvm_libc::frexp(2.0, &exponent)));
- EXPECT_EQ(exponent, 2);
- EXPECT_EQ(valueAsBits(-0.5),
- valueAsBits(__llvm_libc::frexp(-2.0, &exponent)));
- EXPECT_EQ(exponent, 2);
+#include "FrexpTest.h"
- EXPECT_EQ(valueAsBits(0.5), valueAsBits(__llvm_libc::frexp(4.0, &exponent)));
- EXPECT_EQ(exponent, 3);
- EXPECT_EQ(valueAsBits(-0.5),
- valueAsBits(__llvm_libc::frexp(-4.0, &exponent)));
- EXPECT_EQ(exponent, 3);
-
- EXPECT_EQ(valueAsBits(0.5), valueAsBits(__llvm_libc::frexp(8.0, &exponent)));
- EXPECT_EQ(exponent, 4);
- EXPECT_EQ(valueAsBits(-0.5),
- valueAsBits(__llvm_libc::frexp(-8.0, &exponent)));
- EXPECT_EQ(exponent, 4);
-
- EXPECT_EQ(valueAsBits(0.5), valueAsBits(__llvm_libc::frexp(16.0, &exponent)));
- EXPECT_EQ(exponent, 5);
- EXPECT_EQ(valueAsBits(-0.5),
- valueAsBits(__llvm_libc::frexp(-16.0, &exponent)));
- EXPECT_EQ(exponent, 5);
-
- EXPECT_EQ(valueAsBits(0.5), valueAsBits(__llvm_libc::frexp(32.0, &exponent)));
- EXPECT_EQ(exponent, 6);
- EXPECT_EQ(valueAsBits(-0.5),
- valueAsBits(__llvm_libc::frexp(-32.0, &exponent)));
- EXPECT_EQ(exponent, 6);
-
- EXPECT_EQ(valueAsBits(0.5), valueAsBits(__llvm_libc::frexp(64.0, &exponent)));
- EXPECT_EQ(exponent, 7);
- EXPECT_EQ(valueAsBits(-0.5),
- valueAsBits(__llvm_libc::frexp(-64.0, &exponent)));
- EXPECT_EQ(exponent, 7);
-}
-
-TEST(LlvmLibcFrexpTest, SomeIntegers) {
- int exponent;
-
- EXPECT_EQ(valueAsBits(0.75),
- valueAsBits(__llvm_libc::frexp(24.0, &exponent)));
- EXPECT_EQ(exponent, 5);
- EXPECT_EQ(valueAsBits(-0.75),
- valueAsBits(__llvm_libc::frexp(-24.0, &exponent)));
- EXPECT_EQ(exponent, 5);
-
- EXPECT_EQ(valueAsBits(0.625),
- valueAsBits(__llvm_libc::frexp(40.0, &exponent)));
- EXPECT_EQ(exponent, 6);
- EXPECT_EQ(valueAsBits(-0.625),
- valueAsBits(__llvm_libc::frexp(-40.0, &exponent)));
- EXPECT_EQ(exponent, 6);
-
- EXPECT_EQ(valueAsBits(0.78125),
- valueAsBits(__llvm_libc::frexp(800.0, &exponent)));
- EXPECT_EQ(exponent, 10);
- EXPECT_EQ(valueAsBits(-0.78125),
- valueAsBits(__llvm_libc::frexp(-800.0, &exponent)));
- EXPECT_EQ(exponent, 10);
-}
-
-TEST(LlvmLibcFrexpTest, InDoubleRange) {
- using UIntType = FPBits::UIntType;
- constexpr UIntType count = 1000001;
- constexpr UIntType step = UIntType(-1) / count;
- for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
- double x = double(FPBits(v));
- if (isnan(x) || isinf(x) || x == 0.0)
- continue;
-
- mpfr::BinaryOutput<double> result;
- result.f = __llvm_libc::frexp(x, &result.i);
+#include "src/math/frexp.h"
- ASSERT_TRUE(__llvm_libc::fputil::abs(result.f) < 1.0);
- ASSERT_TRUE(__llvm_libc::fputil::abs(result.f) >= 0.5);
- ASSERT_MPFR_MATCH(mpfr::Operation::Frexp, x, result, 0.0);
- }
-}
+LIST_FREXP_TESTS(double, __llvm_libc::frexp)
diff --git a/libc/test/src/math/frexpf_test.cpp b/libc/test/src/math/frexpf_test.cpp
index a3a3da4530b8..5d78f94ec1e5 100644
--- a/libc/test/src/math/frexpf_test.cpp
+++ b/libc/test/src/math/frexpf_test.cpp
@@ -6,152 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "src/math/frexpf.h"
-#include "utils/FPUtil/BasicOperations.h"
-#include "utils/FPUtil/BitPatterns.h"
-#include "utils/FPUtil/ClassificationFunctions.h"
-#include "utils/FPUtil/FPBits.h"
-#include "utils/FPUtil/FloatOperations.h"
-#include "utils/FPUtil/FloatProperties.h"
-#include "utils/MPFRWrapper/MPFRUtils.h"
-#include "utils/UnitTest/Test.h"
-#include <math.h>
-
-using FPBits = __llvm_libc::fputil::FPBits<float>;
-using __llvm_libc::fputil::valueAsBits;
-using __llvm_libc::fputil::valueFromBits;
-
-namespace mpfr = __llvm_libc::testing::mpfr;
-
-using BitPatterns = __llvm_libc::fputil::BitPatterns<float>;
-using Properties = __llvm_libc::fputil::FloatProperties<float>;
-
-TEST(LlvmLibcFrexpfTest, SpecialNumbers) {
- int exponent;
-
- EXPECT_EQ(BitPatterns::aQuietNaN,
- valueAsBits(__llvm_libc::frexpf(
- valueFromBits(BitPatterns::aQuietNaN), &exponent)));
- EXPECT_EQ(BitPatterns::aNegativeQuietNaN,
- valueAsBits(__llvm_libc::frexpf(
- valueFromBits(BitPatterns::aNegativeQuietNaN), &exponent)));
-
- EXPECT_EQ(BitPatterns::aSignallingNaN,
- valueAsBits(__llvm_libc::frexpf(
- valueFromBits(BitPatterns::aSignallingNaN), &exponent)));
- EXPECT_EQ(
- BitPatterns::aNegativeSignallingNaN,
- valueAsBits(__llvm_libc::frexpf(
- valueFromBits(BitPatterns::aNegativeSignallingNaN), &exponent)));
-
- EXPECT_EQ(BitPatterns::inf, valueAsBits(__llvm_libc::frexpf(
- valueFromBits(BitPatterns::inf), &exponent)));
- EXPECT_EQ(BitPatterns::negInf,
- valueAsBits(__llvm_libc::frexpf(valueFromBits(BitPatterns::negInf),
- &exponent)));
-
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::frexpf(valueFromBits(BitPatterns::zero),
- &exponent)));
- EXPECT_EQ(exponent, 0);
- EXPECT_EQ(BitPatterns::negZero,
- valueAsBits(__llvm_libc::frexpf(valueFromBits(BitPatterns::negZero),
- &exponent)));
- EXPECT_EQ(exponent, 0);
-}
-
-TEST(LlvmLibcFrexpfTest, PowersOfTwo) {
- int exponent;
-
- EXPECT_EQ(valueAsBits(0.5f),
- valueAsBits(__llvm_libc::frexpf(1.0f, &exponent)));
- EXPECT_EQ(exponent, 1);
- EXPECT_EQ(valueAsBits(-0.5f),
- valueAsBits(__llvm_libc::frexpf(-1.0f, &exponent)));
- EXPECT_EQ(exponent, 1);
-
- EXPECT_EQ(valueAsBits(0.5f),
- valueAsBits(__llvm_libc::frexpf(2.0f, &exponent)));
- EXPECT_EQ(exponent, 2);
- EXPECT_EQ(valueAsBits(-0.5f),
- valueAsBits(__llvm_libc::frexpf(-2.0f, &exponent)));
- EXPECT_EQ(exponent, 2);
+#include "FrexpTest.h"
- EXPECT_EQ(valueAsBits(0.5f),
- valueAsBits(__llvm_libc::frexpf(4.0f, &exponent)));
- EXPECT_EQ(exponent, 3);
- EXPECT_EQ(valueAsBits(-0.5f),
- valueAsBits(__llvm_libc::frexpf(-4.0f, &exponent)));
- EXPECT_EQ(exponent, 3);
-
- EXPECT_EQ(valueAsBits(0.5f),
- valueAsBits(__llvm_libc::frexpf(8.0f, &exponent)));
- EXPECT_EQ(exponent, 4);
- EXPECT_EQ(valueAsBits(-0.5f),
- valueAsBits(__llvm_libc::frexpf(-8.0f, &exponent)));
- EXPECT_EQ(exponent, 4);
-
- EXPECT_EQ(valueAsBits(0.5f),
- valueAsBits(__llvm_libc::frexpf(16.0f, &exponent)));
- EXPECT_EQ(exponent, 5);
- EXPECT_EQ(valueAsBits(-0.5f),
- valueAsBits(__llvm_libc::frexpf(-16.0f, &exponent)));
- EXPECT_EQ(exponent, 5);
-
- EXPECT_EQ(valueAsBits(0.5f),
- valueAsBits(__llvm_libc::frexpf(32.0f, &exponent)));
- EXPECT_EQ(exponent, 6);
- EXPECT_EQ(valueAsBits(-0.5f),
- valueAsBits(__llvm_libc::frexpf(-32.0f, &exponent)));
- EXPECT_EQ(exponent, 6);
-
- EXPECT_EQ(valueAsBits(0.5f),
- valueAsBits(__llvm_libc::frexpf(64.0f, &exponent)));
- EXPECT_EQ(exponent, 7);
- EXPECT_EQ(valueAsBits(-0.5f),
- valueAsBits(__llvm_libc::frexpf(-64.0f, &exponent)));
- EXPECT_EQ(exponent, 7);
-}
-
-TEST(LlvmLibcFrexpfTest, SomeIntegers) {
- int exponent;
-
- EXPECT_EQ(valueAsBits(0.75f),
- valueAsBits(__llvm_libc::frexpf(24.0f, &exponent)));
- EXPECT_EQ(exponent, 5);
- EXPECT_EQ(valueAsBits(-0.75f),
- valueAsBits(__llvm_libc::frexpf(-24.0f, &exponent)));
- EXPECT_EQ(exponent, 5);
-
- EXPECT_EQ(valueAsBits(0.625f),
- valueAsBits(__llvm_libc::frexpf(40.0f, &exponent)));
- EXPECT_EQ(exponent, 6);
- EXPECT_EQ(valueAsBits(-0.625f),
- valueAsBits(__llvm_libc::frexpf(-40.0f, &exponent)));
- EXPECT_EQ(exponent, 6);
-
- EXPECT_EQ(valueAsBits(0.78125f),
- valueAsBits(__llvm_libc::frexpf(800.0f, &exponent)));
- EXPECT_EQ(exponent, 10);
- EXPECT_EQ(valueAsBits(-0.78125f),
- valueAsBits(__llvm_libc::frexpf(-800.0f, &exponent)));
- EXPECT_EQ(exponent, 10);
-}
-
-TEST(LlvmLibcFrexpfTest, InFloatRange) {
- using UIntType = FPBits::UIntType;
- constexpr UIntType count = 1000001;
- constexpr UIntType step = UIntType(-1) / count;
- for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
- float x = float(FPBits(v));
- if (isnan(x) || isinf(x) || x == 0.0)
- continue;
-
- mpfr::BinaryOutput<float> result;
- result.f = __llvm_libc::frexpf(x, &result.i);
+#include "src/math/frexpf.h"
- ASSERT_TRUE(__llvm_libc::fputil::abs(result.f) < 1.0);
- ASSERT_TRUE(__llvm_libc::fputil::abs(result.f) >= 0.5);
- ASSERT_MPFR_MATCH(mpfr::Operation::Frexp, x, result, 0.0);
- }
-}
+LIST_FREXP_TESTS(float, __llvm_libc::frexpf)
diff --git a/libc/test/src/math/frexpl_test.cpp b/libc/test/src/math/frexpl_test.cpp
index 053782b0ba10..4904ccd14907 100644
--- a/libc/test/src/math/frexpl_test.cpp
+++ b/libc/test/src/math/frexpl_test.cpp
@@ -6,105 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "src/math/frexpl.h"
-#include "utils/FPUtil/BasicOperations.h"
-#include "utils/FPUtil/FPBits.h"
-#include "utils/MPFRWrapper/MPFRUtils.h"
-#include "utils/UnitTest/Test.h"
-#include <math.h>
-
-typedef long double LD;
-using FPBits = __llvm_libc::fputil::FPBits<long double>;
-
-namespace mpfr = __llvm_libc::testing::mpfr;
-
-TEST(LlvmLibcFrexplTest, SpecialNumbers) {
- int exponent;
-
- EXPECT_TRUE(LD(FPBits::inf()) ==
- __llvm_libc::frexpl(LD(FPBits::inf()), &exponent));
- EXPECT_TRUE(LD(FPBits::negInf()) ==
- __llvm_libc::frexpl(LD(FPBits::negInf()), &exponent));
-
- EXPECT_TRUE(LD(FPBits::zero()) ==
- __llvm_libc::frexpl(LD(FPBits::zero()), &exponent));
- EXPECT_EQ(exponent, 0);
-
- EXPECT_TRUE(LD(FPBits::negZero()) ==
- __llvm_libc::frexpl(LD(FPBits::negZero()), &exponent));
- EXPECT_EQ(exponent, 0);
-
- EXPECT_TRUE(
- FPBits(__llvm_libc::frexpl(LD(FPBits::buildNaN(1)), &exponent)).isNaN());
-}
-
-TEST(LlvmLibcFrexplTest, PowersOfTwo) {
- int exponent;
-
- EXPECT_TRUE(0.5l == __llvm_libc::frexpl(1.0l, &exponent));
- EXPECT_EQ(exponent, 1);
- EXPECT_TRUE(-0.5l == __llvm_libc::frexpl(-1.0l, &exponent));
- EXPECT_EQ(exponent, 1);
-
- EXPECT_TRUE(0.5l == __llvm_libc::frexpl(2.0l, &exponent));
- EXPECT_EQ(exponent, 2);
- EXPECT_TRUE(-0.5l == __llvm_libc::frexpl(-2.0l, &exponent));
- EXPECT_EQ(exponent, 2);
+#include "FrexpTest.h"
- EXPECT_TRUE(0.5l == __llvm_libc::frexpl(4.0l, &exponent));
- EXPECT_EQ(exponent, 3);
- EXPECT_TRUE(-0.5l == __llvm_libc::frexpl(-4.0l, &exponent));
- EXPECT_EQ(exponent, 3);
-
- EXPECT_TRUE(0.5l == __llvm_libc::frexpl(8.0l, &exponent));
- EXPECT_EQ(exponent, 4);
- EXPECT_TRUE(-0.5l == __llvm_libc::frexpl(-8.0l, &exponent));
- EXPECT_EQ(exponent, 4);
-
- EXPECT_TRUE(0.5l == __llvm_libc::frexpl(16.0l, &exponent));
- EXPECT_EQ(exponent, 5);
- EXPECT_TRUE(-0.5l == __llvm_libc::frexpl(-16.0l, &exponent));
- EXPECT_EQ(exponent, 5);
-
- EXPECT_TRUE(0.5l == __llvm_libc::frexpl(32.0l, &exponent));
- EXPECT_EQ(exponent, 6);
- EXPECT_TRUE(-0.5l == __llvm_libc::frexpl(-32.0l, &exponent));
- EXPECT_EQ(exponent, 6);
-}
-
-TEST(LlvmLibcFrexplTest, SomeIntegers) {
- int exponent;
-
- EXPECT_TRUE(0.75l == __llvm_libc::frexpl(24.0l, &exponent));
- EXPECT_EQ(exponent, 5);
- EXPECT_TRUE(-0.75l == __llvm_libc::frexpl(-24.0l, &exponent));
- EXPECT_EQ(exponent, 5);
-
- EXPECT_TRUE(0.625l == __llvm_libc::frexpl(40.0l, &exponent));
- EXPECT_EQ(exponent, 6);
- EXPECT_TRUE(-0.625l == __llvm_libc::frexpl(-40.0l, &exponent));
- EXPECT_EQ(exponent, 6);
-
- EXPECT_TRUE(0.78125l == __llvm_libc::frexpl(800.0l, &exponent));
- EXPECT_EQ(exponent, 10);
- EXPECT_TRUE(-0.78125l == __llvm_libc::frexpl(-800.0l, &exponent));
- EXPECT_EQ(exponent, 10);
-}
-
-TEST(LlvmLibcFrexplTest, LongDoubleRange) {
- using UIntType = FPBits::UIntType;
- constexpr UIntType count = 10000000;
- constexpr UIntType step = UIntType(-1) / count;
- for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
- long double x = static_cast<long double>(FPBits(v));
- if (isnan(x) || isinf(x) || x == 0.0l)
- continue;
-
- mpfr::BinaryOutput<long double> result;
- result.f = __llvm_libc::frexpl(x, &result.i);
+#include "src/math/frexpl.h"
- ASSERT_TRUE(__llvm_libc::fputil::abs(result.f) < 1.0);
- ASSERT_TRUE(__llvm_libc::fputil::abs(result.f) >= 0.5);
- ASSERT_MPFR_MATCH(mpfr::Operation::Frexp, x, result, 0.0);
- }
-}
+LIST_FREXP_TESTS(long double, __llvm_libc::frexpl)
diff --git a/libc/test/src/math/logb_test.cpp b/libc/test/src/math/logb_test.cpp
index ca0f9eacde6f..b90348522aa3 100644
--- a/libc/test/src/math/logb_test.cpp
+++ b/libc/test/src/math/logb_test.cpp
@@ -6,94 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "src/math/logb.h"
-#include "utils/FPUtil/BitPatterns.h"
-#include "utils/FPUtil/FloatOperations.h"
-#include "utils/FPUtil/FloatProperties.h"
-#include "utils/FPUtil/ManipulationFunctions.h"
-#include "utils/UnitTest/Test.h"
-#include <math.h>
-
-using __llvm_libc::fputil::valueAsBits;
-using __llvm_libc::fputil::valueFromBits;
-
-using BitPatterns = __llvm_libc::fputil::BitPatterns<double>;
-using Properties = __llvm_libc::fputil::FloatProperties<double>;
-
-TEST(LlvmLibcLogbTest, SpecialNumbers) {
- EXPECT_EQ(
- BitPatterns::aQuietNaN,
- valueAsBits(__llvm_libc::logb(valueFromBits(BitPatterns::aQuietNaN))));
- EXPECT_EQ(BitPatterns::aNegativeQuietNaN,
- valueAsBits(__llvm_libc::logb(
- valueFromBits(BitPatterns::aNegativeQuietNaN))));
-
- EXPECT_EQ(BitPatterns::aSignallingNaN,
- valueAsBits(
- __llvm_libc::logb(valueFromBits(BitPatterns::aSignallingNaN))));
- EXPECT_EQ(BitPatterns::aNegativeSignallingNaN,
- valueAsBits(__llvm_libc::logb(
- valueFromBits(BitPatterns::aNegativeSignallingNaN))));
-
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::logb(valueFromBits(BitPatterns::inf))));
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::logb(valueFromBits(BitPatterns::negInf))));
-
- EXPECT_EQ(BitPatterns::negInf,
- valueAsBits(__llvm_libc::logb(valueFromBits(BitPatterns::zero))));
- EXPECT_EQ(BitPatterns::negInf, valueAsBits(__llvm_libc::logb(
- valueFromBits(BitPatterns::negZero))));
-}
-
-TEST(LlvmLibcLogbTest, PowersOfTwo) {
- EXPECT_EQ(valueAsBits(0.0), valueAsBits(__llvm_libc::logb(1.0)));
- EXPECT_EQ(valueAsBits(0.0), valueAsBits(__llvm_libc::logb(-1.0)));
-
- EXPECT_EQ(valueAsBits(1.0), valueAsBits(__llvm_libc::logb(2.0)));
- EXPECT_EQ(valueAsBits(1.0), valueAsBits(__llvm_libc::logb(-2.0)));
-
- EXPECT_EQ(valueAsBits(2.0), valueAsBits(__llvm_libc::logb(4.0)));
- EXPECT_EQ(valueAsBits(2.0), valueAsBits(__llvm_libc::logb(-4.0)));
+#include "LogbTest.h"
- EXPECT_EQ(valueAsBits(3.0), valueAsBits(__llvm_libc::logb(8.0)));
- EXPECT_EQ(valueAsBits(3.0), valueAsBits(__llvm_libc::logb(-8.0)));
-
- EXPECT_EQ(valueAsBits(4.0), valueAsBits(__llvm_libc::logb(16.0)));
- EXPECT_EQ(valueAsBits(4.0), valueAsBits(__llvm_libc::logb(-16.0)));
-
- EXPECT_EQ(valueAsBits(5.0), valueAsBits(__llvm_libc::logb(32.0)));
- EXPECT_EQ(valueAsBits(5.0), valueAsBits(__llvm_libc::logb(-32.0)));
-}
-
-TEST(LlvmLibcLogbTest, SomeIntegers) {
- EXPECT_EQ(valueAsBits(1.0), valueAsBits(__llvm_libc::logb(3.0)));
- EXPECT_EQ(valueAsBits(1.0), valueAsBits(__llvm_libc::logb(-3.0)));
-
- EXPECT_EQ(valueAsBits(2.0), valueAsBits(__llvm_libc::logb(7.0)));
- EXPECT_EQ(valueAsBits(2.0), valueAsBits(__llvm_libc::logb(-7.0)));
-
- EXPECT_EQ(valueAsBits(3.0), valueAsBits(__llvm_libc::logb(10.0)));
- EXPECT_EQ(valueAsBits(3.0), valueAsBits(__llvm_libc::logb(-10.0)));
-
- EXPECT_EQ(valueAsBits(4.0), valueAsBits(__llvm_libc::logb(31.0)));
- EXPECT_EQ(valueAsBits(4.0), valueAsBits(__llvm_libc::logb(-31.0)));
-
- EXPECT_EQ(valueAsBits(5.0), valueAsBits(__llvm_libc::logb(55.0)));
- EXPECT_EQ(valueAsBits(5.0), valueAsBits(__llvm_libc::logb(-55.0)));
-}
-
-TEST(LlvmLibcLogbTest, InDoubleRange) {
- using BitsType = Properties::BitsType;
- constexpr BitsType count = 10000000;
- constexpr BitsType step = UINT64_MAX / count;
- for (BitsType i = 0, v = 0; i <= count; ++i, v += step) {
- double x = valueFromBits(v);
- if (isnan(x) || isinf(x) || x == 0.0)
- continue;
+#include "src/math/logb.h"
- int exponent;
- __llvm_libc::fputil::frexp(x, exponent);
- ASSERT_TRUE(double(exponent) == __llvm_libc::logb(x) + 1.0);
- }
-}
+LIST_LOGB_TESTS(double, __llvm_libc::logb)
diff --git a/libc/test/src/math/logbf_test.cpp b/libc/test/src/math/logbf_test.cpp
index cc91cae7ec29..727eefffbb17 100644
--- a/libc/test/src/math/logbf_test.cpp
+++ b/libc/test/src/math/logbf_test.cpp
@@ -6,94 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "src/math/logbf.h"
-#include "utils/FPUtil/BitPatterns.h"
-#include "utils/FPUtil/FloatOperations.h"
-#include "utils/FPUtil/FloatProperties.h"
-#include "utils/FPUtil/ManipulationFunctions.h"
-#include "utils/UnitTest/Test.h"
-#include <math.h>
-
-using __llvm_libc::fputil::valueAsBits;
-using __llvm_libc::fputil::valueFromBits;
-
-using BitPatterns = __llvm_libc::fputil::BitPatterns<float>;
-using Properties = __llvm_libc::fputil::FloatProperties<float>;
-
-TEST(LlvmLibcLogbfTest, SpecialNumbers) {
- EXPECT_EQ(
- BitPatterns::aQuietNaN,
- valueAsBits(__llvm_libc::logbf(valueFromBits(BitPatterns::aQuietNaN))));
- EXPECT_EQ(BitPatterns::aNegativeQuietNaN,
- valueAsBits(__llvm_libc::logbf(
- valueFromBits(BitPatterns::aNegativeQuietNaN))));
-
- EXPECT_EQ(BitPatterns::aSignallingNaN,
- valueAsBits(__llvm_libc::logbf(
- valueFromBits(BitPatterns::aSignallingNaN))));
- EXPECT_EQ(BitPatterns::aNegativeSignallingNaN,
- valueAsBits(__llvm_libc::logbf(
- valueFromBits(BitPatterns::aNegativeSignallingNaN))));
-
- EXPECT_EQ(BitPatterns::inf,
- valueAsBits(__llvm_libc::logbf(valueFromBits(BitPatterns::inf))));
- EXPECT_EQ(BitPatterns::inf, valueAsBits(__llvm_libc::logbf(
- valueFromBits(BitPatterns::negInf))));
-
- EXPECT_EQ(BitPatterns::negInf,
- valueAsBits(__llvm_libc::logbf(valueFromBits(BitPatterns::zero))));
- EXPECT_EQ(BitPatterns::negInf, valueAsBits(__llvm_libc::logbf(
- valueFromBits(BitPatterns::negZero))));
-}
-
-TEST(LlvmLibcLogbfTest, PowersOfTwo) {
- EXPECT_EQ(valueAsBits(0.0f), valueAsBits(__llvm_libc::logbf(1.0f)));
- EXPECT_EQ(valueAsBits(0.0f), valueAsBits(__llvm_libc::logbf(-1.0f)));
-
- EXPECT_EQ(valueAsBits(1.0f), valueAsBits(__llvm_libc::logbf(2.0f)));
- EXPECT_EQ(valueAsBits(1.0f), valueAsBits(__llvm_libc::logbf(-2.0f)));
-
- EXPECT_EQ(valueAsBits(2.0f), valueAsBits(__llvm_libc::logbf(4.0f)));
- EXPECT_EQ(valueAsBits(2.0f), valueAsBits(__llvm_libc::logbf(-4.0f)));
+#include "LogbTest.h"
- EXPECT_EQ(valueAsBits(3.0f), valueAsBits(__llvm_libc::logbf(8.0f)));
- EXPECT_EQ(valueAsBits(3.0f), valueAsBits(__llvm_libc::logbf(-8.0f)));
-
- EXPECT_EQ(valueAsBits(4.0f), valueAsBits(__llvm_libc::logbf(16.0f)));
- EXPECT_EQ(valueAsBits(4.0f), valueAsBits(__llvm_libc::logbf(-16.0f)));
-
- EXPECT_EQ(valueAsBits(5.0f), valueAsBits(__llvm_libc::logbf(32.0f)));
- EXPECT_EQ(valueAsBits(5.0f), valueAsBits(__llvm_libc::logbf(-32.0f)));
-}
-
-TEST(LlvmLibcLogbTest, SomeIntegers) {
- EXPECT_EQ(valueAsBits(1.0f), valueAsBits(__llvm_libc::logbf(3.0f)));
- EXPECT_EQ(valueAsBits(1.0f), valueAsBits(__llvm_libc::logbf(-3.0f)));
-
- EXPECT_EQ(valueAsBits(2.0f), valueAsBits(__llvm_libc::logbf(7.0f)));
- EXPECT_EQ(valueAsBits(2.0f), valueAsBits(__llvm_libc::logbf(-7.0f)));
-
- EXPECT_EQ(valueAsBits(3.0f), valueAsBits(__llvm_libc::logbf(10.0f)));
- EXPECT_EQ(valueAsBits(3.0f), valueAsBits(__llvm_libc::logbf(-10.0f)));
-
- EXPECT_EQ(valueAsBits(4.0f), valueAsBits(__llvm_libc::logbf(31.0f)));
- EXPECT_EQ(valueAsBits(4.0f), valueAsBits(__llvm_libc::logbf(-31.0f)));
-
- EXPECT_EQ(valueAsBits(5.0f), valueAsBits(__llvm_libc::logbf(55.0f)));
- EXPECT_EQ(valueAsBits(5.0f), valueAsBits(__llvm_libc::logbf(-55.0f)));
-}
-
-TEST(LlvmLibcLogbfTest, InDoubleRange) {
- using BitsType = Properties::BitsType;
- constexpr BitsType count = 10000000;
- constexpr BitsType step = UINT32_MAX / count;
- for (BitsType i = 0, v = 0; i <= count; ++i, v += step) {
- float x = valueFromBits(v);
- if (isnan(x) || isinf(x) || x == 0.0)
- continue;
+#include "src/math/logbf.h"
- int exponent;
- __llvm_libc::fputil::frexp(x, exponent);
- ASSERT_TRUE(float(exponent) == __llvm_libc::logbf(x) + 1.0);
- }
-}
+LIST_LOGB_TESTS(float, __llvm_libc::logbf)
diff --git a/libc/test/src/math/logbl_test.cpp b/libc/test/src/math/logbl_test.cpp
index 41a724d95b32..1c7b0d4e66e8 100644
--- a/libc/test/src/math/logbl_test.cpp
+++ b/libc/test/src/math/logbl_test.cpp
@@ -6,74 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "src/math/logbl.h"
-#include "utils/FPUtil/FPBits.h"
-#include "utils/FPUtil/ManipulationFunctions.h"
-#include "utils/UnitTest/Test.h"
-#include <math.h>
-
-typedef long double LD;
-using FPBits = __llvm_libc::fputil::FPBits<long double>;
-
-TEST(LlvmLibclogblTest, SpecialNumbers) {
- EXPECT_TRUE(LD(FPBits::inf()) == __llvm_libc::logbl(LD(FPBits::inf())));
- EXPECT_TRUE(LD(FPBits::inf()) == __llvm_libc::logbl(LD(FPBits::negInf())));
-
- EXPECT_TRUE(LD(FPBits::negInf()) == __llvm_libc::logbl(LD(FPBits::zero())));
- EXPECT_TRUE(LD(FPBits::negInf()) ==
- __llvm_libc::logbl(LD(FPBits::negZero())));
-
- EXPECT_TRUE(FPBits(__llvm_libc::logbl(LD(FPBits::buildNaN(1)))).isNaN());
-}
-
-TEST(LlvmLibclogblTest, PowersOfTwo) {
- EXPECT_TRUE(0.0l == __llvm_libc::logbl(1.0l));
- EXPECT_TRUE(0.0l == __llvm_libc::logbl(-1.0l));
-
- EXPECT_TRUE(1.0l == __llvm_libc::logbl(2.0l));
- EXPECT_TRUE(1.0l == __llvm_libc::logbl(-2.0l));
-
- EXPECT_TRUE(2.0l == __llvm_libc::logbl(4.0l));
- EXPECT_TRUE(2.0l == __llvm_libc::logbl(-4.0l));
-
- EXPECT_TRUE(3.0l == __llvm_libc::logbl(8.0l));
- EXPECT_TRUE(3.0l == __llvm_libc::logbl(-8.0l));
+#include "LogbTest.h"
- EXPECT_TRUE(4.0l == __llvm_libc::logbl(16.0l));
- EXPECT_TRUE(4.0l == __llvm_libc::logbl(-16.0l));
-
- EXPECT_TRUE(5.0l == __llvm_libc::logbl(32.0l));
- EXPECT_TRUE(5.0l == __llvm_libc::logbl(-32.0l));
-}
-
-TEST(LlvmLibcLogbTest, SomeIntegers) {
- EXPECT_TRUE(1.0l == __llvm_libc::logbl(3.0l));
- EXPECT_TRUE(1.0l == __llvm_libc::logbl(-3.0l));
-
- EXPECT_TRUE(2.0l == __llvm_libc::logbl(7.0l));
- EXPECT_TRUE(2.0l == __llvm_libc::logbl(-7.0l));
-
- EXPECT_TRUE(3.0l == __llvm_libc::logbl(10.0l));
- EXPECT_TRUE(3.0l == __llvm_libc::logbl(-10.0l));
-
- EXPECT_TRUE(4.0l == __llvm_libc::logbl(31.0l));
- EXPECT_TRUE(4.0l == __llvm_libc::logbl(-31.0l));
-
- EXPECT_TRUE(5.0l == __llvm_libc::logbl(55.0l));
- EXPECT_TRUE(5.0l == __llvm_libc::logbl(-55.0l));
-}
-
-TEST(LlvmLibcLogblTest, LongDoubleRange) {
- using UIntType = FPBits::UIntType;
- constexpr UIntType count = 10000000;
- constexpr UIntType step = UIntType(-1) / count;
- for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
- long double x = LD(FPBits(v));
- if (isnan(x) || isinf(x) || x == 0.0l)
- continue;
+#include "src/math/logbl.h"
- int exponent;
- __llvm_libc::fputil::frexp(x, exponent);
- ASSERT_TRUE((long double)(exponent) == __llvm_libc::logbl(x) + 1.0l);
- }
-}
+LIST_LOGB_TESTS(long double, __llvm_libc::logbl)
diff --git a/libc/test/src/math/modf_test.cpp b/libc/test/src/math/modf_test.cpp
index 936cccad8a5f..ff89517506b4 100644
--- a/libc/test/src/math/modf_test.cpp
+++ b/libc/test/src/math/modf_test.cpp
@@ -6,127 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "src/math/modf.h"
-#include "utils/FPUtil/BasicOperations.h"
-#include "utils/FPUtil/BitPatterns.h"
-#include "utils/FPUtil/FloatOperations.h"
-#include "utils/FPUtil/FloatProperties.h"
-#include "utils/FPUtil/NearestIntegerOperations.h"
-#include "utils/UnitTest/Test.h"
-#include <math.h>
-
-using __llvm_libc::fputil::valueAsBits;
-using __llvm_libc::fputil::valueFromBits;
-
-using BitPatterns = __llvm_libc::fputil::BitPatterns<double>;
-using Properties = __llvm_libc::fputil::FloatProperties<double>;
-
-TEST(LlvmLibcModfTest, SpecialNumbers) {
- double integral;
-
- EXPECT_EQ(BitPatterns::aQuietNaN,
- valueAsBits(__llvm_libc::modf(valueFromBits(BitPatterns::aQuietNaN),
- &integral)));
- EXPECT_EQ(BitPatterns::aNegativeQuietNaN,
- valueAsBits(__llvm_libc::modf(
- valueFromBits(BitPatterns::aNegativeQuietNaN), &integral)));
-
- EXPECT_EQ(BitPatterns::aSignallingNaN,
- valueAsBits(__llvm_libc::modf(
- valueFromBits(BitPatterns::aSignallingNaN), &integral)));
- EXPECT_EQ(
- BitPatterns::aNegativeSignallingNaN,
- valueAsBits(__llvm_libc::modf(
- valueFromBits(BitPatterns::aNegativeSignallingNaN), &integral)));
-
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(
- __llvm_libc::modf(valueFromBits(BitPatterns::inf), &integral)));
- EXPECT_EQ(valueAsBits(integral), BitPatterns::inf);
-
- EXPECT_EQ(BitPatterns::negZero,
- valueAsBits(__llvm_libc::modf(valueFromBits(BitPatterns::negInf),
- &integral)));
- EXPECT_EQ(valueAsBits(integral), BitPatterns::negInf);
-
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::modf(valueFromBits(BitPatterns::zero),
- &integral)));
- EXPECT_EQ(valueAsBits(integral), BitPatterns::zero);
-
- EXPECT_EQ(BitPatterns::negZero,
- valueAsBits(__llvm_libc::modf(valueFromBits(BitPatterns::negZero),
- &integral)));
- EXPECT_EQ(valueAsBits(integral), BitPatterns::negZero);
-}
-
-TEST(LlvmLibcModfTest, Integers) {
- double integral;
-
- EXPECT_EQ(BitPatterns::zero, valueAsBits(__llvm_libc::modf(1.0, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(1.0));
-
- EXPECT_EQ(BitPatterns::negZero,
- valueAsBits(__llvm_libc::modf(-1.0, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(-1.0));
+#include "ModfTest.h"
- EXPECT_EQ(BitPatterns::zero, valueAsBits(__llvm_libc::modf(10.0, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(10.0));
-
- EXPECT_EQ(BitPatterns::negZero,
- valueAsBits(__llvm_libc::modf(-10.0, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(-10.0));
-
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::modf(12345.0, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(12345.0));
-
- EXPECT_EQ(BitPatterns::negZero,
- valueAsBits(__llvm_libc::modf(-12345.0, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(-12345.0));
-}
-
-TEST(LlvmLibcModfTest, Fractions) {
- double integral;
-
- EXPECT_EQ(valueAsBits(0.5), valueAsBits(__llvm_libc::modf(1.5, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(1.0));
-
- EXPECT_EQ(valueAsBits(-0.5), valueAsBits(__llvm_libc::modf(-1.5, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(-1.0));
-
- EXPECT_EQ(valueAsBits(0.75),
- valueAsBits(__llvm_libc::modf(10.75, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(10.0));
-
- EXPECT_EQ(valueAsBits(-0.75),
- valueAsBits(__llvm_libc::modf(-10.75, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(-10.0));
-
- EXPECT_EQ(valueAsBits(0.125),
- valueAsBits(__llvm_libc::modf(100.125, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(100.0));
-
- EXPECT_EQ(valueAsBits(-0.125),
- valueAsBits(__llvm_libc::modf(-100.125, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(-100.0));
-}
-
-TEST(LlvmLibcModfTest, InDoubleRange) {
- using BitsType = Properties::BitsType;
- constexpr BitsType count = 10000000;
- constexpr BitsType step = UINT64_MAX / count;
- for (BitsType i = 0, v = 0; i <= count; ++i, v += step) {
- double x = valueFromBits(v);
- if (isnan(x) || isinf(x) || x == 0.0) {
- // These conditions have been tested in other tests.
- continue;
- }
+#include "src/math/modf.h"
- double integral;
- double frac = __llvm_libc::modf(x, &integral);
- ASSERT_TRUE(__llvm_libc::fputil::abs(frac) < 1.0);
- ASSERT_TRUE(__llvm_libc::fputil::trunc(x) == integral);
- ASSERT_TRUE(integral + frac == x);
- }
-}
+LIST_MODF_TESTS(double, __llvm_libc::modf)
diff --git a/libc/test/src/math/modff_test.cpp b/libc/test/src/math/modff_test.cpp
index ec91ef3d018b..440304ab95ac 100644
--- a/libc/test/src/math/modff_test.cpp
+++ b/libc/test/src/math/modff_test.cpp
@@ -6,131 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "src/math/modff.h"
-#include "utils/FPUtil/BasicOperations.h"
-#include "utils/FPUtil/BitPatterns.h"
-#include "utils/FPUtil/FloatOperations.h"
-#include "utils/FPUtil/FloatProperties.h"
-#include "utils/FPUtil/NearestIntegerOperations.h"
-#include "utils/UnitTest/Test.h"
-#include <math.h>
-
-using __llvm_libc::fputil::valueAsBits;
-using __llvm_libc::fputil::valueFromBits;
-
-using BitPatterns = __llvm_libc::fputil::BitPatterns<float>;
-using Properties = __llvm_libc::fputil::FloatProperties<float>;
-
-TEST(LlvmLibcModffTest, SpecialNumbers) {
- float integral;
-
- EXPECT_EQ(BitPatterns::aQuietNaN,
- valueAsBits(__llvm_libc::modff(
- valueFromBits(BitPatterns::aQuietNaN), &integral)));
- EXPECT_EQ(BitPatterns::aNegativeQuietNaN,
- valueAsBits(__llvm_libc::modff(
- valueFromBits(BitPatterns::aNegativeQuietNaN), &integral)));
-
- EXPECT_EQ(BitPatterns::aSignallingNaN,
- valueAsBits(__llvm_libc::modff(
- valueFromBits(BitPatterns::aSignallingNaN), &integral)));
- EXPECT_EQ(
- BitPatterns::aNegativeSignallingNaN,
- valueAsBits(__llvm_libc::modff(
- valueFromBits(BitPatterns::aNegativeSignallingNaN), &integral)));
-
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::modff(valueFromBits(BitPatterns::inf),
- &integral)));
- EXPECT_EQ(valueAsBits(integral), BitPatterns::inf);
-
- EXPECT_EQ(BitPatterns::negZero,
- valueAsBits(__llvm_libc::modff(valueFromBits(BitPatterns::negInf),
- &integral)));
- EXPECT_EQ(valueAsBits(integral), BitPatterns::negInf);
-
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::modff(valueFromBits(BitPatterns::zero),
- &integral)));
- EXPECT_EQ(valueAsBits(integral), BitPatterns::zero);
-
- EXPECT_EQ(BitPatterns::negZero,
- valueAsBits(__llvm_libc::modff(valueFromBits(BitPatterns::negZero),
- &integral)));
- EXPECT_EQ(valueAsBits(integral), BitPatterns::negZero);
-}
-
-TEST(LlvmLibcModffTest, Integers) {
- float integral;
-
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::modff(1.0f, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(1.0f));
-
- EXPECT_EQ(BitPatterns::negZero,
- valueAsBits(__llvm_libc::modff(-1.0f, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(-1.0f));
+#include "ModfTest.h"
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::modff(10.0f, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(10.0f));
-
- EXPECT_EQ(BitPatterns::negZero,
- valueAsBits(__llvm_libc::modff(-10.0f, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(-10.0f));
-
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::modff(12345.0f, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(12345.0f));
-
- EXPECT_EQ(BitPatterns::negZero,
- valueAsBits(__llvm_libc::modff(-12345.0f, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(-12345.0f));
-}
-
-TEST(LlvmLibcModffTest, Fractions) {
- float integral;
-
- EXPECT_EQ(valueAsBits(0.5f),
- valueAsBits(__llvm_libc::modff(1.5f, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(1.0f));
-
- EXPECT_EQ(valueAsBits(-0.5f),
- valueAsBits(__llvm_libc::modff(-1.5f, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(-1.0f));
-
- EXPECT_EQ(valueAsBits(0.75f),
- valueAsBits(__llvm_libc::modff(10.75f, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(10.0f));
-
- EXPECT_EQ(valueAsBits(-0.75f),
- valueAsBits(__llvm_libc::modff(-10.75f, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(-10.0f));
-
- EXPECT_EQ(valueAsBits(0.125f),
- valueAsBits(__llvm_libc::modff(100.125f, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(100.0f));
-
- EXPECT_EQ(valueAsBits(-0.125f),
- valueAsBits(__llvm_libc::modff(-100.125f, &integral)));
- EXPECT_EQ(valueAsBits(integral), valueAsBits(-100.0f));
-}
-
-TEST(LlvmLibcModffTest, InDoubleRange) {
- using BitsType = Properties::BitsType;
- constexpr BitsType count = 10000000;
- constexpr BitsType step = UINT32_MAX / count;
- for (BitsType i = 0, v = 0; i <= count; ++i, v += step) {
- float x = valueFromBits(v);
- if (isnan(x) || isinf(x) || x == 0.0f) {
- // These conditions have been tested in other tests.
- continue;
- }
+#include "src/math/modff.h"
- float integral;
- float frac = __llvm_libc::modff(x, &integral);
- ASSERT_TRUE(__llvm_libc::fputil::abs(frac) < 1.0f);
- ASSERT_TRUE(__llvm_libc::fputil::trunc(x) == integral);
- ASSERT_TRUE(integral + frac == x);
- }
-}
+LIST_MODF_TESTS(float, __llvm_libc::modff)
diff --git a/libc/test/src/math/modfl_test.cpp b/libc/test/src/math/modfl_test.cpp
index fae4690b65cc..c98678b3e924 100644
--- a/libc/test/src/math/modfl_test.cpp
+++ b/libc/test/src/math/modfl_test.cpp
@@ -6,97 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "src/math/modfl.h"
-#include "utils/FPUtil/BasicOperations.h"
-#include "utils/FPUtil/FPBits.h"
-#include "utils/FPUtil/NearestIntegerOperations.h"
-#include "utils/UnitTest/Test.h"
-#include <math.h>
-
-typedef long double LD;
-using FPBits = __llvm_libc::fputil::FPBits<long double>;
-
-TEST(LlvmLibcmodflTest, SpecialNumbers) {
- long double integral;
-
- EXPECT_TRUE(LD(FPBits::zero()) ==
- __llvm_libc::modfl(LD(FPBits::inf()), &integral));
- EXPECT_TRUE(LD(FPBits::inf()) == integral);
-
- EXPECT_TRUE(LD(FPBits::negZero()) ==
- __llvm_libc::modfl(LD(FPBits::negInf()), &integral));
- EXPECT_TRUE(LD(FPBits::negInf()) == integral);
-
- EXPECT_TRUE(LD(FPBits::zero()) ==
- __llvm_libc::modfl(LD(FPBits::zero()), &integral));
- EXPECT_TRUE(integral == 0.0l);
-
- EXPECT_TRUE(LD(FPBits::negZero()) ==
- __llvm_libc::modfl(LD(FPBits::negZero()), &integral));
- EXPECT_TRUE(integral == 0.0l);
-
- EXPECT_TRUE(
- FPBits(__llvm_libc::modfl(LD(FPBits::buildNaN(1)), &integral)).isNaN());
-}
-
-TEST(LlvmLibcmodflTest, Integers) {
- long double integral;
-
- EXPECT_TRUE(LD(FPBits::zero()) == __llvm_libc::modfl(1.0l, &integral));
- EXPECT_TRUE(integral == 1.0l);
-
- EXPECT_TRUE(LD(FPBits::negZero()) == __llvm_libc::modfl(-1.0l, &integral));
- EXPECT_TRUE(integral == -1.0l);
-
- EXPECT_TRUE(LD(FPBits::zero()) == __llvm_libc::modfl(10.0l, &integral));
- EXPECT_TRUE(integral == 10.0l);
+#include "ModfTest.h"
- EXPECT_TRUE(LD(FPBits::negZero()) == __llvm_libc::modfl(-10.0l, &integral));
- EXPECT_TRUE(integral == -10.0l);
-
- EXPECT_TRUE(LD(FPBits::zero()) == __llvm_libc::modfl(12345.0l, &integral));
- EXPECT_TRUE(integral == 12345.0l);
-
- EXPECT_TRUE(LD(FPBits::negZero()) ==
- __llvm_libc::modfl(-12345.0l, &integral));
- EXPECT_TRUE(integral == -12345.0l);
-}
-
-TEST(LlvmLibcModfTest, Fractions) {
- long double integral;
-
- EXPECT_TRUE(0.5l == __llvm_libc::modfl(1.5l, &integral));
- EXPECT_TRUE(integral == 1.0l);
-
- EXPECT_TRUE(-0.5l == __llvm_libc::modfl(-1.5l, &integral));
- EXPECT_TRUE(integral == -1.0l);
-
- EXPECT_TRUE(0.75l == __llvm_libc::modfl(10.75l, &integral));
- EXPECT_TRUE(integral == 10.0l);
-
- EXPECT_TRUE(-0.75l == __llvm_libc::modfl(-10.75l, &integral));
- EXPECT_TRUE(integral == -10.0l);
-
- EXPECT_TRUE(0.125l == __llvm_libc::modfl(100.125l, &integral));
- EXPECT_TRUE(integral == 100.0l);
-
- EXPECT_TRUE(-0.125l == __llvm_libc::modfl(-100.125l, &integral));
- EXPECT_TRUE(integral == -100.0l);
-}
-
-TEST(LlvmLibcModflTest, LongDoubleRange) {
- using UIntType = FPBits::UIntType;
- constexpr UIntType count = 10000000;
- constexpr UIntType step = UIntType(-1) / count;
- for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
- long double x = LD(FPBits(v));
- if (isnan(x) || isinf(x) || x == 0.0l)
- continue;
+#include "src/math/modfl.h"
- long double integral;
- long double frac = __llvm_libc::modfl(x, &integral);
- ASSERT_TRUE(__llvm_libc::fputil::abs(frac) < 1.0l);
- ASSERT_TRUE(__llvm_libc::fputil::trunc(x) == integral);
- ASSERT_TRUE(integral + frac == x);
- }
-}
+LIST_MODF_TESTS(long double, __llvm_libc::modfl)
diff --git a/libc/test/src/math/sdcomp26094.h b/libc/test/src/math/sdcomp26094.h
index 7e477534c98b..9c7d464e5d2b 100644
--- a/libc/test/src/math/sdcomp26094.h
+++ b/libc/test/src/math/sdcomp26094.h
@@ -10,17 +10,16 @@
#define LLVM_LIBC_TEST_SRC_MATH_SDCOMP26094_H
#include "utils/CPP/Array.h"
-#include "utils/FPUtil/BitPatterns.h"
+
+#include <stdint.h>
namespace __llvm_libc {
namespace testing {
-static constexpr __llvm_libc::cpp::Array<fputil::BitPatterns<float>::BitsType,
- 10>
- sdcomp26094Values{
- 0x46427f1b, 0x4647e568, 0x46428bac, 0x4647f1f9, 0x4647fe8a,
- 0x45d8d7f1, 0x45d371a4, 0x45ce0b57, 0x45d35882, 0x45cdf235,
- };
+static constexpr __llvm_libc::cpp::Array<uint32_t, 10> sdcomp26094Values{
+ 0x46427f1b, 0x4647e568, 0x46428bac, 0x4647f1f9, 0x4647fe8a,
+ 0x45d8d7f1, 0x45d371a4, 0x45ce0b57, 0x45d35882, 0x45cdf235,
+};
} // namespace testing
} // namespace __llvm_libc
diff --git a/libc/test/src/math/sin_test.cpp b/libc/test/src/math/sin_test.cpp
index dd3fcb58c969..be230a15ed54 100644
--- a/libc/test/src/math/sin_test.cpp
+++ b/libc/test/src/math/sin_test.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "src/math/sin.h"
+#include "utils/FPUtil/FPBits.h"
#include "utils/FPUtil/TestHelpers.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
#include "utils/UnitTest/Test.h"
diff --git a/libc/test/src/math/sincosf_test.cpp b/libc/test/src/math/sincosf_test.cpp
index 97b983720335..c8172e9da9de 100644
--- a/libc/test/src/math/sincosf_test.cpp
+++ b/libc/test/src/math/sincosf_test.cpp
@@ -9,10 +9,8 @@
#include "src/math/sincosf.h"
#include "test/src/math/sdcomp26094.h"
#include "utils/CPP/Array.h"
-#include "utils/FPUtil/BitPatterns.h"
-#include "utils/FPUtil/ClassificationFunctions.h"
-#include "utils/FPUtil/FloatOperations.h"
-#include "utils/FPUtil/FloatProperties.h"
+#include "utils/FPUtil/FPBits.h"
+#include "utils/FPUtil/TestHelpers.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
#include "utils/UnitTest/Test.h"
#include <math.h>
@@ -20,63 +18,42 @@
#include <errno.h>
#include <stdint.h>
-using __llvm_libc::fputil::isNegativeQuietNaN;
-using __llvm_libc::fputil::isQuietNaN;
-using __llvm_libc::fputil::valueAsBits;
-using __llvm_libc::fputil::valueFromBits;
-
-using BitPatterns = __llvm_libc::fputil::BitPatterns<float>;
-
using __llvm_libc::testing::sdcomp26094Values;
+using FPBits = __llvm_libc::fputil::FPBits<float>;
namespace mpfr = __llvm_libc::testing::mpfr;
+DECLARE_SPECIAL_CONSTANTS(float)
+
TEST(LlvmLibcSinCosfTest, SpecialNumbers) {
errno = 0;
float sin, cos;
- __llvm_libc::sincosf(valueFromBits(BitPatterns::aQuietNaN), &sin, &cos);
- EXPECT_TRUE(isQuietNaN(cos));
- EXPECT_TRUE(isQuietNaN(sin));
- EXPECT_EQ(errno, 0);
-
- __llvm_libc::sincosf(valueFromBits(BitPatterns::aNegativeQuietNaN), &sin,
- &cos);
- EXPECT_TRUE(isNegativeQuietNaN(cos));
- EXPECT_TRUE(isNegativeQuietNaN(sin));
- EXPECT_EQ(errno, 0);
-
- __llvm_libc::sincosf(valueFromBits(BitPatterns::aSignallingNaN), &sin, &cos);
- EXPECT_TRUE(isQuietNaN(cos));
- EXPECT_TRUE(isQuietNaN(sin));
- EXPECT_EQ(errno, 0);
-
- __llvm_libc::sincosf(valueFromBits(BitPatterns::aNegativeSignallingNaN), &sin,
- &cos);
- EXPECT_TRUE(isNegativeQuietNaN(cos));
- EXPECT_TRUE(isNegativeQuietNaN(sin));
+ __llvm_libc::sincosf(aNaN, &sin, &cos);
+ EXPECT_FP_EQ(aNaN, cos);
+ EXPECT_FP_EQ(aNaN, sin);
EXPECT_EQ(errno, 0);
- __llvm_libc::sincosf(valueFromBits(BitPatterns::zero), &sin, &cos);
- EXPECT_EQ(BitPatterns::one, valueAsBits(cos));
- EXPECT_EQ(BitPatterns::zero, valueAsBits(sin));
+ __llvm_libc::sincosf(0.0f, &sin, &cos);
+ EXPECT_FP_EQ(1.0f, cos);
+ EXPECT_FP_EQ(0.0f, sin);
EXPECT_EQ(errno, 0);
- __llvm_libc::sincosf(valueFromBits(BitPatterns::negZero), &sin, &cos);
- EXPECT_EQ(BitPatterns::one, valueAsBits(cos));
- EXPECT_EQ(BitPatterns::negZero, valueAsBits(sin));
+ __llvm_libc::sincosf(-0.0f, &sin, &cos);
+ EXPECT_FP_EQ(1.0f, cos);
+ EXPECT_FP_EQ(-0.0f, sin);
EXPECT_EQ(errno, 0);
errno = 0;
- __llvm_libc::sincosf(valueFromBits(BitPatterns::inf), &sin, &cos);
- EXPECT_TRUE(isQuietNaN(cos));
- EXPECT_TRUE(isQuietNaN(sin));
+ __llvm_libc::sincosf(inf, &sin, &cos);
+ EXPECT_FP_EQ(aNaN, cos);
+ EXPECT_FP_EQ(aNaN, sin);
EXPECT_EQ(errno, EDOM);
errno = 0;
- __llvm_libc::sincosf(valueFromBits(BitPatterns::negInf), &sin, &cos);
- EXPECT_TRUE(isQuietNaN(cos));
- EXPECT_TRUE(isQuietNaN(sin));
+ __llvm_libc::sincosf(negInf, &sin, &cos);
+ EXPECT_FP_EQ(aNaN, cos);
+ EXPECT_FP_EQ(aNaN, sin);
EXPECT_EQ(errno, EDOM);
}
@@ -84,7 +61,7 @@ TEST(LlvmLibcSinCosfTest, InFloatRange) {
constexpr uint32_t count = 1000000;
constexpr uint32_t step = UINT32_MAX / count;
for (uint32_t i = 0, v = 0; i <= count; ++i, v += step) {
- float x = valueFromBits(v);
+ float x = float(FPBits((v)));
if (isnan(x) || isinf(x))
continue;
@@ -98,28 +75,28 @@ TEST(LlvmLibcSinCosfTest, InFloatRange) {
// For small values, cos(x) is 1 and sin(x) is x.
TEST(LlvmLibcSinCosfTest, SmallValues) {
uint32_t bits = 0x17800000;
- float x = valueFromBits(bits);
+ float x = float(FPBits((bits)));
float result_cos, result_sin;
__llvm_libc::sincosf(x, &result_sin, &result_cos);
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));
+ EXPECT_FP_EQ(1.0f, result_cos);
+ EXPECT_FP_EQ(x, result_sin);
bits = 0x00400000;
- x = valueFromBits(bits);
+ x = float(FPBits((bits)));
__llvm_libc::sincosf(x, &result_sin, &result_cos);
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));
+ EXPECT_FP_EQ(1.0f, result_cos);
+ EXPECT_FP_EQ(x, result_sin);
}
// SDCOMP-26094: check sinf in the cases for which the range reducer
// returns values furthest beyond its nominal upper bound of pi/4.
TEST(LlvmLibcSinCosfTest, SDCOMP_26094) {
for (uint32_t v : sdcomp26094Values) {
- float x = valueFromBits(v);
+ float x = float(FPBits((v)));
float sin, cos;
__llvm_libc::sincosf(x, &sin, &cos);
EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, cos, 1.0);
diff --git a/libc/test/src/math/sinf_test.cpp b/libc/test/src/math/sinf_test.cpp
index 67175f813233..d2364ae0285a 100644
--- a/libc/test/src/math/sinf_test.cpp
+++ b/libc/test/src/math/sinf_test.cpp
@@ -9,10 +9,8 @@
#include "src/math/sinf.h"
#include "test/src/math/sdcomp26094.h"
#include "utils/CPP/Array.h"
-#include "utils/FPUtil/BitPatterns.h"
-#include "utils/FPUtil/ClassificationFunctions.h"
-#include "utils/FPUtil/FloatOperations.h"
-#include "utils/FPUtil/FloatProperties.h"
+#include "utils/FPUtil/FPBits.h"
+#include "utils/FPUtil/TestHelpers.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
#include "utils/UnitTest/Test.h"
#include <math.h>
@@ -20,51 +18,31 @@
#include <errno.h>
#include <stdint.h>
-using __llvm_libc::fputil::isNegativeQuietNaN;
-using __llvm_libc::fputil::isQuietNaN;
-using __llvm_libc::fputil::valueAsBits;
-using __llvm_libc::fputil::valueFromBits;
-
-using BitPatterns = __llvm_libc::fputil::BitPatterns<float>;
-
using __llvm_libc::testing::sdcomp26094Values;
+using FPBits = __llvm_libc::fputil::FPBits<float>;
namespace mpfr = __llvm_libc::testing::mpfr;
+DECLARE_SPECIAL_CONSTANTS(float)
+
TEST(LlvmLibcSinfTest, SpecialNumbers) {
errno = 0;
- EXPECT_TRUE(
- isQuietNaN(__llvm_libc::sinf(valueFromBits(BitPatterns::aQuietNaN))));
- EXPECT_EQ(errno, 0);
-
- EXPECT_TRUE(isNegativeQuietNaN(
- __llvm_libc::sinf(valueFromBits(BitPatterns::aNegativeQuietNaN))));
- EXPECT_EQ(errno, 0);
-
- EXPECT_TRUE(isQuietNaN(
- __llvm_libc::sinf(valueFromBits(BitPatterns::aSignallingNaN))));
- EXPECT_EQ(errno, 0);
-
- EXPECT_TRUE(isNegativeQuietNaN(
- __llvm_libc::sinf(valueFromBits(BitPatterns::aNegativeSignallingNaN))));
+ EXPECT_FP_EQ(aNaN, __llvm_libc::sinf(aNaN));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::zero,
- valueAsBits(__llvm_libc::sinf(valueFromBits(BitPatterns::zero))));
+ EXPECT_FP_EQ(0.0f, __llvm_libc::sinf(0.0f));
EXPECT_EQ(errno, 0);
- EXPECT_EQ(BitPatterns::negZero, valueAsBits(__llvm_libc::sinf(
- valueFromBits(BitPatterns::negZero))));
+ EXPECT_FP_EQ(-0.0f, __llvm_libc::sinf(-0.0f));
EXPECT_EQ(errno, 0);
errno = 0;
- EXPECT_TRUE(isQuietNaN(__llvm_libc::sinf(valueFromBits(BitPatterns::inf))));
+ EXPECT_FP_EQ(aNaN, __llvm_libc::sinf(inf));
EXPECT_EQ(errno, EDOM);
errno = 0;
- EXPECT_TRUE(
- isQuietNaN(__llvm_libc::sinf(valueFromBits(BitPatterns::negInf))));
+ EXPECT_FP_EQ(aNaN, __llvm_libc::sinf(negInf));
EXPECT_EQ(errno, EDOM);
}
@@ -72,7 +50,7 @@ TEST(LlvmLibcSinfTest, InFloatRange) {
constexpr uint32_t count = 1000000;
constexpr uint32_t step = UINT32_MAX / count;
for (uint32_t i = 0, v = 0; i <= count; ++i, v += step) {
- float x = valueFromBits(v);
+ float x = float(FPBits(v));
if (isnan(x) || isinf(x))
continue;
ASSERT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x), 1.0);
@@ -80,30 +58,28 @@ TEST(LlvmLibcSinfTest, InFloatRange) {
}
TEST(LlvmLibcSinfTest, SpecificBitPatterns) {
- float x = valueFromBits(0xc70d39a1);
+ float x = float(FPBits(uint32_t(0xc70d39a1)));
EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x), 1.0);
}
// For small values, sin(x) is x.
TEST(LlvmLibcSinfTest, SmallValues) {
- uint32_t bits = 0x17800000;
- float x = valueFromBits(bits);
+ float x = float(FPBits(uint32_t(0x17800000)));
float result = __llvm_libc::sinf(x);
EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result, 1.0);
- EXPECT_EQ(bits, valueAsBits(result));
+ EXPECT_FP_EQ(x, result);
- bits = 0x00400000;
- x = valueFromBits(bits);
+ x = float(FPBits(uint32_t(0x00400000)));
result = __llvm_libc::sinf(x);
EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result, 1.0);
- EXPECT_EQ(bits, valueAsBits(result));
+ EXPECT_FP_EQ(x, result);
}
// SDCOMP-26094: check sinf in the cases for which the range reducer
// returns values furthest beyond its nominal upper bound of pi/4.
TEST(LlvmLibcSinfTest, SDCOMP_26094) {
for (uint32_t v : sdcomp26094Values) {
- float x = valueFromBits(v);
+ float x = float(FPBits((v)));
EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x), 1.0);
}
}
diff --git a/libc/utils/FPUtil/BitPatterns.h b/libc/utils/FPUtil/BitPatterns.h
deleted file mode 100644
index a26d403e1bf6..000000000000
--- a/libc/utils/FPUtil/BitPatterns.h
+++ /dev/null
@@ -1,69 +0,0 @@
-//===-- Bit patterns of common floating point numbers -----------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_UTILS_FPUTIL_BIT_PATTERNS_H
-#define LLVM_LIBC_UTILS_FPUTIL_BIT_PATTERNS_H
-
-#include "FloatProperties.h"
-
-#include <float.h>
-
-static_assert(
- FLT_RADIX == 2,
- "LLVM libc only supports radix 2 IEEE 754 floating point formats.");
-
-namespace __llvm_libc {
-namespace fputil {
-
-template <typename T> struct BitPatterns {};
-
-template <> struct BitPatterns<float> {
- using BitsType = FloatProperties<float>::BitsType;
-
- static constexpr BitsType inf = 0x7f800000U;
- static constexpr BitsType negInf = 0xff800000U;
-
- static constexpr BitsType zero = 0x0;
- static constexpr BitsType negZero = 0x80000000U;
-
- static constexpr BitsType one = 0x3f800000U;
- static constexpr BitsType negOne = 0xbf800000U;
-
- // Examples of quiet NAN.
- static constexpr BitsType aQuietNaN = 0x7fc00000U;
- static constexpr BitsType aNegativeQuietNaN = 0xffc00000U;
-
- // Examples of signalling NAN.
- static constexpr BitsType aSignallingNaN = 0x7f800001U;
- static constexpr BitsType aNegativeSignallingNaN = 0xff800001U;
-};
-
-template <> struct BitPatterns<double> {
- using BitsType = FloatProperties<double>::BitsType;
-
- static constexpr BitsType inf = 0x7ff0000000000000ULL;
- static constexpr BitsType negInf = 0xfff0000000000000ULL;
-
- static constexpr BitsType zero = 0x0ULL;
- static constexpr BitsType negZero = 0x8000000000000000ULL;
-
- static constexpr BitsType one = 0x3FF0000000000000ULL;
-
- // Examples of quiet NAN.
- static constexpr BitsType aQuietNaN = 0x7ff8000000000000ULL;
- static constexpr BitsType aNegativeQuietNaN = 0xfff8000000000000ULL;
-
- // Examples of signalling NAN.
- static constexpr BitsType aSignallingNaN = 0x7ff0000000000001ULL;
- static constexpr BitsType aNegativeSignallingNaN = 0xfff0000000000001ULL;
-};
-
-} // namespace fputil
-} // namespace __llvm_libc
-
-#endif // LLVM_LIBC_UTILS_FPUTIL_BIT_PATTERNS_H
diff --git a/libc/utils/FPUtil/CMakeLists.txt b/libc/utils/FPUtil/CMakeLists.txt
index b1cbb3a14ea0..7b6daff72179 100644
--- a/libc/utils/FPUtil/CMakeLists.txt
+++ b/libc/utils/FPUtil/CMakeLists.txt
@@ -16,11 +16,8 @@ add_header_library(
${LONG_DOUBLE_HDR}
${FENV_IMPL}
BasicOperations.h
- BitPatterns.h
- ClassificationFunctions.h
DivisionAndRemainderOperations.h
FEnv.h
- FloatOperations.h
FloatProperties.h
FPBits.h
BasicOperations.h
diff --git a/libc/utils/FPUtil/ClassificationFunctions.h b/libc/utils/FPUtil/ClassificationFunctions.h
deleted file mode 100644
index a80e349291cd..000000000000
--- a/libc/utils/FPUtil/ClassificationFunctions.h
+++ /dev/null
@@ -1,90 +0,0 @@
-//===-- Floating point classification functions -----------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_UTILS_FPUTIL_CLASSIFICATION_FUNCTIONS_H
-#define LLVM_LIBC_UTILS_FPUTIL_CLASSIFICATION_FUNCTIONS_H
-
-#include "BitPatterns.h"
-#include "FloatOperations.h"
-#include "FloatProperties.h"
-
-#include "utils/CPP/TypeTraits.h"
-
-namespace __llvm_libc {
-namespace fputil {
-
-template <typename BitsType> static inline bool bitsAreInf(BitsType bits) {
- using FPType = typename FloatType<BitsType>::Type;
- return ((bits & BitPatterns<FPType>::inf) == BitPatterns<FPType>::inf) &&
- ((bits & FloatProperties<FPType>::mantissaMask) == 0);
-}
-
-// Return true if x is infinity (positive or negative.)
-template <typename T,
- cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
-static inline bool isInf(T x) {
- return bitsAreInf(valueAsBits(x));
-}
-
-template <typename BitsType> static inline bool bitsAreNaN(BitsType bits) {
- using FPType = typename FloatType<BitsType>::Type;
- return ((bits & BitPatterns<FPType>::inf) == BitPatterns<FPType>::inf) &&
- ((bits & FloatProperties<FPType>::mantissaMask) != 0);
-}
-
-// Return true if x is a NAN (quiet or signalling.)
-template <typename T,
- cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
-static inline bool isNaN(T x) {
- return bitsAreNaN(valueAsBits(x));
-}
-
-template <typename BitsType> static inline bool bitsAreInfOrNaN(BitsType bits) {
- using FPType = typename FloatType<BitsType>::Type;
- return (bits & BitPatterns<FPType>::inf) == BitPatterns<FPType>::inf;
-}
-
-template <typename BitsType> static inline bool bitsAreZero(BitsType bits) {
- using FPType = typename FloatType<BitsType>::Type;
- return (bits == BitPatterns<FPType>::zero) ||
- (bits == BitPatterns<FPType>::negZero);
-}
-
-// Return true if x is any kind of NaN or infinity.
-template <typename T,
- cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
-static inline bool isInfOrNaN(T x) {
- return bitsAreInfOrNaN(valueAsBits(x));
-}
-
-// Return true if x is a quiet NAN.
-template <typename T,
- cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
-static inline bool isQuietNaN(T x) {
- using Properties = FloatProperties<T>;
- using BitsType = typename FloatProperties<T>::BitsType;
- BitsType bits = valueAsBits(x);
- return ((bits & BitPatterns<T>::inf) == BitPatterns<T>::inf) &&
- ((bits & Properties::quietNaNMask) != 0);
-}
-
-// Return true if x is a quiet NAN with sign bit set.
-template <typename T,
- cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
-static inline bool isNegativeQuietNaN(T x) {
- using Properties = FloatProperties<T>;
- using BitsType = typename FloatProperties<T>::BitsType;
- BitsType bits = valueAsBits(x);
- return ((bits & BitPatterns<T>::negInf) == BitPatterns<T>::negInf) &&
- ((bits & Properties::quietNaNMask) != 0);
-}
-
-} // namespace fputil
-} // namespace __llvm_libc
-
-#endif // LLVM_LIBC_UTILS_FPUTIL_CLASSIFICATION_FUNCTIONS_H
diff --git a/libc/utils/FPUtil/FloatOperations.h b/libc/utils/FPUtil/FloatOperations.h
deleted file mode 100644
index ffd138d6cc9b..000000000000
--- a/libc/utils/FPUtil/FloatOperations.h
+++ /dev/null
@@ -1,63 +0,0 @@
-//===-- Common operations on floating point numbers -------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_UTILS_FPUTIL_FLOAT_OPERATIONS_H
-#define LLVM_LIBC_UTILS_FPUTIL_FLOAT_OPERATIONS_H
-
-#include "BitPatterns.h"
-#include "FloatProperties.h"
-
-#include "utils/CPP/TypeTraits.h"
-
-namespace __llvm_libc {
-namespace fputil {
-
-// Return the bits of a float value.
-template <typename T,
- cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
-static inline typename FloatProperties<T>::BitsType valueAsBits(T x) {
- using BitsType = typename FloatProperties<T>::BitsType;
- return *reinterpret_cast<BitsType *>(&x);
-}
-
-// Return the float value from bits.
-template <typename BitsType,
- cpp::EnableIfType<
- cpp::IsFloatingPointType<FloatTypeT<BitsType>>::Value, int> = 0>
-static inline FloatTypeT<BitsType> valueFromBits(BitsType bits) {
- return *reinterpret_cast<FloatTypeT<BitsType> *>(&bits);
-}
-
-// Return the bits of abs(x).
-template <typename T,
- cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
-static inline typename FloatProperties<T>::BitsType absBits(T x) {
- return valueAsBits(x) & (~FloatProperties<T>::signMask);
-}
-
-template <typename BitsType>
-static inline int getExponentFromBits(BitsType bits) {
- using FPType = typename FloatType<BitsType>::Type;
- using Properties = FloatProperties<FPType>;
- bits &= Properties::exponentMask;
- int e = (bits >> Properties::mantissaWidth); // Shift out the mantissa.
- e -= Properties::exponentOffset; // Zero adjust.
- return e;
-}
-
-// Return the zero adjusted exponent value of x.
-template <typename T,
- cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
-static inline int getExponent(T x) {
- return getExponentFromBits(valueAsBits(x));
-}
-
-} // namespace fputil
-} // namespace __llvm_libc
-
-#endif // LLVM_LIBC_UTILS_FPUTIL_FLOAT_OPERATIONS_H
More information about the libc-commits
mailing list