commit c77103add76a320d1ce877216e26dddd390caadc (tree)
parent 69cbe8ea3c54b181a42612973ae25aada7bd8b6e
Author: mihael <hi@mihaelm.com>
Date: Sat, 14 Mar 2026 10:55:04 +0100
`libzigc`: implement `acoshf`
The functions were tested by running:
```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib
$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=acoshf -fqemu -fwasmtime --summary line
Build Summary: 369/369 steps succeeded
```
Diffstat:
4 files changed, 5 insertions(+), 28 deletions(-)
diff --git a/lib/c/math.zig b/lib/c/math.zig
@@ -42,6 +42,7 @@ comptime {
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
symbol(&acos, "acos");
symbol(&acosf, "acosf");
+ symbol(&acoshf, "acoshf");
symbol(&asin, "asin");
symbol(&atan, "atan");
symbol(&atanf, "atanf");
@@ -74,6 +75,10 @@ fn acosf(x: f32) callconv(.c) f32 {
return math.acos(x);
}
+fn acoshf(x: f32) callconv(.c) f32 {
+ return math.acosh(x);
+}
+
fn asin(x: f64) callconv(.c) f64 {
return math.asin(x);
}
diff --git a/lib/libc/musl/src/math/acoshf.c b/lib/libc/musl/src/math/acoshf.c
@@ -1,26 +0,0 @@
-#include "libm.h"
-
-#if FLT_EVAL_METHOD==2
-#undef sqrtf
-#define sqrtf sqrtl
-#elif FLT_EVAL_METHOD==1
-#undef sqrtf
-#define sqrtf sqrt
-#endif
-
-/* acosh(x) = log(x + sqrt(x*x-1)) */
-float acoshf(float x)
-{
- union {float f; uint32_t i;} u = {x};
- uint32_t a = u.i & 0x7fffffff;
-
- if (a < 0x3f800000+(1<<23))
- /* |x| < 2, invalid if x < 1 */
- /* up to 2ulp error in [1,1.125] */
- return log1pf(x-1 + sqrtf((x-1)*(x-1)+2*(x-1)));
- if (u.i < 0x3f800000+(12<<23))
- /* 2 <= x < 0x1p12 */
- return logf(2*x - 1/(x+sqrtf(x*x-1)));
- /* x >= 0x1p12 or x <= -2 or nan */
- return logf(x) + 0.693147180559945309417232121458176568f;
-}
diff --git a/src/libs/musl.zig b/src/libs/musl.zig
@@ -796,7 +796,6 @@ const src_files = [_][]const u8{
"musl/src/math/aarch64/nearbyintf.c",
"musl/src/math/aarch64/rintf.c",
"musl/src/math/acosh.c",
- "musl/src/math/acoshf.c",
"musl/src/math/acoshl.c",
"musl/src/math/acosl.c",
"musl/src/math/arm/fma.c",
diff --git a/src/libs/wasi_libc.zig b/src/libs/wasi_libc.zig
@@ -665,7 +665,6 @@ const libc_top_half_src_files = [_][]const u8{
"musl/src/locale/wcscoll.c",
"musl/src/locale/wcsxfrm.c",
"musl/src/math/acosh.c",
- "musl/src/math/acoshf.c",
"musl/src/math/acoshl.c",
"musl/src/math/acosl.c",
"musl/src/math/asinf.c",