diff --git a/lib/c/math.zig b/lib/c/math.zig index cce37f9000858b41b08d14a9012f5e607a2b2367..ae3491e430c4cb433ab01430b93193ed732ed14b 100644 --- a/lib/c/math.zig +++ b/lib/c/math.zig @@ -45,6 +45,7 @@ comptime { symbol(&atanl, "atanl"); symbol(&cbrt, "cbrt"); symbol(&cbrtf, "cbrtf"); + symbol(&cosh, "cosh"); symbol(&exp10, "exp10"); symbol(&exp10f, "exp10f"); symbol(&hypot, "hypot"); @@ -125,6 +126,10 @@ fn copysignl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble { return math.copysign(x, y); } +fn cosh(x: f64) callconv(.c) f64 { + return math.cosh(x); +} + fn cbrt(x: f64) callconv(.c) f64 { return math.cbrt(x); } diff --git a/lib/libc/musl/src/math/cosh.c b/lib/libc/musl/src/math/cosh.c deleted file mode 100644 index 490c15fb166752d18fa4015401f5a27fd34337b6..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/cosh.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "libm.h" - -/* cosh(x) = (exp(x) + 1/exp(x))/2 - * = 1 + 0.5*(exp(x)-1)*(exp(x)-1)/exp(x) - * = 1 + x*x/2 + o(x^4) - */ -double cosh(double x) -{ - union {double f; uint64_t i;} u = {.f = x}; - uint32_t w; - double t; - - /* |x| */ - u.i &= (uint64_t)-1/2; - x = u.f; - w = u.i >> 32; - - /* |x| < log(2) */ - if (w < 0x3fe62e42) { - if (w < 0x3ff00000 - (26<<20)) { - /* raise inexact if x!=0 */ - FORCE_EVAL(x + 0x1p120f); - return 1; - } - t = expm1(x); - return 1 + t*t/(2*(1+t)); - } - - /* |x| < log(DBL_MAX) */ - if (w < 0x40862e42) { - t = exp(x); - /* note: if x>log(0x1p26) then the 1/t is not needed */ - return 0.5*(t + 1/t); - } - - /* |x| > log(DBL_MAX) or nan */ - /* note: the result is stored to handle overflow */ - t = __expo2(x, 1.0); - return t; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/math/cosh.c b/lib/libc/wasi/libc-top-half/musl/src/math/cosh.c deleted file mode 100644 index 2cdf0023f8b3725d12c8ec96ba0e6ed30f1d5aae..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/math/cosh.c +++ /dev/null @@ -1,44 +0,0 @@ -#include "libm.h" - -/* cosh(x) = (exp(x) + 1/exp(x))/2 - * = 1 + 0.5*(exp(x)-1)*(exp(x)-1)/exp(x) - * = 1 + x*x/2 + o(x^4) - */ -double cosh(double x) -{ - union {double f; uint64_t i;} u = {.f = x}; - uint32_t w; - double t; - - /* |x| */ - u.i &= (uint64_t)-1/2; - x = u.f; - w = u.i >> 32; - - /* |x| < log(2) */ - if (w < 0x3fe62e42) { - if (w < 0x3ff00000 - (26<<20)) { - /* raise inexact if x!=0 */ - FORCE_EVAL(x + 0x1p120f); - return 1; - } - t = expm1(x); - return 1 + t*t/(2*(1+t)); - } - - /* |x| < log(DBL_MAX) */ - if (w < 0x40862e42) { - t = exp(x); - /* note: if x>log(0x1p26) then the 1/t is not needed */ - return 0.5*(t + 1/t); - } - - /* |x| > log(DBL_MAX) or nan */ - /* note: the result is stored to handle overflow */ -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes - t = __expo2(x, 1.0); -#else - t = __expo2(x); -#endif - return t; -} diff --git a/src/libs/musl.zig b/src/libs/musl.zig index d8f5fe28121d5b1e93507bae4edee26c2456ea57..eb49d4c4f136f9b166f4dc81593d7d2ecc9b8daf 100644 --- a/src/libs/musl.zig +++ b/src/libs/musl.zig @@ -819,7 +819,6 @@ const src_files = [_][]const u8{ "musl/src/math/cbrtl.c", "musl/src/math/__cos.c", "musl/src/math/__cosdf.c", - "musl/src/math/cosh.c", "musl/src/math/coshf.c", "musl/src/math/coshl.c", "musl/src/math/__cosl.c", diff --git a/src/libs/wasi_libc.zig b/src/libs/wasi_libc.zig index 0bdcb724c50c1db7a6253f042d20e0fb4c2e09c9..72b19fe2e6e88e9cb8ead76bd4178248ef1c633c 100644 --- a/src/libs/wasi_libc.zig +++ b/src/libs/wasi_libc.zig @@ -1003,7 +1003,6 @@ const libc_top_half_src_files = [_][]const u8{ "wasi/libc-top-half/musl/src/locale/locale_map.c", "wasi/libc-top-half/musl/src/locale/newlocale.c", "wasi/libc-top-half/musl/src/locale/uselocale.c", - "wasi/libc-top-half/musl/src/math/cosh.c", "wasi/libc-top-half/musl/src/math/coshf.c", "wasi/libc-top-half/musl/src/math/__expo2.c", "wasi/libc-top-half/musl/src/math/__expo2f.c",