diff options
Diffstat (limited to 'libc/test')
-rw-r--r-- | libc/test/src/math/CMakeLists.txt | 3 | ||||
-rw-r--r-- | libc/test/src/math/frexp_test.cpp | 25 | ||||
-rw-r--r-- | libc/test/src/math/frexpf_test.cpp | 26 | ||||
-rw-r--r-- | libc/test/src/math/frexpl_test.cpp | 12 |
4 files changed, 43 insertions, 23 deletions
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt index e73de5403564..2fe766a2ffc6 100644 --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -333,6 +333,7 @@ add_fp_unittest( add_fp_unittest( frexp_test + NEED_MPFR SUITE libc_math_unittests SRCS @@ -345,6 +346,7 @@ add_fp_unittest( add_fp_unittest( frexpf_test + NEED_MPFR SUITE libc_math_unittests SRCS @@ -357,6 +359,7 @@ add_fp_unittest( add_fp_unittest( frexpl_test + NEED_MPFR SUITE libc_math_unittests SRCS diff --git a/libc/test/src/math/frexp_test.cpp b/libc/test/src/math/frexp_test.cpp index f828d515a688..360bbf237560 100644 --- a/libc/test/src/math/frexp_test.cpp +++ b/libc/test/src/math/frexp_test.cpp @@ -11,13 +11,18 @@ #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" +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>; @@ -127,17 +132,19 @@ TEST(FrexpTest, SomeIntegers) { } TEST(FrexpTest, InDoubleRange) { - using BitsType = Properties::BitsType; - constexpr BitsType count = 1000000; - constexpr BitsType step = UINT64_MAX / count; - for (BitsType i = 0, v = 0; i <= count; ++i, v += step) { - double x = valueFromBits(v); + 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 = FPBits(v); if (isnan(x) || isinf(x) || x == 0.0) continue; - int exponent; - double frac = __llvm_libc::frexp(x, &exponent); - ASSERT_TRUE(__llvm_libc::fputil::abs(frac) < 1.0); - ASSERT_TRUE(__llvm_libc::fputil::abs(frac) >= 0.5); + mpfr::BinaryOutput<double> result; + result.f = __llvm_libc::frexp(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); } } diff --git a/libc/test/src/math/frexpf_test.cpp b/libc/test/src/math/frexpf_test.cpp index 3b82c68078ee..1bf0c36cf165 100644 --- a/libc/test/src/math/frexpf_test.cpp +++ b/libc/test/src/math/frexpf_test.cpp @@ -11,14 +11,18 @@ #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" +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>; @@ -109,7 +113,7 @@ TEST(FrexpfTest, PowersOfTwo) { EXPECT_EQ(exponent, 7); } -TEST(FrexpTest, SomeIntegers) { +TEST(FrexpfTest, SomeIntegers) { int exponent; EXPECT_EQ(valueAsBits(0.75f), @@ -135,17 +139,19 @@ TEST(FrexpTest, SomeIntegers) { } TEST(FrexpfTest, InFloatRange) { - using BitsType = Properties::BitsType; - constexpr BitsType count = 1000000; - constexpr BitsType step = UINT32_MAX / count; - for (BitsType i = 0, v = 0; i <= count; ++i, v += step) { - float x = valueFromBits(v); + 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 = FPBits(v); if (isnan(x) || isinf(x) || x == 0.0) continue; - int exponent; - float frac = __llvm_libc::frexpf(x, &exponent); - ASSERT_TRUE(__llvm_libc::fputil::abs(frac) < 1.0f); - ASSERT_TRUE(__llvm_libc::fputil::abs(frac) >= 0.5f); + mpfr::BinaryOutput<float> result; + result.f = __llvm_libc::frexpf(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); } } diff --git a/libc/test/src/math/frexpl_test.cpp b/libc/test/src/math/frexpl_test.cpp index ace445f0a2de..9846bb84ae27 100644 --- a/libc/test/src/math/frexpl_test.cpp +++ b/libc/test/src/math/frexpl_test.cpp @@ -10,10 +10,13 @@ #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" using FPBits = __llvm_libc::fputil::FPBits<long double>; +namespace mpfr = __llvm_libc::testing::mpfr; + TEST(FrexplTest, SpecialNumbers) { int exponent; @@ -94,10 +97,11 @@ TEST(FrexplTest, LongDoubleRange) { if (isnan(x) || isinf(x) || x == 0.0l) continue; - int exponent; - long double frac = __llvm_libc::frexpl(x, &exponent); + mpfr::BinaryOutput<long double> result; + result.f = __llvm_libc::frexpl(x, &result.i); - ASSERT_TRUE(__llvm_libc::fputil::abs(frac) < 1.0l); - ASSERT_TRUE(__llvm_libc::fputil::abs(frac) >= 0.5l); + 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); } } |