| author | |
| committer | |
| log | d4217e21191d66fd62fed980a2429a6eddd7ca7a |
| tree | 8fdd79a30f4493281bde5eb0757b4b284a61badf |
| parent | 96bd268c8c07b8aae0372317bfea60ef2fb3f257 |
See #30978.
Commands i run:
```
$ stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib
$ stage4/bin/zig build test-libc -Dlibc-test-path=../../libc-test -Dtest-filter=exp10 -fqemu -fwasmtime --summary line
Build Summary: 725/737 steps succeeded (12 skipped)
```
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31163
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Pivok <pivoc@protonmail.com>
Co-committed-by: Pivok <pivoc@protonmail.com>5 files changed, 20 insertions(+), 50 deletions(-)
lib/c/math.zig+20| ... | @@ -45,8 +45,12 @@ comptime { | ... | @@ -45,8 +45,12 @@ comptime { |
| 45 | symbol(&atanl, "atanl"); | 45 | symbol(&atanl, "atanl"); |
| 46 | symbol(&cbrt, "cbrt"); | 46 | symbol(&cbrt, "cbrt"); |
| 47 | symbol(&cbrtf, "cbrtf"); | 47 | symbol(&cbrtf, "cbrtf"); |
| 48 | symbol(&exp10, "exp10"); | ||
| 49 | symbol(&exp10f, "exp10f"); | ||
| 48 | symbol(&hypot, "hypot"); | 50 | symbol(&hypot, "hypot"); |
| 49 | symbol(&pow, "pow"); | 51 | symbol(&pow, "pow"); |
| 52 | symbol(&pow10, "pow10"); | ||
| 53 | symbol(&pow10f, "pow10f"); | ||
| 50 | } | 54 | } |
| 51 | 55 | ||
| 52 | if (builtin.target.isMuslLibC()) { | 56 | if (builtin.target.isMuslLibC()) { |
| ... | @@ -123,6 +127,14 @@ fn cbrtf(x: f32) callconv(.c) f32 { | ... | @@ -123,6 +127,14 @@ fn cbrtf(x: f32) callconv(.c) f32 { |
| 123 | return math.cbrt(x); | 127 | return math.cbrt(x); |
| 124 | } | 128 | } |
| 125 | 129 | ||
| 130 | fn exp10(x: f64) callconv(.c) f64 { | ||
| 131 | return math.pow(f64, 10.0, x); | ||
| 132 | } | ||
| 133 | |||
| 134 | fn exp10f(x: f32) callconv(.c) f32 { | ||
| 135 | return math.pow(f32, 10.0, x); | ||
| 136 | } | ||
| 137 | |||
| 126 | fn hypot(x: f64, y: f64) callconv(.c) f64 { | 138 | fn hypot(x: f64, y: f64) callconv(.c) f64 { |
| 127 | return math.hypot(x, y); | 139 | return math.hypot(x, y); |
| 128 | } | 140 | } |
| ... | @@ -138,3 +150,11 @@ fn hypotl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble { | ... | @@ -138,3 +150,11 @@ fn hypotl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble { |
| 138 | fn pow(x: f64, y: f64) callconv(.c) f64 { | 150 | fn pow(x: f64, y: f64) callconv(.c) f64 { |
| 139 | return math.pow(f64, x, y); | 151 | return math.pow(f64, x, y); |
| 140 | } | 152 | } |
| 153 | |||
| 154 | fn pow10(x: f64) callconv(.c) f64 { | ||
| 155 | return exp10(x); | ||
| 156 | } | ||
| 157 | |||
| 158 | fn pow10f(x: f32) callconv(.c) f32 { | ||
| 159 | return exp10f(x); | ||
| 160 | } |
lib/libc/musl/src/math/exp10.c deleted-24| ... | @@ -1,24 +0,0 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <math.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | |||
| 5 | double exp10(double x) | ||
| 6 | { | ||
| 7 | 	static const double p10[] = { | ||
| 8 | 		1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10, | ||
| 9 | 		1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, | ||
| 10 | 		1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, | ||
| 11 | 		1e10, 1e11, 1e12, 1e13, 1e14, 1e15 | ||
| 12 | 	}; | ||
| 13 | 	double n, y = modf(x, &n); | ||
| 14 | 	union {double f; uint64_t i;} u = {n}; | ||
| 15 | 	/* fabs(n) < 16 without raising invalid on nan */ | ||
| 16 | 	if ((u.i>>52 & 0x7ff) < 0x3ff+4) { | ||
| 17 | 		if (!y) return p10[(int)n+15]; | ||
| 18 | 		y = exp2(3.32192809488736234787031942948939 * y); | ||
| 19 | 		return y * p10[(int)n+15]; | ||
| 20 | 	} | ||
| 21 | 	return pow(10.0, x); | ||
| 22 | } | ||
| 23 | |||
| 24 | weak_alias(exp10, pow10); | ||
lib/libc/musl/src/math/exp10f.c deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <math.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | |||
| 5 | float exp10f(float x) | ||
| 6 | { | ||
| 7 | 	static const float p10[] = { | ||
| 8 | 		1e-7f, 1e-6f, 1e-5f, 1e-4f, 1e-3f, 1e-2f, 1e-1f, | ||
| 9 | 		1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7 | ||
| 10 | 	}; | ||
| 11 | 	float n, y = modff(x, &n); | ||
| 12 | 	union {float f; uint32_t i;} u = {n}; | ||
| 13 | 	/* fabsf(n) < 8 without raising invalid on nan */ | ||
| 14 | 	if ((u.i>>23 & 0xff) < 0x7f+3) { | ||
| 15 | 		if (!y) return p10[(int)n+7]; | ||
| 16 | 		y = exp2f(3.32192809488736234787031942948939f * y); | ||
| 17 | 		return y * p10[(int)n+7]; | ||
| 18 | 	} | ||
| 19 | 	return exp2(3.32192809488736234787031942948939 * x); | ||
| 20 | } | ||
| 21 | |||
| 22 | weak_alias(exp10f, pow10f); | ||
src/libs/musl.zig-2| ... | @@ -848,8 +848,6 @@ const src_files = [_][]const u8{ | ... | @@ -848,8 +848,6 @@ const src_files = [_][]const u8{ |
| 848 | "musl/src/math/erf.c", | 848 | "musl/src/math/erf.c", |
| 849 | "musl/src/math/erff.c", | 849 | "musl/src/math/erff.c", |
| 850 | "musl/src/math/erfl.c", | 850 | "musl/src/math/erfl.c", |
| 851 | "musl/src/math/exp10.c", | ||
| 852 | "musl/src/math/exp10f.c", | ||
| 853 | "musl/src/math/exp10l.c", | 851 | "musl/src/math/exp10l.c", |
| 854 | "musl/src/math/exp2f_data.c", | 852 | "musl/src/math/exp2f_data.c", |
| 855 | "musl/src/math/exp2l.c", | 853 | "musl/src/math/exp2l.c", |
src/libs/wasi_libc.zig-2| ... | @@ -710,8 +710,6 @@ const libc_top_half_src_files = [_][]const u8{ | ... | @@ -710,8 +710,6 @@ const libc_top_half_src_files = [_][]const u8{ |
| 710 | "musl/src/math/erf.c", | 710 | "musl/src/math/erf.c", |
| 711 | "musl/src/math/erff.c", | 711 | "musl/src/math/erff.c", |
| 712 | "musl/src/math/erfl.c", | 712 | "musl/src/math/erfl.c", |
| 713 | "musl/src/math/exp10.c", | ||
| 714 | "musl/src/math/exp10f.c", | ||
| 715 | "musl/src/math/exp10l.c", | 713 | "musl/src/math/exp10l.c", |
| 716 | "musl/src/math/exp2f_data.c", | 714 | "musl/src/math/exp2f_data.c", |
| 717 | "musl/src/math/exp2l.c", | 715 | "musl/src/math/exp2l.c", |