[libc-commits] [libc] [libc][math][c23] Add atanhf16 C23 math function. (PR #132612)
via libc-commits
libc-commits at lists.llvm.org
Tue Apr 15 05:46:59 PDT 2025
================
@@ -0,0 +1,99 @@
+//===-- Half-precision atanh(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/atanhf16.h"
+#include "explogxf.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/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+static constexpr size_t N_EXCEPTS = 4;
+static constexpr fputil::ExceptValues<float16, N_EXCEPTS> ATANHF16_EXCEPTS{{
+ // (input, RZ output, RU offset, RD offset, RN offset)
+ // x = 0x1.a5cp-4, atanhf16(x) = 0x1.a74p-4 (RZ)
+ {0x2E97, 0x2E9D, 1, 0, 0},
+ // x = -0x1.a5cp-4, atanhf16(x) = -0x1.a74p-4 (RZ)
+ {0xAE97, 0xAE9D, 0, 1, 0},
+ // x = -0x1.99cp-4, atanhf16(x) = -0x1.9bp-4 (RZ)
+ {0xAE67, 0xAE6C, 0, 1, 1},
+ // x = -0x1.b8cp-3, atanhf16(x) = -0x1.bfcp-3 (RZ)
+ {0xB2E3, 0xB2FF, 0, 1, 0},
+}};
+
+LLVM_LIBC_FUNCTION(float16, atanhf16, (float16 x)) {
+ using FPBits = fputil::FPBits<float16>;
+
+ FPBits xbits(x);
+ Sign sign = xbits.sign();
+ uint16_t x_abs = xbits.abs().uintval();
+
+ // |x| >= 1
+ if (LIBC_UNLIKELY(x_abs >= 0x3c00U)) {
+ if (xbits.is_nan())
+ return x;
----------------
overmighty wrote:
```suggestion
if (x_bits.is_nan()) {
if (x_bits.is_signaling_nan()) {
fputil::raise_except_if_required(FE_INVALID);
return FPBits::quiet_nan().get_val();
}
return x;
}
```
https://github.com/llvm/llvm-project/pull/132612
More information about the libc-commits
mailing list