aboutsummaryrefslogtreecommitdiff
path: root/libc/test
diff options
context:
space:
mode:
authorOverMighty <its.overmighty@gmail.com>2024-06-05 15:46:36 +0200
committerGitHub <noreply@github.com>2024-06-05 09:46:36 -0400
commit6c973036818f926c65ddc9b40578917e5f2240cb (patch)
tree63ca3adfd08d993f7f5564c0d740323268dfd634 /libc/test
parentb9549261e218cee2ad1305fb7272b831799b7bfe (diff)
downloadllvm-6c973036818f926c65ddc9b40578917e5f2240cb.zip
llvm-6c973036818f926c65ddc9b40578917e5f2240cb.tar.gz
llvm-6c973036818f926c65ddc9b40578917e5f2240cb.tar.bz2
[libc][math][c23] Add copysignf16 C23 math function (#94351)
#93566
Diffstat (limited to 'libc/test')
-rw-r--r--libc/test/src/math/smoke/CMakeLists.txt18
-rw-r--r--libc/test/src/math/smoke/CopySignTest.h9
-rw-r--r--libc/test/src/math/smoke/copysignf16_test.cpp13
3 files changed, 37 insertions, 3 deletions
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index b6a3f0b..6b70d89 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -995,6 +995,7 @@ add_fp_unittest(
CopySignTest.h
DEPENDS
libc.src.math.copysign
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -1008,6 +1009,7 @@ add_fp_unittest(
CopySignTest.h
DEPENDS
libc.src.math.copysignf
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -1021,6 +1023,21 @@ add_fp_unittest(
CopySignTest.h
DEPENDS
libc.src.math.copysignl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ copysignf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ copysignf16_test.cpp
+ HDRS
+ CopySignTest.h
+ DEPENDS
+ libc.src.math.copysignf16
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
@@ -1034,6 +1051,7 @@ add_fp_unittest(
CopySignTest.h
DEPENDS
libc.src.math.copysignf128
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
)
diff --git a/libc/test/src/math/smoke/CopySignTest.h b/libc/test/src/math/smoke/CopySignTest.h
index 1810560..1eb323a 100644
--- a/libc/test/src/math/smoke/CopySignTest.h
+++ b/libc/test/src/math/smoke/CopySignTest.h
@@ -9,6 +9,7 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_COPYSIGNTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_COPYSIGNTEST_H
+#include "src/__support/CPP/algorithm.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -35,9 +36,11 @@ public:
}
void testRange(CopySignFunc func) {
- constexpr StorageType COUNT = 100'000;
- constexpr StorageType STEP = STORAGE_MAX / COUNT;
- for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
+ 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 x_bits = FPBits(v);
T x = T(v);
if (x_bits.is_nan() || x_bits.is_inf())
diff --git a/libc/test/src/math/smoke/copysignf16_test.cpp b/libc/test/src/math/smoke/copysignf16_test.cpp
new file mode 100644
index 0000000..80a67f1
--- /dev/null
+++ b/libc/test/src/math/smoke/copysignf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for copysignf16 -----------------------------------------===//
+//
+// 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 "CopySignTest.h"
+
+#include "src/math/copysignf16.h"
+
+LIST_COPYSIGN_TESTS(float16, LIBC_NAMESPACE::copysignf16)