[libc-commits] [libc] [libc][math][c23] Add acospif16() function (PR #132754)

via libc-commits libc-commits at lists.llvm.org
Mon Mar 24 08:03:13 PDT 2025


https://github.com/amemov created https://github.com/llvm/llvm-project/pull/132754

Addresses #132211 
Part of #95250


>From 619bc84c438882fe337460b19df626db7cca536a Mon Sep 17 00:00:00 2001
From: Anton <shepelev777 at gmail.com>
Date: Sun, 23 Mar 2025 16:50:32 -0400
Subject: [PATCH 1/3] Declared and defined acospif16 - declared acospif16
 implementation and header file - declared test files - declared in CMakeLists
 that the op needs to be checked - defined the op in math.yaml - declared in
 the index.rst that the op needs to be checked for float16 - declared an
 entrypoint for linux x86_64

---
 libc/config/linux/x86_64/entrypoints.txt    |  1 +
 libc/docs/headers/math/index.rst            |  2 +-
 libc/include/math.yaml                      |  7 +++++++
 libc/src/math/CMakeLists.txt                |  1 +
 libc/src/math/acospif16.h                   | 21 +++++++++++++++++++++
 libc/src/math/generic/CMakeLists.txt        | 20 ++++++++++++++++++++
 libc/src/math/generic/acospif16.cpp         | 20 ++++++++++++++++++++
 libc/test/src/math/CMakeLists.txt           | 11 +++++++++++
 libc/test/src/math/acospif16_test.cpp       | 12 ++++++++++++
 libc/test/src/math/smoke/CMakeLists.txt     | 11 +++++++++++
 libc/test/src/math/smoke/acospif16_test.cpp | 13 +++++++++++++
 11 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 libc/src/math/acospif16.h
 create mode 100644 libc/src/math/generic/acospif16.cpp
 create mode 100644 libc/test/src/math/acospif16_test.cpp
 create mode 100644 libc/test/src/math/smoke/acospif16_test.cpp

diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 124b80d03d846..2f1e16cd20a0e 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -654,6 +654,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
     # math.h C23 _Float16 entrypoints
     libc.src.math.asinf16
     libc.src.math.acosf16
+    libc.src.math.acospif16
     libc.src.math.canonicalizef16
     libc.src.math.ceilf16
     libc.src.math.copysignf16
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index 85585f4fc5f3d..f59828f22a3a2 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -253,7 +253,7 @@ Higher Math Functions
 +-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
 | acosh     | |check|          |                 |                        |                      |                        | 7.12.5.1               | F.10.2.1                   |
 +-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| acospi    |                  |                 |                        |                      |                        | 7.12.4.8               | F.10.1.8                   |
+| acospi    |                  |                 |                        | |check|              |                        | 7.12.4.8               | F.10.1.8                   |
 +-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
 | asin      | |check|          |                 |                        | |check|              |                        | 7.12.4.2               | F.10.1.2                   |
 +-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/include/math.yaml b/libc/include/math.yaml
index fbfc51348411a..dfe04732fbd03 100644
--- a/libc/include/math.yaml
+++ b/libc/include/math.yaml
@@ -21,6 +21,13 @@ functions:
     arguments:
       - type: _Float16
     guard: LIBC_TYPES_HAS_FLOAT16
+  - name: acospif16
+    standards:
+      - stdc
+    return_type: _Float16
+    arguments:
+      - type: _Float16
+    guard: LIBC_TYPES_HAS_FLOAT16
   - name: acoshf
     standards:
       - stdc
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index f18a73d46f9aa..6f22c51e06933 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -43,6 +43,7 @@ endfunction()
 add_math_entrypoint_object(acos)
 add_math_entrypoint_object(acosf)
 add_math_entrypoint_object(acosf16)
+add_math_entrypoint_object(acospif16)
 
 add_math_entrypoint_object(acosh)
 add_math_entrypoint_object(acoshf)
diff --git a/libc/src/math/acospif16.h b/libc/src/math/acospif16.h
new file mode 100644
index 0000000000000..c6903af70b393
--- /dev/null
+++ b/libc/src/math/acospif16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for acospif16 ---------------------*- C++ -*-===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_MATH_ACOSPIF16_H
+#define LLVM_LIBC_SRC_MATH_ACOSPIF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float16 acospif16(float16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ACOSPIF16_H
\ No newline at end of file
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index db07bd1a098cc..0825551baac25 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4054,6 +4054,26 @@ add_entrypoint_object(
     libc.src.__support.macros.properties.types  
 )
 
+add_entrypoint_object(
+  acospif16
+  SRCS
+    acospif16.cpp
+  HDRS
+    ../acospif16.h
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.__support.FPUtil.cast
+    libc.src.__support.FPUtil.except_value_utils
+    libc.src.__support.FPUtil.fenv_impl
+    libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.multiply_add
+    libc.src.__support.FPUtil.polyeval
+    libc.src.__support.FPUtil.sqrt
+    libc.src.__support.macros.optimization
+    libc.src.__support.macros.properties.types  
+)
+
 add_header_library(
   atan_utils
   HDRS
diff --git a/libc/src/math/generic/acospif16.cpp b/libc/src/math/generic/acospif16.cpp
new file mode 100644
index 0000000000000..99eb9e31f7821
--- /dev/null
+++ b/libc/src/math/generic/acospif16.cpp
@@ -0,0 +1,20 @@
+//===-- Half-precision acospif16(x) function ------------------------------===//
+//
+// 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 "src/math/acospif16.h"
+#include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/macros/optimization.h"
\ No newline at end of file
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index beafa87e03a77..c52aef996b956 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2221,6 +2221,17 @@ add_fp_unittest(
     libc.src.math.acosf16  
 )
 
+add_fp_unittest(
+  acospif16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    acospif16_test.cpp
+  DEPENDS
+    libc.src.math.acosf16  
+)
+
 add_fp_unittest(
   atanf_test
   NEED_MPFR
diff --git a/libc/test/src/math/acospif16_test.cpp b/libc/test/src/math/acospif16_test.cpp
new file mode 100644
index 0000000000000..91d668373a973
--- /dev/null
+++ b/libc/test/src/math/acospif16_test.cpp
@@ -0,0 +1,12 @@
+//===-- Exhaustive test for acospif16 -------------------------------------===//
+//
+// 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 "src/math/acospif16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 94ec099ddfcbc..f6801e10ca4bc 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3991,6 +3991,17 @@ add_fp_unittest(
     libc.src.math.acosf16  
 )
 
+add_fp_unittest(
+  acospif16_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    acospif16_test.cpp
+  DEPENDS
+    libc.src.errno.errno
+    libc.src.math.acosf16  
+)
+
 add_fp_unittest(
   atanf_test
   SUITE
diff --git a/libc/test/src/math/smoke/acospif16_test.cpp b/libc/test/src/math/smoke/acospif16_test.cpp
new file mode 100644
index 0000000000000..292cc8d07e2de
--- /dev/null
+++ b/libc/test/src/math/smoke/acospif16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for acospif16 -------------------------------------------===//
+//
+//
+// 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 "src/errno/libc_errno.h"
+#include "src/math/acospif16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"

>From 3c83bff5753d592a54b4e800e228a762d0d599d4 Mon Sep 17 00:00:00 2001
From: amemov <shepelev777 at gmail.com>
Date: Mon, 24 Mar 2025 14:38:29 +0000
Subject: [PATCH 2/3] Implemented the function and tests - Implemented
 acospif16.cpp - Implemented acospif16_test.cpp for both unit tests and
 exhaustive tests

TODO:
- Before editing, ninja check-libc was failing the tests. Need to fix
---
 libc/src/math/acospif16.h                   |  3 ++-
 libc/src/math/generic/acospif16.cpp         | 19 ++++++-------
 libc/test/src/math/acospif16_test.cpp       | 30 +++++++++++++++++++++
 libc/test/src/math/smoke/acospif16_test.cpp | 25 +++++++++++++++++
 4 files changed, 67 insertions(+), 10 deletions(-)

diff --git a/libc/src/math/acospif16.h b/libc/src/math/acospif16.h
index c6903af70b393..6145bf4b949ef 100644
--- a/libc/src/math/acospif16.h
+++ b/libc/src/math/acospif16.h
@@ -11,6 +11,7 @@
 
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/types.h"
+#include "src/math/acosf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
@@ -18,4 +19,4 @@ float16 acospif16(float16 x);
 
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LLVM_LIBC_SRC_MATH_ACOSPIF16_H
\ No newline at end of file
+#endif // LLVM_LIBC_SRC_MATH_ACOSPIF16_H
diff --git a/libc/src/math/generic/acospif16.cpp b/libc/src/math/generic/acospif16.cpp
index 99eb9e31f7821..2fab197fff5c2 100644
--- a/libc/src/math/generic/acospif16.cpp
+++ b/libc/src/math/generic/acospif16.cpp
@@ -8,13 +8,14 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/acospif16.h"
-#include "hdr/errno_macros.h"
-#include "hdr/fenv_macros.h"
-#include "src/__support/FPUtil/FEnvImpl.h"
-#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/FPUtil/PolyEval.h"
 #include "src/__support/FPUtil/cast.h"
-#include "src/__support/FPUtil/except_value_utils.h"
-#include "src/__support/FPUtil/multiply_add.h"
-#include "src/__support/FPUtil/sqrt.h"
-#include "src/__support/macros/optimization.h"
\ No newline at end of file
+
+namespace LIBC_NAMESPACE_DECL {
+// Generated by Sollya using the following command:
+// > round(pi, SG, RN);
+static constexpr float PI = 0x1.921fb6p1f;
+
+LLVM_LIBC_FUNCTION(float16, acospif16, (float16 x)) {
+    return fputil::cast<float16>(acosf16(x) / PI);  
+}
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/acospif16_test.cpp b/libc/test/src/math/acospif16_test.cpp
index 91d668373a973..d600973489f01 100644
--- a/libc/test/src/math/acospif16_test.cpp
+++ b/libc/test/src/math/acospif16_test.cpp
@@ -10,3 +10,33 @@
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 #include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcAcospif16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+// Range: [0, Inf]
+static constexpr uint16_t POS_START = 0x0000U;
+static constexpr uint16_t POS_STOP = 0x7c00U;
+
+// Range: [-Inf, 0]
+static constexpr uint16_t NEG_START = 0x8000U;
+static constexpr uint16_t NEG_STOP = 0xfc00U;
+
+TEST_F(LlvmLibcAcospif16Test, PositiveRange) {
+  for (uint16_t v = POS_START; v <= POS_STOP; ++v) {
+    float16 x = FPBits(v).get_val();
+
+    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,
+                                   LIBC_NAMESPACE::acospif16(x), 0.5);
+  }
+}
+
+TEST_F(LlvmLibcAcospif16Test, NegativeRange) {
+  for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {
+    float16 x = FPBits(v).get_val();
+
+    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,
+                                   LIBC_NAMESPACE::acospif16(x), 0.5);
+  }
+}
\ No newline at end of file
diff --git a/libc/test/src/math/smoke/acospif16_test.cpp b/libc/test/src/math/smoke/acospif16_test.cpp
index 292cc8d07e2de..9e39b55c4f792 100644
--- a/libc/test/src/math/smoke/acospif16_test.cpp
+++ b/libc/test/src/math/smoke/acospif16_test.cpp
@@ -11,3 +11,28 @@
 #include "src/math/acospif16.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
+
+using LlvmLibcAcospif16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
+TEST_F(LlvmLibcAcospif16Test, SpecialNumbers) {
+    LIBC_NAMESPACE::libc_errno = 0;
+    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(aNaN));
+    EXPECT_MATH_ERRNO(0);
+  
+    EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::acospif16(sNaN), FE_INVALID);
+    EXPECT_MATH_ERRNO(0);
+  
+    EXPECT_FP_EQ(zero, LIBC_NAMESPACE::acospif16(1.0f));
+    EXPECT_MATH_ERRNO(0);
+  
+    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(inf));
+    EXPECT_MATH_ERRNO(EDOM);
+  
+    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(neg_inf));
+    EXPECT_MATH_ERRNO(EDOM);
+  
+    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(2.0f));
+    EXPECT_MATH_ERRNO(EDOM);
+  
+    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(-2.0f));
+    EXPECT_MATH_ERRNO(EDOM);
+  }
\ No newline at end of file

>From 7c0fa527bbec941f8311c009f607a0fa821772a5 Mon Sep 17 00:00:00 2001
From: amemov <shepelev777 at gmail.com>
Date: Mon, 24 Mar 2025 14:58:35 +0000
Subject: [PATCH 3/3] Implemented the function and tests - Implemented
 acospif16.cpp - Implemented acospif16_test.cpp for both unit tests and
 exhaustive tests

TODO:
- Before editing, ninja check-libc was failing the tests. Need to fix that or run my  tests in isolation. On the surface, looks like it should work just fine, but further work would need to be done at least on my machine.
---
 libc/src/math/acospif16.h                   | 44 +++++------
 libc/test/src/math/acosf16_test.cpp         |  2 +-
 libc/test/src/math/acospif16_test.cpp       | 82 ++++++++++-----------
 libc/test/src/math/smoke/acospif16_test.cpp | 74 +++++++++----------
 4 files changed, 101 insertions(+), 101 deletions(-)

diff --git a/libc/src/math/acospif16.h b/libc/src/math/acospif16.h
index 6145bf4b949ef..38b1fe0a66be5 100644
--- a/libc/src/math/acospif16.h
+++ b/libc/src/math/acospif16.h
@@ -1,22 +1,22 @@
-//===-- Implementation header for acospif16 ---------------------*- C++ -*-===//
-//
-// 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.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_SRC_MATH_ACOSPIF16_H
-#define LLVM_LIBC_SRC_MATH_ACOSPIF16_H
-
-#include "src/__support/macros/config.h"
-#include "src/__support/macros/properties/types.h"
-#include "src/math/acosf16.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-float16 acospif16(float16 x);
-
-} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC_MATH_ACOSPIF16_H
+//===-- Implementation header for acospif16 ---------------------*- C++ -*-===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_MATH_ACOSPIF16_H
+#define LLVM_LIBC_SRC_MATH_ACOSPIF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+#include "src/math/acosf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float16 acospif16(float16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ACOSPIF16_H
diff --git a/libc/test/src/math/acosf16_test.cpp b/libc/test/src/math/acosf16_test.cpp
index f4890c81b0bcb..83f986bce9991 100644
--- a/libc/test/src/math/acosf16_test.cpp
+++ b/libc/test/src/math/acosf16_test.cpp
@@ -10,7 +10,7 @@
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 #include "utils/MPFRWrapper/MPFRUtils.h"
-
+ 
 using LlvmLibcAcosf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
 
 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
diff --git a/libc/test/src/math/acospif16_test.cpp b/libc/test/src/math/acospif16_test.cpp
index d600973489f01..cc18dc1541a33 100644
--- a/libc/test/src/math/acospif16_test.cpp
+++ b/libc/test/src/math/acospif16_test.cpp
@@ -1,42 +1,42 @@
-//===-- Exhaustive test for acospif16 -------------------------------------===//
-//
-// 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 "src/math/acospif16.h"
-#include "test/UnitTest/FPMatcher.h"
-#include "test/UnitTest/Test.h"
-#include "utils/MPFRWrapper/MPFRUtils.h"
-
-using LlvmLibcAcospif16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
-
-namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
-
-// Range: [0, Inf]
-static constexpr uint16_t POS_START = 0x0000U;
-static constexpr uint16_t POS_STOP = 0x7c00U;
-
-// Range: [-Inf, 0]
-static constexpr uint16_t NEG_START = 0x8000U;
-static constexpr uint16_t NEG_STOP = 0xfc00U;
-
-TEST_F(LlvmLibcAcospif16Test, PositiveRange) {
-  for (uint16_t v = POS_START; v <= POS_STOP; ++v) {
-    float16 x = FPBits(v).get_val();
-
-    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,
-                                   LIBC_NAMESPACE::acospif16(x), 0.5);
-  }
-}
-
-TEST_F(LlvmLibcAcospif16Test, NegativeRange) {
-  for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {
-    float16 x = FPBits(v).get_val();
-
-    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,
-                                   LIBC_NAMESPACE::acospif16(x), 0.5);
-  }
+//===-- Exhaustive test for acospif16 -------------------------------------===//
+//
+// 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 "src/math/acospif16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcAcospif16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+// Range: [0, Inf]
+static constexpr uint16_t POS_START = 0x0000U;
+static constexpr uint16_t POS_STOP = 0x7c00U;
+
+// Range: [-Inf, 0]
+static constexpr uint16_t NEG_START = 0x8000U;
+static constexpr uint16_t NEG_STOP = 0xfc00U;
+
+TEST_F(LlvmLibcAcospif16Test, PositiveRange) {
+  for (uint16_t v = POS_START; v <= POS_STOP; ++v) {
+    float16 x = FPBits(v).get_val();
+
+    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,
+                                   LIBC_NAMESPACE::acospif16(x), 0.5);
+  }
+}
+
+TEST_F(LlvmLibcAcospif16Test, NegativeRange) {
+  for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {
+    float16 x = FPBits(v).get_val();
+
+    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,
+                                   LIBC_NAMESPACE::acospif16(x), 0.5);
+  }
 }
\ No newline at end of file
diff --git a/libc/test/src/math/smoke/acospif16_test.cpp b/libc/test/src/math/smoke/acospif16_test.cpp
index 9e39b55c4f792..9316a9d4b381f 100644
--- a/libc/test/src/math/smoke/acospif16_test.cpp
+++ b/libc/test/src/math/smoke/acospif16_test.cpp
@@ -1,38 +1,38 @@
-//===-- Unittests for acospif16 -------------------------------------------===//
-//
-//
-// 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 "src/errno/libc_errno.h"
-#include "src/math/acospif16.h"
-#include "test/UnitTest/FPMatcher.h"
-#include "test/UnitTest/Test.h"
-
-using LlvmLibcAcospif16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
-TEST_F(LlvmLibcAcospif16Test, SpecialNumbers) {
-    LIBC_NAMESPACE::libc_errno = 0;
-    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(aNaN));
-    EXPECT_MATH_ERRNO(0);
-  
-    EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::acospif16(sNaN), FE_INVALID);
-    EXPECT_MATH_ERRNO(0);
-  
-    EXPECT_FP_EQ(zero, LIBC_NAMESPACE::acospif16(1.0f));
-    EXPECT_MATH_ERRNO(0);
-  
-    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(inf));
-    EXPECT_MATH_ERRNO(EDOM);
-  
-    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(neg_inf));
-    EXPECT_MATH_ERRNO(EDOM);
-  
-    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(2.0f));
-    EXPECT_MATH_ERRNO(EDOM);
-  
-    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(-2.0f));
-    EXPECT_MATH_ERRNO(EDOM);
+//===-- Unittests for acospif16 -------------------------------------------===//
+//
+//
+// 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 "src/errno/libc_errno.h"
+#include "src/math/acospif16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using LlvmLibcAcospif16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
+TEST_F(LlvmLibcAcospif16Test, SpecialNumbers) {
+    LIBC_NAMESPACE::libc_errno = 0;
+    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(aNaN));
+    EXPECT_MATH_ERRNO(0);
+  
+    EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::acospif16(sNaN), FE_INVALID);
+    EXPECT_MATH_ERRNO(0);
+  
+    EXPECT_FP_EQ(zero, LIBC_NAMESPACE::acospif16(1.0f));
+    EXPECT_MATH_ERRNO(0);
+  
+    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(inf));
+    EXPECT_MATH_ERRNO(EDOM);
+  
+    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(neg_inf));
+    EXPECT_MATH_ERRNO(EDOM);
+  
+    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(2.0f));
+    EXPECT_MATH_ERRNO(EDOM);
+  
+    EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(-2.0f));
+    EXPECT_MATH_ERRNO(EDOM);
   }
\ No newline at end of file



More information about the libc-commits mailing list