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

via libc-commits libc-commits at lists.llvm.org
Tue Mar 25 11:14:44 PDT 2025


================
@@ -0,0 +1,21 @@
+//===-- 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 "src/__support/FPUtil/cast.h"
+
+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);  
----------------
lntue wrote:

I'm not sure you can directly share much of the codes from `acosf16`.  For example, `acosf16(-1)` might not be the same depending on the rounding mode, but `acospif16(-1)` is always 1 regardless of the rounding mode.  You should follow and adjust the implementation of `acosf16` at https://github.com/llvm/llvm-project/blob/main/libc/src/math/generic/acosf16.cpp, and in all the final polynomial approximation step, you can directly generate the polynomials for `acospif16`, so that you don't even need to do the divisions.

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


More information about the libc-commits mailing list