authorgravatar for hi@mihaelm.commihael <hi@mihaelm.com> 2026-03-10 00:09:00+01:00
committergravatar for hi@mihaelm.commihael <hi@mihaelm.com> 2026-03-10 00:42:32+01:00
log159568a05a222681f54a27310ac15c3043563f95
tree4d173c445efc90f343f80b0712cfa939c495e9ef
parent1f92162875a3f05942dad6696b206cb9a1394f80
signaturebadge-check Signed by SSH key SHA256:aoFoShdYLdrqMichqKXSSieTKUfACUIDJHsKc4V2tQg

Reimplement `coshf` in `libzigc`

The function basically calls the Zig std's implementation. The changes 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=coshf -fqemu -fwasmtime --summary line Build Summary: 553/553 steps succeeded ```

7 files changed, 5 insertions(+), 83 deletions(-)

lib/c/math.zig+5
......@@ -31,6 +31,7 @@ comptime {
3131 }
3232
3333 if (builtin.target.isMinGW() or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
34 symbol(&coshf, "coshf");
3435 symbol(&hypotf, "hypotf");
3536 symbol(&hypotl, "hypotl");
3637 symbol(&nan, "nan");
......@@ -130,6 +131,10 @@ fn cosh(x: f64) callconv(.c) f64 {
130131 return math.cosh(x);
131132}
132133
134fn coshf(x: f32) callconv(.c) f32 {
135 return math.cosh(x);
136}
137
133138fn cbrt(x: f64) callconv(.c) f64 {
134139 return math.cbrt(x);
135140}
lib/libc/mingw/math/coshf.c deleted-10
......@@ -1,10 +0,0 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6#include <math.h>
7float coshf (float x)
8{
9 return (float) cosh (x);
10}
lib/libc/musl/src/math/coshf.c deleted-33
......@@ -1,33 +0,0 @@
1#include "libm.h"
2
3float coshf(float x)
4{
5 union {float f; uint32_t i;} u = {.f = x};
6 uint32_t w;
7 float t;
8
9 /* |x| */
10 u.i &= 0x7fffffff;
11 x = u.f;
12 w = u.i;
13
14 /* |x| < log(2) */
15 if (w < 0x3f317217) {
16 if (w < 0x3f800000 - (12<<23)) {
17 FORCE_EVAL(x + 0x1p120f);
18 return 1;
19 }
20 t = expm1f(x);
21 return 1 + t*t/(2*(1+t));
22 }
23
24 /* |x| < log(FLT_MAX) */
25 if (w < 0x42b17217) {
26 t = expf(x);
27 return 0.5f*(t + 1/t);
28 }
29
30 /* |x| > log(FLT_MAX) or nan */
31 t = __expo2f(x, 1.0f);
32 return t;
33}
lib/libc/wasi/libc-top-half/musl/src/math/coshf.c deleted-37
......@@ -1,37 +0,0 @@
1#include "libm.h"
2
3float coshf(float x)
4{
5 union {float f; uint32_t i;} u = {.f = x};
6 uint32_t w;
7 float t;
8
9 /* |x| */
10 u.i &= 0x7fffffff;
11 x = u.f;
12 w = u.i;
13
14 /* |x| < log(2) */
15 if (w < 0x3f317217) {
16 if (w < 0x3f800000 - (12<<23)) {
17 FORCE_EVAL(x + 0x1p120f);
18 return 1;
19 }
20 t = expm1f(x);
21 return 1 + t*t/(2*(1+t));
22 }
23
24 /* |x| < log(FLT_MAX) */
25 if (w < 0x42b17217) {
26 t = expf(x);
27 return 0.5f*(t + 1/t);
28 }
29
30 /* |x| > log(FLT_MAX) or nan */
31#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes
32 t = __expo2f(x, 1.0f);
33#else
34 t = __expo2f(x);
35#endif
36 return t;
37}
src/libs/mingw.zig-1
......@@ -977,7 +977,6 @@ const mingw32_x86_src = [_][]const u8{
977977
978978const mingw32_x86_32_src = [_][]const u8{
979979 // ucrtbase
980 "math" ++ path.sep_str ++ "coshf.c",
981980 "math" ++ path.sep_str ++ "modff.c",
982981 "math" ++ path.sep_str ++ "powf.c",
983982 "math" ++ path.sep_str ++ "sinhf.c",
src/libs/musl.zig-1
......@@ -819,7 +819,6 @@ const src_files = [_][]const u8{
819819 "musl/src/math/cbrtl.c",
820820 "musl/src/math/__cos.c",
821821 "musl/src/math/__cosdf.c",
822 "musl/src/math/coshf.c",
823822 "musl/src/math/coshl.c",
824823 "musl/src/math/__cosl.c",
825824 "musl/src/math/cosl.c",
src/libs/wasi_libc.zig-1
......@@ -1003,7 +1003,6 @@ const libc_top_half_src_files = [_][]const u8{
10031003 "wasi/libc-top-half/musl/src/locale/locale_map.c",
10041004 "wasi/libc-top-half/musl/src/locale/newlocale.c",
10051005 "wasi/libc-top-half/musl/src/locale/uselocale.c",
1006 "wasi/libc-top-half/musl/src/math/coshf.c",
10071006 "wasi/libc-top-half/musl/src/math/__expo2.c",
10081007 "wasi/libc-top-half/musl/src/math/__expo2f.c",
10091008 "wasi/libc-top-half/musl/src/math/fmal.c",