aboutsummaryrefslogtreecommitdiff
path: root/libc/test
diff options
context:
space:
mode:
authorOverMighty <its.overmighty@gmail.com>2024-06-05 18:38:15 +0200
committerGitHub <noreply@github.com>2024-06-05 12:38:15 -0400
commitfda1e4b01f723c31a36ad659564ae4a61365930e (patch)
tree8ff4c4f8382a05a74d09196b2f38b3705bd5cfa8 /libc/test
parentaa512943f47548beab655a5228c23b5503d480f8 (diff)
downloadllvm-fda1e4b01f723c31a36ad659564ae4a61365930e.zip
llvm-fda1e4b01f723c31a36ad659564ae4a61365930e.tar.gz
llvm-fda1e4b01f723c31a36ad659564ae4a61365930e.tar.bz2
[libc][math][c23] Add MPFR unit tests for {ceil,floor,round,roundeven,trunc}f16 (#94383)
Diffstat (limited to 'libc/test')
-rw-r--r--libc/test/src/math/CMakeLists.txt90
-rw-r--r--libc/test/src/math/CeilTest.h27
-rw-r--r--libc/test/src/math/FloorTest.h22
-rw-r--r--libc/test/src/math/RoundEvenTest.h30
-rw-r--r--libc/test/src/math/RoundTest.h22
-rw-r--r--libc/test/src/math/TruncTest.h22
-rw-r--r--libc/test/src/math/ceilf16_test.cpp13
-rw-r--r--libc/test/src/math/floorf16_test.cpp13
-rw-r--r--libc/test/src/math/roundevenf16_test.cpp13
-rw-r--r--libc/test/src/math/roundf16_test.cpp13
-rw-r--r--libc/test/src/math/truncf16_test.cpp13
11 files changed, 229 insertions, 49 deletions
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 102188c..e4a3087 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -141,6 +141,7 @@ add_fp_unittest(
TruncTest.h
DEPENDS
libc.src.math.trunc
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -155,6 +156,7 @@ add_fp_unittest(
TruncTest.h
DEPENDS
libc.src.math.truncf
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -169,6 +171,22 @@ add_fp_unittest(
TruncTest.h
DEPENDS
libc.src.math.truncl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ truncf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ truncf16_test.cpp
+ HDRS
+ TruncTest.h
+ DEPENDS
+ libc.src.math.truncf16
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -183,6 +201,7 @@ add_fp_unittest(
CeilTest.h
DEPENDS
libc.src.math.ceil
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -197,6 +216,7 @@ add_fp_unittest(
CeilTest.h
DEPENDS
libc.src.math.ceilf
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -211,6 +231,22 @@ add_fp_unittest(
CeilTest.h
DEPENDS
libc.src.math.ceill
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ ceilf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ ceilf16_test.cpp
+ HDRS
+ CeilTest.h
+ DEPENDS
+ libc.src.math.ceilf16
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -225,6 +261,7 @@ add_fp_unittest(
FloorTest.h
DEPENDS
libc.src.math.floor
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -239,6 +276,7 @@ add_fp_unittest(
FloorTest.h
DEPENDS
libc.src.math.floorf
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -253,6 +291,22 @@ add_fp_unittest(
FloorTest.h
DEPENDS
libc.src.math.floorl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ floorf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ floorf16_test.cpp
+ HDRS
+ FloorTest.h
+ DEPENDS
+ libc.src.math.floorf16
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -267,6 +321,7 @@ add_fp_unittest(
RoundTest.h
DEPENDS
libc.src.math.round
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -281,6 +336,7 @@ add_fp_unittest(
RoundTest.h
DEPENDS
libc.src.math.roundf
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -295,6 +351,22 @@ add_fp_unittest(
RoundTest.h
DEPENDS
libc.src.math.roundl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ roundf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ roundf16_test.cpp
+ HDRS
+ RoundTest.h
+ DEPENDS
+ libc.src.math.roundf16
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -309,6 +381,7 @@ add_fp_unittest(
RoundEvenTest.h
DEPENDS
libc.src.math.roundeven
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -323,6 +396,7 @@ add_fp_unittest(
RoundEvenTest.h
DEPENDS
libc.src.math.roundevenf
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -337,6 +411,22 @@ add_fp_unittest(
RoundEvenTest.h
DEPENDS
libc.src.math.roundevenl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ roundevenf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ roundevenf16_test.cpp
+ HDRS
+ RoundEvenTest.h
+ DEPENDS
+ libc.src.math.roundevenf16
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
diff --git a/libc/test/src/math/CeilTest.h b/libc/test/src/math/CeilTest.h
index b4c3752..3af8742 100644
--- a/libc/test/src/math/CeilTest.h
+++ b/libc/test/src/math/CeilTest.h
@@ -6,6 +6,10 @@
//
//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_TEST_SRC_MATH_CEILTEST_H
+#define LLVM_LIBC_TEST_SRC_MATH_CEILTEST_H
+
+#include "src/__support/CPP/algorithm.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -59,18 +63,21 @@ public:
EXPECT_FP_EQ(T(-10.0), func(T(-10.32)));
EXPECT_FP_EQ(T(11.0), func(T(10.65)));
EXPECT_FP_EQ(T(-10.0), func(T(-10.65)));
- EXPECT_FP_EQ(T(1235.0), func(T(1234.38)));
- EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38)));
- EXPECT_FP_EQ(T(1235.0), func(T(1234.96)));
- EXPECT_FP_EQ(T(-1234.0), func(T(-1234.96)));
+ EXPECT_FP_EQ(T(124.0), func(T(123.38)));
+ EXPECT_FP_EQ(T(-123.0), func(T(-123.38)));
+ EXPECT_FP_EQ(T(124.0), func(T(123.96)));
+ EXPECT_FP_EQ(T(-123.0), func(T(-123.96)));
}
void testRange(CeilFunc func) {
- constexpr StorageType COUNT = 100'000;
- constexpr StorageType STEP = STORAGE_MAX / COUNT;
- for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
- T x = FPBits(v).get_val();
- if (isnan(x) || isinf(x))
+ constexpr int COUNT = 100'000;
+ constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+ static_cast<StorageType>(STORAGE_MAX / COUNT), StorageType(1));
+ StorageType v = 0;
+ for (int i = 0; i <= COUNT; ++i, v += STEP) {
+ FPBits xbits(v);
+ T x = xbits.get_val();
+ if (xbits.is_inf_or_nan())
continue;
ASSERT_MPFR_MATCH(mpfr::Operation::Ceil, x, func(x), 0.0);
@@ -84,3 +91,5 @@ public:
TEST_F(LlvmLibcCeilTest, RoundedNubmers) { testRoundedNumbers(&func); } \
TEST_F(LlvmLibcCeilTest, Fractions) { testFractions(&func); } \
TEST_F(LlvmLibcCeilTest, Range) { testRange(&func); }
+
+#endif // LLVM_LIBC_TEST_SRC_MATH_CEILTEST_H
diff --git a/libc/test/src/math/FloorTest.h b/libc/test/src/math/FloorTest.h
index 9103a5b..cce0c73 100644
--- a/libc/test/src/math/FloorTest.h
+++ b/libc/test/src/math/FloorTest.h
@@ -9,6 +9,7 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_FLOORTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_FLOORTEST_H
+#include "src/__support/CPP/algorithm.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -62,18 +63,21 @@ public:
EXPECT_FP_EQ(T(-11.0), func(T(-10.32)));
EXPECT_FP_EQ(T(10.0), func(T(10.65)));
EXPECT_FP_EQ(T(-11.0), func(T(-10.65)));
- EXPECT_FP_EQ(T(1234.0), func(T(1234.38)));
- EXPECT_FP_EQ(T(-1235.0), func(T(-1234.38)));
- EXPECT_FP_EQ(T(1234.0), func(T(1234.96)));
- EXPECT_FP_EQ(T(-1235.0), func(T(-1234.96)));
+ EXPECT_FP_EQ(T(123.0), func(T(123.38)));
+ EXPECT_FP_EQ(T(-124.0), func(T(-123.38)));
+ EXPECT_FP_EQ(T(123.0), func(T(123.96)));
+ EXPECT_FP_EQ(T(-124.0), func(T(-123.96)));
}
void testRange(FloorFunc func) {
- constexpr StorageType COUNT = 100'000;
- constexpr StorageType STEP = STORAGE_MAX / COUNT;
- for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
- T x = FPBits(v).get_val();
- if (isnan(x) || isinf(x))
+ constexpr int COUNT = 100'000;
+ constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+ static_cast<StorageType>(STORAGE_MAX / COUNT), StorageType(1));
+ StorageType v = 0;
+ for (int i = 0; i <= COUNT; ++i, v += STEP) {
+ FPBits xbits(v);
+ T x = xbits.get_val();
+ if (xbits.is_inf_or_nan())
continue;
ASSERT_MPFR_MATCH(mpfr::Operation::Floor, x, func(x), 0.0);
diff --git a/libc/test/src/math/RoundEvenTest.h b/libc/test/src/math/RoundEvenTest.h
index d70555d..5ecda66 100644
--- a/libc/test/src/math/RoundEvenTest.h
+++ b/libc/test/src/math/RoundEvenTest.h
@@ -9,6 +9,7 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_ROUNDEVENTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_ROUNDEVENTEST_H
+#include "src/__support/CPP/algorithm.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -60,22 +61,25 @@ public:
EXPECT_FP_EQ(T(-2.0), func(T(-1.75)));
EXPECT_FP_EQ(T(11.0), func(T(10.65)));
EXPECT_FP_EQ(T(-11.0), func(T(-10.65)));
- EXPECT_FP_EQ(T(1233.0), func(T(1233.25)));
- EXPECT_FP_EQ(T(1234.0), func(T(1233.50)));
- EXPECT_FP_EQ(T(1234.0), func(T(1233.75)));
- EXPECT_FP_EQ(T(-1233.0), func(T(-1233.25)));
- EXPECT_FP_EQ(T(-1234.0), func(T(-1233.50)));
- EXPECT_FP_EQ(T(-1234.0), func(T(-1233.75)));
- EXPECT_FP_EQ(T(1234.0), func(T(1234.50)));
- EXPECT_FP_EQ(T(-1234.0), func(T(-1234.50)));
+ EXPECT_FP_EQ(T(123.0), func(T(123.25)));
+ EXPECT_FP_EQ(T(124.0), func(T(123.50)));
+ EXPECT_FP_EQ(T(124.0), func(T(123.75)));
+ EXPECT_FP_EQ(T(-123.0), func(T(-123.25)));
+ EXPECT_FP_EQ(T(-124.0), func(T(-123.50)));
+ EXPECT_FP_EQ(T(-124.0), func(T(-123.75)));
+ EXPECT_FP_EQ(T(124.0), func(T(124.50)));
+ EXPECT_FP_EQ(T(-124.0), func(T(-124.50)));
}
void testRange(RoundEvenFunc func) {
- constexpr StorageType COUNT = 100'000;
- constexpr StorageType STEP = STORAGE_MAX / COUNT;
- for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
- T x = FPBits(v).get_val();
- if (isnan(x) || isinf(x))
+ constexpr int COUNT = 100'000;
+ constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+ static_cast<StorageType>(STORAGE_MAX / COUNT), StorageType(1));
+ StorageType v = 0;
+ for (int i = 0; i <= COUNT; ++i, v += STEP) {
+ FPBits xbits(v);
+ T x = xbits.get_val();
+ if (xbits.is_inf_or_nan())
continue;
ASSERT_MPFR_MATCH(mpfr::Operation::RoundEven, x, func(x), 0.0);
diff --git a/libc/test/src/math/RoundTest.h b/libc/test/src/math/RoundTest.h
index 2a31df3..d571d5d 100644
--- a/libc/test/src/math/RoundTest.h
+++ b/libc/test/src/math/RoundTest.h
@@ -9,6 +9,7 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_ROUNDTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_ROUNDTEST_H
+#include "src/__support/CPP/algorithm.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -62,18 +63,21 @@ public:
EXPECT_FP_EQ(T(-10.0), func(T(-10.32)));
EXPECT_FP_EQ(T(11.0), func(T(10.65)));
EXPECT_FP_EQ(T(-11.0), func(T(-10.65)));
- EXPECT_FP_EQ(T(1234.0), func(T(1234.38)));
- EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38)));
- EXPECT_FP_EQ(T(1235.0), func(T(1234.96)));
- EXPECT_FP_EQ(T(-1235.0), func(T(-1234.96)));
+ EXPECT_FP_EQ(T(123.0), func(T(123.38)));
+ EXPECT_FP_EQ(T(-123.0), func(T(-123.38)));
+ EXPECT_FP_EQ(T(124.0), func(T(123.96)));
+ EXPECT_FP_EQ(T(-124.0), func(T(-123.96)));
}
void testRange(RoundFunc func) {
- constexpr StorageType COUNT = 100'000;
- constexpr StorageType STEP = STORAGE_MAX / COUNT;
- for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
- T x = FPBits(v).get_val();
- if (isnan(x) || isinf(x))
+ constexpr int COUNT = 100'000;
+ constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+ static_cast<StorageType>(STORAGE_MAX / COUNT), StorageType(1));
+ StorageType v = 0;
+ for (int i = 0; i <= COUNT; ++i, v += STEP) {
+ FPBits xbits(v);
+ T x = xbits.get_val();
+ if (xbits.is_inf_or_nan())
continue;
ASSERT_MPFR_MATCH(mpfr::Operation::Round, x, func(x), 0.0);
diff --git a/libc/test/src/math/TruncTest.h b/libc/test/src/math/TruncTest.h
index bc5b761..76c9740 100644
--- a/libc/test/src/math/TruncTest.h
+++ b/libc/test/src/math/TruncTest.h
@@ -9,6 +9,7 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_TRUNCTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_TRUNCTEST_H
+#include "src/__support/CPP/algorithm.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -62,18 +63,21 @@ public:
EXPECT_FP_EQ(T(-10.0), func(T(-10.32)));
EXPECT_FP_EQ(T(10.0), func(T(10.65)));
EXPECT_FP_EQ(T(-10.0), func(T(-10.65)));
- EXPECT_FP_EQ(T(1234.0), func(T(1234.38)));
- EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38)));
- EXPECT_FP_EQ(T(1234.0), func(T(1234.96)));
- EXPECT_FP_EQ(T(-1234.0), func(T(-1234.96)));
+ EXPECT_FP_EQ(T(123.0), func(T(123.38)));
+ EXPECT_FP_EQ(T(-123.0), func(T(-123.38)));
+ EXPECT_FP_EQ(T(123.0), func(T(123.96)));
+ EXPECT_FP_EQ(T(-123.0), func(T(-123.96)));
}
void testRange(TruncFunc func) {
- constexpr StorageType COUNT = 100'000;
- constexpr StorageType STEP = STORAGE_MAX / COUNT;
- for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
- T x = FPBits(v).get_val();
- if (isnan(x) || isinf(x))
+ constexpr int COUNT = 100'000;
+ constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+ static_cast<StorageType>(STORAGE_MAX / COUNT), StorageType(1));
+ StorageType v = 0;
+ for (int i = 0; i <= COUNT; ++i, v += STEP) {
+ FPBits xbits(v);
+ T x = xbits.get_val();
+ if (xbits.is_inf_or_nan())
continue;
ASSERT_MPFR_MATCH(mpfr::Operation::Trunc, x, func(x), 0.0);
diff --git a/libc/test/src/math/ceilf16_test.cpp b/libc/test/src/math/ceilf16_test.cpp
new file mode 100644
index 0000000..a6ec922
--- /dev/null
+++ b/libc/test/src/math/ceilf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for ceilf16 ---------------------------------------------===//
+//
+// 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 "CeilTest.h"
+
+#include "src/math/ceilf16.h"
+
+LIST_CEIL_TESTS(float16, LIBC_NAMESPACE::ceilf16)
diff --git a/libc/test/src/math/floorf16_test.cpp b/libc/test/src/math/floorf16_test.cpp
new file mode 100644
index 0000000..ca5160e
--- /dev/null
+++ b/libc/test/src/math/floorf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for floorf16 --------------------------------------------===//
+//
+// 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 "FloorTest.h"
+
+#include "src/math/floorf16.h"
+
+LIST_FLOOR_TESTS(float16, LIBC_NAMESPACE::floorf16)
diff --git a/libc/test/src/math/roundevenf16_test.cpp b/libc/test/src/math/roundevenf16_test.cpp
new file mode 100644
index 0000000..911a32c
--- /dev/null
+++ b/libc/test/src/math/roundevenf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for roundevenf16 ----------------------------------------===//
+//
+// 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 "RoundEvenTest.h"
+
+#include "src/math/roundevenf16.h"
+
+LIST_ROUNDEVEN_TESTS(float16, LIBC_NAMESPACE::roundevenf16)
diff --git a/libc/test/src/math/roundf16_test.cpp b/libc/test/src/math/roundf16_test.cpp
new file mode 100644
index 0000000..54ead85
--- /dev/null
+++ b/libc/test/src/math/roundf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for roundf16 --------------------------------------------===//
+//
+// 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 "RoundTest.h"
+
+#include "src/math/roundf16.h"
+
+LIST_ROUND_TESTS(float16, LIBC_NAMESPACE::roundf16)
diff --git a/libc/test/src/math/truncf16_test.cpp b/libc/test/src/math/truncf16_test.cpp
new file mode 100644
index 0000000..832d88e
--- /dev/null
+++ b/libc/test/src/math/truncf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for truncf16 --------------------------------------------===//
+//
+// 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 "TruncTest.h"
+
+#include "src/math/truncf16.h"
+
+LIST_TRUNC_TESTS(float16, LIBC_NAMESPACE::truncf16)