| author | |
| committer | |
| log | 1f92162875a3f05942dad6696b206cb9a1394f80 |
| tree | 331e363f84c6a6146587f478cf6e2e5b29512da7 |
| parent | 3b515fbede945a2927d5aba59212553a8b26b944 |
| signature |
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=cosh -fqemu -fwasmtime --summary line
Build Summary: 921/921 steps succeeded
```5 files changed, 5 insertions(+), 86 deletions(-)
lib/c/math.zig+5| ... | ... | @@ -45,6 +45,7 @@ comptime { |
| 45 | 45 | symbol(&atanl, "atanl"); |
| 46 | 46 | symbol(&cbrt, "cbrt"); |
| 47 | 47 | symbol(&cbrtf, "cbrtf"); |
| 48 | symbol(&cosh, "cosh"); | |
| 48 | 49 | symbol(&exp10, "exp10"); |
| 49 | 50 | symbol(&exp10f, "exp10f"); |
| 50 | 51 | symbol(&hypot, "hypot"); |
| ... | ... | @@ -125,6 +126,10 @@ fn copysignl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble { |
| 125 | 126 | return math.copysign(x, y); |
| 126 | 127 | } |
| 127 | 128 | |
| 129 | fn cosh(x: f64) callconv(.c) f64 { | |
| 130 | return math.cosh(x); | |
| 131 | } | |
| 132 | ||
| 128 | 133 | fn cbrt(x: f64) callconv(.c) f64 { |
| 129 | 134 | return math.cbrt(x); |
| 130 | 135 | } |
lib/libc/musl/src/math/cosh.c deleted-40| ... | ... | @@ -1,40 +0,0 @@ |
| 1 | #include "libm.h" | |
| 2 | ||
| 3 | /* cosh(x) = (exp(x) + 1/exp(x))/2 | |
| 4 | * = 1 + 0.5*(exp(x)-1)*(exp(x)-1)/exp(x) | |
| 5 | * = 1 + x*x/2 + o(x^4) | |
| 6 | */ | |
| 7 | double cosh(double x) | |
| 8 | { | |
| 9 | 	union {double f; uint64_t i;} u = {.f = x}; | |
| 10 | 	uint32_t w; | |
| 11 | 	double t; | |
| 12 | ||
| 13 | 	/* |x| */ | |
| 14 | 	u.i &= (uint64_t)-1/2; | |
| 15 | 	x = u.f; | |
| 16 | 	w = u.i >> 32; | |
| 17 | ||
| 18 | 	/* |x| < log(2) */ | |
| 19 | 	if (w < 0x3fe62e42) { | |
| 20 | 		if (w < 0x3ff00000 - (26<<20)) { | |
| 21 | 			/* raise inexact if x!=0 */ | |
| 22 | 			FORCE_EVAL(x + 0x1p120f); | |
| 23 | 			return 1; | |
| 24 | 		} | |
| 25 | 		t = expm1(x); | |
| 26 | 		return 1 + t*t/(2*(1+t)); | |
| 27 | 	} | |
| 28 | ||
| 29 | 	/* |x| < log(DBL_MAX) */ | |
| 30 | 	if (w < 0x40862e42) { | |
| 31 | 		t = exp(x); | |
| 32 | 		/* note: if x>log(0x1p26) then the 1/t is not needed */ | |
| 33 | 		return 0.5*(t + 1/t); | |
| 34 | 	} | |
| 35 | ||
| 36 | 	/* |x| > log(DBL_MAX) or nan */ | |
| 37 | 	/* note: the result is stored to handle overflow */ | |
| 38 | 	t = __expo2(x, 1.0); | |
| 39 | 	return t; | |
| 40 | } |
lib/libc/wasi/libc-top-half/musl/src/math/cosh.c deleted-44| ... | ... | @@ -1,44 +0,0 @@ |
| 1 | #include "libm.h" | |
| 2 | ||
| 3 | /* cosh(x) = (exp(x) + 1/exp(x))/2 | |
| 4 | * = 1 + 0.5*(exp(x)-1)*(exp(x)-1)/exp(x) | |
| 5 | * = 1 + x*x/2 + o(x^4) | |
| 6 | */ | |
| 7 | double cosh(double x) | |
| 8 | { | |
| 9 | 	union {double f; uint64_t i;} u = {.f = x}; | |
| 10 | 	uint32_t w; | |
| 11 | 	double t; | |
| 12 | ||
| 13 | 	/* |x| */ | |
| 14 | 	u.i &= (uint64_t)-1/2; | |
| 15 | 	x = u.f; | |
| 16 | 	w = u.i >> 32; | |
| 17 | ||
| 18 | 	/* |x| < log(2) */ | |
| 19 | 	if (w < 0x3fe62e42) { | |
| 20 | 		if (w < 0x3ff00000 - (26<<20)) { | |
| 21 | 			/* raise inexact if x!=0 */ | |
| 22 | 			FORCE_EVAL(x + 0x1p120f); | |
| 23 | 			return 1; | |
| 24 | 		} | |
| 25 | 		t = expm1(x); | |
| 26 | 		return 1 + t*t/(2*(1+t)); | |
| 27 | 	} | |
| 28 | ||
| 29 | 	/* |x| < log(DBL_MAX) */ | |
| 30 | 	if (w < 0x40862e42) { | |
| 31 | 		t = exp(x); | |
| 32 | 		/* note: if x>log(0x1p26) then the 1/t is not needed */ | |
| 33 | 		return 0.5*(t + 1/t); | |
| 34 | 	} | |
| 35 | ||
| 36 | 	/* |x| > log(DBL_MAX) or nan */ | |
| 37 | 	/* note: the result is stored to handle overflow */ | |
| 38 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | |
| 39 | 	t = __expo2(x, 1.0); | |
| 40 | #else | |
| 41 | 	t = __expo2(x); | |
| 42 | #endif | |
| 43 | 	return t; | |
| 44 | } |
src/libs/musl.zig-1| ... | ... | @@ -819,7 +819,6 @@ const src_files = [_][]const u8{ |
| 819 | 819 | "musl/src/math/cbrtl.c", |
| 820 | 820 | "musl/src/math/__cos.c", |
| 821 | 821 | "musl/src/math/__cosdf.c", |
| 822 | "musl/src/math/cosh.c", | |
| 823 | 822 | "musl/src/math/coshf.c", |
| 824 | 823 | "musl/src/math/coshl.c", |
| 825 | 824 | "musl/src/math/__cosl.c", |
src/libs/wasi_libc.zig-1| ... | ... | @@ -1003,7 +1003,6 @@ const libc_top_half_src_files = [_][]const u8{ |
| 1003 | 1003 | "wasi/libc-top-half/musl/src/locale/locale_map.c", |
| 1004 | 1004 | "wasi/libc-top-half/musl/src/locale/newlocale.c", |
| 1005 | 1005 | "wasi/libc-top-half/musl/src/locale/uselocale.c", |
| 1006 | "wasi/libc-top-half/musl/src/math/cosh.c", | |
| 1007 | 1006 | "wasi/libc-top-half/musl/src/math/coshf.c", |
| 1008 | 1007 | "wasi/libc-top-half/musl/src/math/__expo2.c", |
| 1009 | 1008 | "wasi/libc-top-half/musl/src/math/__expo2f.c", |