| author | |
| committer | |
| log | c2587582c8af957f032bee1951d923d472c89e2f |
| tree | 3db2fd27a453108c5fe55abed1a83b12ae53527d |
| parent | 5d9660972d4b2f1ed575978e8543c88e1392f6b5 |
| parent | 4a0be5613b865c345e2b9daade65ee6fbb139e39 |
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31434
Reviewed-by: Andrew Kelley <andrew@ziglang.org>9 files changed, 52 insertions(+), 210 deletions(-)
lib/c/math.zig+52-41| ... | ... | @@ -14,23 +14,24 @@ comptime { |
| 14 | 14 | symbol(&isnanl, "isnanl"); |
| 15 | 15 | symbol(&isnanl, "__isnanl"); |
| 16 | 16 | |
| 17 | symbol(&math.floatTrueMin(f64), "__DENORM"); | |
| 18 | symbol(&math.inf(f64), "__INF"); | |
| 17 | 19 | symbol(&math.nan(f64), "__QNAN"); |
| 18 | 20 | symbol(&math.snan(f64), "__SNAN"); |
| 19 | symbol(&math.inf(f64), "__INF"); | |
| 20 | symbol(&math.floatTrueMin(f64), "__DENORM"); | |
| 21 | 21 | |
| 22 | symbol(&math.floatTrueMin(f32), "__DENORMF"); | |
| 23 | symbol(&math.inf(f32), "__INFF"); | |
| 22 | 24 | symbol(&math.nan(f32), "__QNANF"); |
| 23 | 25 | symbol(&math.snan(f32), "__SNANF"); |
| 24 | symbol(&math.inf(f32), "__INFF"); | |
| 25 | symbol(&math.floatTrueMin(f32), "__DENORMF"); | |
| 26 | 26 | |
| 27 | symbol(&math.floatTrueMin(c_longdouble), "__DENORML"); | |
| 28 | symbol(&math.inf(c_longdouble), "__INFL"); | |
| 27 | 29 | symbol(&math.nan(c_longdouble), "__QNANL"); |
| 28 | 30 | symbol(&math.snan(c_longdouble), "__SNANL"); |
| 29 | symbol(&math.inf(c_longdouble), "__INFL"); | |
| 30 | symbol(&math.floatTrueMin(c_longdouble), "__DENORML"); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | if (builtin.target.isMinGW() or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { |
| 34 | symbol(&coshf, "coshf"); | |
| 34 | 35 | symbol(&hypotf, "hypotf"); |
| 35 | 36 | symbol(&hypotl, "hypotl"); |
| 36 | 37 | symbol(&nan, "nan"); |
| ... | ... | @@ -40,25 +41,27 @@ comptime { |
| 40 | 41 | |
| 41 | 42 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { |
| 42 | 43 | symbol(&acos, "acos"); |
| 43 | symbol(&atanf, "atanf"); | |
| 44 | symbol(&acosf, "acosf"); | |
| 44 | 45 | symbol(&atan, "atan"); |
| 46 | symbol(&atanf, "atanf"); | |
| 45 | 47 | symbol(&atanl, "atanl"); |
| 46 | 48 | symbol(&cbrt, "cbrt"); |
| 47 | 49 | symbol(&cbrtf, "cbrtf"); |
| 50 | symbol(&cosh, "cosh"); | |
| 48 | 51 | symbol(&exp10, "exp10"); |
| 49 | 52 | symbol(&exp10f, "exp10f"); |
| 50 | 53 | symbol(&hypot, "hypot"); |
| 51 | 54 | symbol(&pow, "pow"); |
| 52 | 55 | symbol(&pow10, "pow10"); |
| 53 | 56 | symbol(&pow10f, "pow10f"); |
| 54 | symbol(&acosf, "acosf"); | |
| 55 | 57 | } |
| 56 | 58 | |
| 57 | 59 | if (builtin.target.isMuslLibC()) { |
| 58 | symbol(&copysignf, "copysignf"); | |
| 59 | 60 | symbol(&copysign, "copysign"); |
| 61 | symbol(&copysignf, "copysignf"); | |
| 60 | 62 | symbol(&rint, "rint"); |
| 61 | 63 | } |
| 64 | ||
| 62 | 65 | symbol(&copysignl, "copysignl"); |
| 63 | 66 | } |
| 64 | 67 | |
| ... | ... | @@ -66,14 +69,18 @@ fn acos(x: f64) callconv(.c) f64 { |
| 66 | 69 | return math.acos(x); |
| 67 | 70 | } |
| 68 | 71 | |
| 69 | fn atanf(x: f32) callconv(.c) f32 { | |
| 70 | return math.atan(x); | |
| 72 | fn acosf(x: f32) callconv(.c) f32 { | |
| 73 | return std.math.acos(x); | |
| 71 | 74 | } |
| 72 | 75 | |
| 73 | 76 | fn atan(x: f64) callconv(.c) f64 { |
| 74 | 77 | return math.atan(x); |
| 75 | 78 | } |
| 76 | 79 | |
| 80 | fn atanf(x: f32) callconv(.c) f32 { | |
| 81 | return math.atan(x); | |
| 82 | } | |
| 83 | ||
| 77 | 84 | fn atanl(x: c_longdouble) callconv(.c) c_longdouble { |
| 78 | 85 | return switch (@typeInfo(@TypeOf(x)).float.bits) { |
| 79 | 86 | 16 => math.atan(@as(f16, @floatCast(x))), |
| ... | ... | @@ -85,39 +92,19 @@ fn atanl(x: c_longdouble) callconv(.c) c_longdouble { |
| 85 | 92 | }; |
| 86 | 93 | } |
| 87 | 94 | |
| 88 | fn acosf(x: f32) callconv(.c) f32 { | |
| 89 | return std.math.acos(x); | |
| 90 | } | |
| 91 | ||
| 92 | fn isnan(x: f64) callconv(.c) c_int { | |
| 93 | return if (math.isNan(x)) 1 else 0; | |
| 94 | } | |
| 95 | ||
| 96 | fn isnanf(x: f32) callconv(.c) c_int { | |
| 97 | return if (math.isNan(x)) 1 else 0; | |
| 98 | } | |
| 99 | ||
| 100 | fn isnanl(x: c_longdouble) callconv(.c) c_int { | |
| 101 | return if (math.isNan(x)) 1 else 0; | |
| 102 | } | |
| 103 | ||
| 104 | fn nan(_: [*:0]const c_char) callconv(.c) f64 { | |
| 105 | return math.nan(f64); | |
| 106 | } | |
| 107 | ||
| 108 | fn nanf(_: [*:0]const c_char) callconv(.c) f32 { | |
| 109 | return math.nan(f32); | |
| 95 | fn cbrt(x: f64) callconv(.c) f64 { | |
| 96 | return math.cbrt(x); | |
| 110 | 97 | } |
| 111 | 98 | |
| 112 | fn nanl(_: [*:0]const c_char) callconv(.c) c_longdouble { | |
| 113 | return math.nan(c_longdouble); | |
| 99 | fn cbrtf(x: f32) callconv(.c) f32 { | |
| 100 | return math.cbrt(x); | |
| 114 | 101 | } |
| 115 | 102 | |
| 116 | fn copysignf(x: f32, y: f32) callconv(.c) f32 { | |
| 103 | fn copysign(x: f64, y: f64) callconv(.c) f64 { | |
| 117 | 104 | return math.copysign(x, y); |
| 118 | 105 | } |
| 119 | 106 | |
| 120 | fn copysign(x: f64, y: f64) callconv(.c) f64 { | |
| 107 | fn copysignf(x: f32, y: f32) callconv(.c) f32 { | |
| 121 | 108 | return math.copysign(x, y); |
| 122 | 109 | } |
| 123 | 110 | |
| ... | ... | @@ -125,12 +112,12 @@ fn copysignl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble { |
| 125 | 112 | return math.copysign(x, y); |
| 126 | 113 | } |
| 127 | 114 | |
| 128 | fn cbrt(x: f64) callconv(.c) f64 { | |
| 129 | return math.cbrt(x); | |
| 115 | fn cosh(x: f64) callconv(.c) f64 { | |
| 116 | return math.cosh(x); | |
| 130 | 117 | } |
| 131 | 118 | |
| 132 | fn cbrtf(x: f32) callconv(.c) f32 { | |
| 133 | return math.cbrt(x); | |
| 119 | fn coshf(x: f32) callconv(.c) f32 { | |
| 120 | return math.cosh(x); | |
| 134 | 121 | } |
| 135 | 122 | |
| 136 | 123 | fn exp10(x: f64) callconv(.c) f64 { |
| ... | ... | @@ -153,6 +140,30 @@ fn hypotl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble { |
| 153 | 140 | return math.hypot(x, y); |
| 154 | 141 | } |
| 155 | 142 | |
| 143 | fn isnan(x: f64) callconv(.c) c_int { | |
| 144 | return if (math.isNan(x)) 1 else 0; | |
| 145 | } | |
| 146 | ||
| 147 | fn isnanf(x: f32) callconv(.c) c_int { | |
| 148 | return if (math.isNan(x)) 1 else 0; | |
| 149 | } | |
| 150 | ||
| 151 | fn isnanl(x: c_longdouble) callconv(.c) c_int { | |
| 152 | return if (math.isNan(x)) 1 else 0; | |
| 153 | } | |
| 154 | ||
| 155 | fn nan(_: [*:0]const c_char) callconv(.c) f64 { | |
| 156 | return math.nan(f64); | |
| 157 | } | |
| 158 | ||
| 159 | fn nanf(_: [*:0]const c_char) callconv(.c) f32 { | |
| 160 | return math.nan(f32); | |
| 161 | } | |
| 162 | ||
| 163 | fn nanl(_: [*:0]const c_char) callconv(.c) c_longdouble { | |
| 164 | return math.nan(c_longdouble); | |
| 165 | } | |
| 166 | ||
| 156 | 167 | fn pow(x: f64, y: f64) callconv(.c) f64 { |
| 157 | 168 | return math.pow(f64, x, y); |
| 158 | 169 | } |
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> | |
| 7 | float coshf (float x) | |
| 8 | { | |
| 9 | return (float) cosh (x); | |
| 10 | } |
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/musl/src/math/coshf.c deleted-33| ... | ... | @@ -1,33 +0,0 @@ |
| 1 | #include "libm.h" | |
| 2 | ||
| 3 | float 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/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 | } |
lib/libc/wasi/libc-top-half/musl/src/math/coshf.c deleted-37| ... | ... | @@ -1,37 +0,0 @@ |
| 1 | #include "libm.h" | |
| 2 | ||
| 3 | float 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{ |
| 977 | 977 | |
| 978 | 978 | const mingw32_x86_32_src = [_][]const u8{ |
| 979 | 979 | // ucrtbase |
| 980 | "math" ++ path.sep_str ++ "coshf.c", | |
| 981 | 980 | "math" ++ path.sep_str ++ "modff.c", |
| 982 | 981 | "math" ++ path.sep_str ++ "powf.c", |
| 983 | 982 | "math" ++ path.sep_str ++ "sinhf.c", |
src/libs/musl.zig-2| ... | ... | @@ -819,8 +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 | "musl/src/math/coshf.c", | |
| 824 | 822 | "musl/src/math/coshl.c", |
| 825 | 823 | "musl/src/math/__cosl.c", |
| 826 | 824 | "musl/src/math/cosl.c", |
src/libs/wasi_libc.zig-2| ... | ... | @@ -1003,8 +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 | "wasi/libc-top-half/musl/src/math/coshf.c", | |
| 1008 | 1006 | "wasi/libc-top-half/musl/src/math/__expo2.c", |
| 1009 | 1007 | "wasi/libc-top-half/musl/src/math/__expo2f.c", |
| 1010 | 1008 | "wasi/libc-top-half/musl/src/math/fmal.c", |