aboutsummaryrefslogtreecommitdiff
path: root/libc/test/src/math/frexpf_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libc/test/src/math/frexpf_test.cpp')
-rw-r--r--libc/test/src/math/frexpf_test.cpp26
1 files changed, 16 insertions, 10 deletions
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);
}
}