authorgravatar for hi@mihaelm.commihael <hi@mihaelm.com> 2026-03-15 23:28:13+01:00
committergravatar for hi@mihaelm.commihael <hi@mihaelm.com> 2026-03-17 23:33:10+01:00
log691416c24d3c99574f1b168931f8fcd6227760b8
tree211322c8f2c7ce3e73ad5b6d2a2166a5306495ff
parentfd680ba5fbe99dde71b6ec28ecae1cddf4fed71b
signaturebadge-check Signed by SSH key SHA256:aoFoShdYLdrqMichqKXSSieTKUfACUIDJHsKc4V2tQg

`libzigc`: Implement `tanhf`

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=tanhf -fqemu -fwasmtime --summary line Build Summary: 553/553 steps succeeded ```

6 files changed, 5 insertions(+), 52 deletions(-)

lib/c/math.zig+5
...@@ -43,6 +43,7 @@ comptime {...@@ -43,6 +43,7 @@ comptime {
43 symbol(&nan, "nan");43 symbol(&nan, "nan");
44 symbol(&nanf, "nanf");44 symbol(&nanf, "nanf");
45 symbol(&nanl, "nanl");45 symbol(&nanl, "nanl");
46 symbol(&tanhf, "tanhf");
46 }47 }
4748
48 if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {49 if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
...@@ -343,3 +344,7 @@ test "rint" {...@@ -343,3 +344,7 @@ test "rint" {
343fn tanh(x: f64) callconv(.c) f64 {344fn tanh(x: f64) callconv(.c) f64 {
344 return math.tanh(x);345 return math.tanh(x);
345}346}
347
348fn tanhf(x: f32) callconv(.c) f32 {
349 return math.tanh(x);
350}
lib/libc/mingw/math/tanhf.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 tanhf (float x)
8{
9 return (float) tanh (x);
10}
lib/libc/musl/src/math/tanhf.c deleted-39
...@@ -1,39 +0,0 @@
1#include "libm.h"
2
3float tanhf(float x)
4{
5 union {float f; uint32_t i;} u = {.f = x};
6 uint32_t w;
7 int sign;
8 float t;
9
10 /* x = |x| */
11 sign = u.i >> 31;
12 u.i &= 0x7fffffff;
13 x = u.f;
14 w = u.i;
15
16 if (w > 0x3f0c9f54) {
17 /* |x| > log(3)/2 ~= 0.5493 or nan */
18 if (w > 0x41200000) {
19 /* |x| > 10 */
20 t = 1 + 0/x;
21 } else {
22 t = expm1f(2*x);
23 t = 1 - 2/(t+2);
24 }
25 } else if (w > 0x3e82c578) {
26 /* |x| > log(5/3)/2 ~= 0.2554 */
27 t = expm1f(2*x);
28 t = t/(t+2);
29 } else if (w >= 0x00800000) {
30 /* |x| >= 0x1p-126 */
31 t = expm1f(-2*x);
32 t = -t/(t+2);
33 } else {
34 /* |x| is subnormal */
35 FORCE_EVAL(x*x);
36 t = x;
37 }
38 return sign ? -t : t;
39}
src/libs/mingw.zig-1
...@@ -978,7 +978,6 @@ const mingw32_x86_32_src = [_][]const u8{...@@ -978,7 +978,6 @@ const mingw32_x86_32_src = [_][]const u8{
978 // ucrtbase978 // ucrtbase
979 "math" ++ path.sep_str ++ "powf.c",979 "math" ++ path.sep_str ++ "powf.c",
980 "math" ++ path.sep_str ++ "sinhf.c",980 "math" ++ path.sep_str ++ "sinhf.c",
981 "math" ++ path.sep_str ++ "tanhf.c",
982 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "acosf.c",981 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "acosf.c",
983 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "asinf.c",982 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "asinf.c",
984 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "atan2f.c",983 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "atan2f.c",
src/libs/musl.zig-1
...@@ -1003,7 +1003,6 @@ const src_files = [_][]const u8{...@@ -1003,7 +1003,6 @@ const src_files = [_][]const u8{
1003 "musl/src/math/sinl.c",1003 "musl/src/math/sinl.c",
1004 "musl/src/math/__tan.c",1004 "musl/src/math/__tan.c",
1005 "musl/src/math/__tandf.c",1005 "musl/src/math/__tandf.c",
1006 "musl/src/math/tanhf.c",
1007 "musl/src/math/tanhl.c",1006 "musl/src/math/tanhl.c",
1008 "musl/src/math/__tanl.c",1007 "musl/src/math/__tanl.c",
1009 "musl/src/math/tanl.c",1008 "musl/src/math/tanl.c",
src/libs/wasi_libc.zig-1
...@@ -793,7 +793,6 @@ const libc_top_half_src_files = [_][]const u8{...@@ -793,7 +793,6 @@ const libc_top_half_src_files = [_][]const u8{
793 "musl/src/math/sinl.c",793 "musl/src/math/sinl.c",
794 "musl/src/math/__tan.c",794 "musl/src/math/__tan.c",
795 "musl/src/math/__tandf.c",795 "musl/src/math/__tandf.c",
796 "musl/src/math/tanhf.c",
797 "musl/src/math/tanhl.c",796 "musl/src/math/tanhl.c",
798 "musl/src/math/__tanl.c",797 "musl/src/math/__tanl.c",
799 "musl/src/math/tanl.c",798 "musl/src/math/tanl.c",