[libc-commits] [libc] [libc][math][c23] Add acoshf16 C23 math function. (PR #130588)

via libc-commits libc-commits at lists.llvm.org
Sun Mar 16 10:27:59 PDT 2025


================
@@ -0,0 +1,88 @@
+//===-- Half-precision acoshf16 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/acoshf16.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/generic/sqrt.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/macros/optimization.h"
+#include "src/math/generic/explogxf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+static constexpr size_t N_EXCEPTS = 2;
+static constexpr fputil::ExceptValues<float16, N_EXCEPTS> ACOSHF16_EXCEPTS{
+    {// (input, RZ output, RU offset, RD offset, RN offset)
+     {0x41B7, 0x3ED8, 1, 0, 0},
+     {0x3CE4, 0x393E, 1, 0, 1}}};
----------------
overmighty wrote:

Nit: this formatting is not great.

```suggestion
static constexpr fputil::ExceptValues<float16, N_EXCEPTS> ACOSHF16_EXCEPTS{{
    // (input, RZ output, RU offset, RD offset, RN offset)
    {0x41B7, 0x3ED8, 1, 0, 0},
    {0x3CE4, 0x393E, 1, 0, 1},
}};
```

It would also be nice to add a comment for each value. For example, in expf16.cpp we have:

```cpp
static constexpr fputil::ExceptValues<float16, 2> EXPF16_EXCEPTS_LO = {{
    // (input, RZ output, RU offset, RD offset, RN offset)
    // x = 0x1.de4p-8, expf16(x) = 0x1.01cp+0 (RZ)
    {0x1f79U, 0x3c07U, 1U, 0U, 0U},
    // x = 0x1.73cp-6, expf16(x) = 0x1.05cp+0 (RZ)
    {0x25cfU, 0x3c17U, 1U, 0U, 0U},
}};
```

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


More information about the libc-commits mailing list