aboutsummaryrefslogtreecommitdiff
path: root/libc/test
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@google.com>2020-08-20 22:36:53 -0700
committerSiva Chandra Reddy <sivachandra@google.com>2020-08-25 21:42:49 -0700
commit3f4674a5577dcc63a846d33f61e9bd95e388223d (patch)
treed683c03c11b697656d07cb4ff85e6a4e467eeb5e /libc/test
parent75e0b5866869ea1feb140d6f718d74c786547113 (diff)
downloadllvm-project-3f4674a5577dcc63a846d33f61e9bd95e388223d.tar.gz
[libc] Extend MPFRMatcher to handle multiple-input-multiple-output functions.
Tests for frexp[f|l] now use the new capability. Not all input-output combinations have been addressed by this change. Support for newer combinations can be added in future as needed. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D86506
Diffstat (limited to 'libc/test')
-rw-r--r--libc/test/src/math/CMakeLists.txt3
-rw-r--r--libc/test/src/math/frexp_test.cpp25
-rw-r--r--libc/test/src/math/frexpf_test.cpp26
-rw-r--r--libc/test/src/math/frexpl_test.cpp12
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);
}
}