aboutsummaryrefslogtreecommitdiff
path: root/libc/test
diff options
context:
space:
mode:
authorOverMighty <its.overmighty@gmail.com>2024-06-21 15:01:47 +0200
committerGitHub <noreply@github.com>2024-06-21 09:01:47 -0400
commitb5efd214297a50664cf3373362db29432c883ebd (patch)
treeb0e94374a4e8cfb43700c05f7d99419f1ab78877 /libc/test
parentc399aeacf67e517bcfa9c4d7e5cc709a3fbe5d09 (diff)
downloadllvm-b5efd214297a50664cf3373362db29432c883ebd.zip
llvm-b5efd214297a50664cf3373362db29432c883ebd.tar.gz
llvm-b5efd214297a50664cf3373362db29432c883ebd.tar.bz2
[libc][math][c23] Add {ldexp,scalbn,scalbln}f16 C23 math functions (#94797)
Part of #93566.
Diffstat (limited to 'libc/test')
-rw-r--r--libc/test/src/math/smoke/CMakeLists.txt41
-rw-r--r--libc/test/src/math/smoke/LdExpTest.h33
-rw-r--r--libc/test/src/math/smoke/ScalbnTest.h4
-rw-r--r--libc/test/src/math/smoke/ldexpf16_test.cpp13
-rw-r--r--libc/test/src/math/smoke/scalblnf16_test.cpp13
-rw-r--r--libc/test/src/math/smoke/scalbn_test.cpp2
-rw-r--r--libc/test/src/math/smoke/scalbnf128_test.cpp2
-rw-r--r--libc/test/src/math/smoke/scalbnf16_test.cpp13
-rw-r--r--libc/test/src/math/smoke/scalbnf_test.cpp2
-rw-r--r--libc/test/src/math/smoke/scalbnl_test.cpp2
10 files changed, 108 insertions, 17 deletions
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index bd8de18..8cae52f 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -1551,6 +1551,21 @@ add_fp_unittest(
)
add_fp_unittest(
+ ldexpf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ ldexpf16_test.cpp
+ HDRS
+ LdExpTest.h
+ DEPENDS
+ libc.src.math.ldexpf16
+ libc.src.__support.CPP.limits
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.normal_float
+)
+
+add_fp_unittest(
ldexpf128_test
SUITE
libc-math-smoke-tests
@@ -3456,6 +3471,19 @@ add_fp_unittest(
)
add_fp_unittest(
+ scalblnf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ scalblnf16_test.cpp
+ HDRS
+ ScalbnTest.h
+ DEPENDS
+ libc.src.math.scalblnf16
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
scalbn_test
SUITE
libc-math-smoke-tests
@@ -3495,6 +3523,19 @@ add_fp_unittest(
)
add_fp_unittest(
+ scalbnf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ scalbnf16_test.cpp
+ HDRS
+ ScalbnTest.h
+ DEPENDS
+ libc.src.math.scalbnf16
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
scalbnf128_test
SUITE
libc-math-smoke-tests
diff --git a/libc/test/src/math/smoke/LdExpTest.h b/libc/test/src/math/smoke/LdExpTest.h
index 713d305..7739bd7 100644
--- a/libc/test/src/math/smoke/LdExpTest.h
+++ b/libc/test/src/math/smoke/LdExpTest.h
@@ -18,7 +18,7 @@
#include <stdint.h>
-template <typename T>
+template <typename T, typename U = int>
class LdExpTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;
using NormalFloat = LIBC_NAMESPACE::fputil::NormalFloat<T>;
@@ -31,13 +31,13 @@ class LdExpTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
const T nan = FPBits::quiet_nan().get_val();
// A normalized mantissa to be used with tests.
- static constexpr StorageType MANTISSA = NormalFloat::ONE + 0x1234;
+ static constexpr StorageType MANTISSA = NormalFloat::ONE + 0x123;
public:
- typedef T (*LdExpFunc)(T, int);
+ typedef T (*LdExpFunc)(T, U);
void testSpecialNumbers(LdExpFunc func) {
- int exp_array[5] = {-INT_MAX - 1, -10, 0, 10, INT_MAX};
+ int exp_array[5] = {INT_MIN, -10, 0, 10, INT_MAX};
for (int exp : exp_array) {
ASSERT_FP_EQ(zero, func(zero, exp));
ASSERT_FP_EQ(neg_zero, func(neg_zero, exp));
@@ -45,6 +45,17 @@ public:
ASSERT_FP_EQ(neg_inf, func(neg_inf, exp));
ASSERT_FP_EQ(nan, func(nan, exp));
}
+
+ if constexpr (sizeof(U) < sizeof(long) || sizeof(long) == sizeof(int))
+ return;
+ long long_exp_array[4] = {LONG_MIN, INT_MIN - 1L, INT_MAX + 1L, LONG_MAX};
+ for (long exp : long_exp_array) {
+ ASSERT_FP_EQ(zero, func(zero, exp));
+ ASSERT_FP_EQ(neg_zero, func(neg_zero, exp));
+ ASSERT_FP_EQ(inf, func(inf, exp));
+ ASSERT_FP_EQ(neg_inf, func(neg_inf, exp));
+ ASSERT_FP_EQ(nan, func(nan, exp));
+ }
}
void testPowersOfTwo(LdExpFunc func) {
@@ -60,7 +71,7 @@ public:
void testOverflow(LdExpFunc func) {
NormalFloat x(Sign::POS, FPBits::MAX_BIASED_EXPONENT - 10,
- NormalFloat::ONE + 0xF00BA);
+ NormalFloat::ONE + 0xFB);
for (int32_t exp = 10; exp < 100; ++exp) {
ASSERT_FP_EQ(inf, func(T(x), exp));
ASSERT_FP_EQ(neg_inf, func(-T(x), exp));
@@ -95,10 +106,10 @@ public:
void testNormalOperation(LdExpFunc func) {
T val_array[] = {// Normal numbers
- NormalFloat(Sign::POS, 100, MANTISSA),
- NormalFloat(Sign::POS, -100, MANTISSA),
- NormalFloat(Sign::NEG, 100, MANTISSA),
- NormalFloat(Sign::NEG, -100, MANTISSA),
+ NormalFloat(Sign::POS, 10, MANTISSA),
+ NormalFloat(Sign::POS, -10, MANTISSA),
+ NormalFloat(Sign::NEG, 10, MANTISSA),
+ NormalFloat(Sign::NEG, -10, MANTISSA),
// Subnormal numbers
NormalFloat(Sign::POS, -FPBits::EXP_BIAS, MANTISSA),
NormalFloat(Sign::NEG, -FPBits::EXP_BIAS, MANTISSA)};
@@ -114,8 +125,8 @@ public:
NormalFloat two_to_exp = NormalFloat(static_cast<T>(1.L));
two_to_exp = two_to_exp.mul2(exp);
- ASSERT_FP_EQ(func(x, exp), x * two_to_exp);
- ASSERT_FP_EQ(func(x, -exp), x / two_to_exp);
+ ASSERT_FP_EQ(func(x, exp), x * static_cast<T>(two_to_exp));
+ ASSERT_FP_EQ(func(x, -exp), x / static_cast<T>(two_to_exp));
}
}
diff --git a/libc/test/src/math/smoke/ScalbnTest.h b/libc/test/src/math/smoke/ScalbnTest.h
index e1d035c..67ea30f 100644
--- a/libc/test/src/math/smoke/ScalbnTest.h
+++ b/libc/test/src/math/smoke/ScalbnTest.h
@@ -12,8 +12,8 @@
#include "LdExpTest.h"
#include "test/UnitTest/Test.h"
-#define LIST_SCALBN_TESTS(T, func) \
- using LlvmLibcScalbnTest = LdExpTestTemplate<T>; \
+#define LIST_SCALBN_TESTS(T, U, func) \
+ using LlvmLibcScalbnTest = LdExpTestTemplate<T, U>; \
TEST_F(LlvmLibcScalbnTest, SpecialNumbers) { testSpecialNumbers(&func); } \
TEST_F(LlvmLibcScalbnTest, PowersOfTwo) { testPowersOfTwo(&func); } \
TEST_F(LlvmLibcScalbnTest, OverFlow) { testOverflow(&func); } \
diff --git a/libc/test/src/math/smoke/ldexpf16_test.cpp b/libc/test/src/math/smoke/ldexpf16_test.cpp
new file mode 100644
index 0000000..ecf8f76
--- /dev/null
+++ b/libc/test/src/math/smoke/ldexpf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for ldexpf16 --------------------------------------------===//
+//
+// 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 "LdExpTest.h"
+
+#include "src/math/ldexpf16.h"
+
+LIST_LDEXP_TESTS(float16, LIBC_NAMESPACE::ldexpf16);
diff --git a/libc/test/src/math/smoke/scalblnf16_test.cpp b/libc/test/src/math/smoke/scalblnf16_test.cpp
new file mode 100644
index 0000000..a678254
--- /dev/null
+++ b/libc/test/src/math/smoke/scalblnf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for scalblnf16 ------------------------------------------===//
+//
+// 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 "ScalbnTest.h"
+
+#include "src/math/scalblnf16.h"
+
+LIST_SCALBN_TESTS(float16, long, LIBC_NAMESPACE::scalblnf16)
diff --git a/libc/test/src/math/smoke/scalbn_test.cpp b/libc/test/src/math/smoke/scalbn_test.cpp
index 413a239..86ad71b 100644
--- a/libc/test/src/math/smoke/scalbn_test.cpp
+++ b/libc/test/src/math/smoke/scalbn_test.cpp
@@ -10,4 +10,4 @@
#include "src/math/scalbn.h"
-LIST_SCALBN_TESTS(double, LIBC_NAMESPACE::scalbn)
+LIST_SCALBN_TESTS(double, int, LIBC_NAMESPACE::scalbn)
diff --git a/libc/test/src/math/smoke/scalbnf128_test.cpp b/libc/test/src/math/smoke/scalbnf128_test.cpp
index dc259de..b42902a 100644
--- a/libc/test/src/math/smoke/scalbnf128_test.cpp
+++ b/libc/test/src/math/smoke/scalbnf128_test.cpp
@@ -10,4 +10,4 @@
#include "src/math/scalbnf128.h"
-LIST_SCALBN_TESTS(float128, LIBC_NAMESPACE::scalbnf128)
+LIST_SCALBN_TESTS(float128, int, LIBC_NAMESPACE::scalbnf128)
diff --git a/libc/test/src/math/smoke/scalbnf16_test.cpp b/libc/test/src/math/smoke/scalbnf16_test.cpp
new file mode 100644
index 0000000..9cee0d0
--- /dev/null
+++ b/libc/test/src/math/smoke/scalbnf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for scalbnf16 -------------------------------------------===//
+//
+// 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 "ScalbnTest.h"
+
+#include "src/math/scalbnf16.h"
+
+LIST_SCALBN_TESTS(float16, int, LIBC_NAMESPACE::scalbnf16)
diff --git a/libc/test/src/math/smoke/scalbnf_test.cpp b/libc/test/src/math/smoke/scalbnf_test.cpp
index e97781c..b25db4e 100644
--- a/libc/test/src/math/smoke/scalbnf_test.cpp
+++ b/libc/test/src/math/smoke/scalbnf_test.cpp
@@ -10,4 +10,4 @@
#include "src/math/scalbnf.h"
-LIST_SCALBN_TESTS(float, LIBC_NAMESPACE::scalbnf)
+LIST_SCALBN_TESTS(float, int, LIBC_NAMESPACE::scalbnf)
diff --git a/libc/test/src/math/smoke/scalbnl_test.cpp b/libc/test/src/math/smoke/scalbnl_test.cpp
index b0e0053..838b065 100644
--- a/libc/test/src/math/smoke/scalbnl_test.cpp
+++ b/libc/test/src/math/smoke/scalbnl_test.cpp
@@ -10,4 +10,4 @@
#include "src/math/scalbnl.h"
-LIST_SCALBN_TESTS(long double, LIBC_NAMESPACE::scalbnl)
+LIST_SCALBN_TESTS(long double, int, LIBC_NAMESPACE::scalbnl)