diff --git a/lib/c/math.zig b/lib/c/math.zig index 27524e9860..85b871c695 100644 --- a/lib/c/math.zig +++ b/lib/c/math.zig @@ -45,8 +45,12 @@ comptime { symbol(&atanl, "atanl"); symbol(&cbrt, "cbrt"); symbol(&cbrtf, "cbrtf"); + symbol(&exp10, "exp10"); + symbol(&exp10f, "exp10f"); symbol(&hypot, "hypot"); symbol(&pow, "pow"); + symbol(&pow10, "pow10"); + symbol(&pow10f, "pow10f"); } if (builtin.target.isMuslLibC()) { @@ -123,6 +127,14 @@ fn cbrtf(x: f32) callconv(.c) f32 { return math.cbrt(x); } +fn exp10(x: f64) callconv(.c) f64 { + return math.pow(f64, 10.0, x); +} + +fn exp10f(x: f32) callconv(.c) f32 { + return math.pow(f32, 10.0, x); +} + fn hypot(x: f64, y: f64) callconv(.c) f64 { return math.hypot(x, y); } @@ -138,3 +150,11 @@ fn hypotl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble { fn pow(x: f64, y: f64) callconv(.c) f64 { return math.pow(f64, x, y); } + +fn pow10(x: f64) callconv(.c) f64 { + return exp10(x); +} + +fn pow10f(x: f32) callconv(.c) f32 { + return exp10f(x); +} diff --git a/lib/libc/musl/src/math/exp10.c b/lib/libc/musl/src/math/exp10.c deleted file mode 100644 index 26899ebac9..0000000000 --- a/lib/libc/musl/src/math/exp10.c +++ /dev/null @@ -1,24 +0,0 @@ -#define _GNU_SOURCE -#include -#include - -double exp10(double x) -{ - static const double p10[] = { - 1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10, - 1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, - 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, - 1e10, 1e11, 1e12, 1e13, 1e14, 1e15 - }; - double n, y = modf(x, &n); - union {double f; uint64_t i;} u = {n}; - /* fabs(n) < 16 without raising invalid on nan */ - if ((u.i>>52 & 0x7ff) < 0x3ff+4) { - if (!y) return p10[(int)n+15]; - y = exp2(3.32192809488736234787031942948939 * y); - return y * p10[(int)n+15]; - } - return pow(10.0, x); -} - -weak_alias(exp10, pow10); diff --git a/lib/libc/musl/src/math/exp10f.c b/lib/libc/musl/src/math/exp10f.c deleted file mode 100644 index d009f0a84f..0000000000 --- a/lib/libc/musl/src/math/exp10f.c +++ /dev/null @@ -1,22 +0,0 @@ -#define _GNU_SOURCE -#include -#include - -float exp10f(float x) -{ - static const float p10[] = { - 1e-7f, 1e-6f, 1e-5f, 1e-4f, 1e-3f, 1e-2f, 1e-1f, - 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7 - }; - float n, y = modff(x, &n); - union {float f; uint32_t i;} u = {n}; - /* fabsf(n) < 8 without raising invalid on nan */ - if ((u.i>>23 & 0xff) < 0x7f+3) { - if (!y) return p10[(int)n+7]; - y = exp2f(3.32192809488736234787031942948939f * y); - return y * p10[(int)n+7]; - } - return exp2(3.32192809488736234787031942948939 * x); -} - -weak_alias(exp10f, pow10f); diff --git a/src/libs/musl.zig b/src/libs/musl.zig index d0c87ada31..ff359a1e93 100644 --- a/src/libs/musl.zig +++ b/src/libs/musl.zig @@ -848,8 +848,6 @@ const src_files = [_][]const u8{ "musl/src/math/erf.c", "musl/src/math/erff.c", "musl/src/math/erfl.c", - "musl/src/math/exp10.c", - "musl/src/math/exp10f.c", "musl/src/math/exp10l.c", "musl/src/math/exp2f_data.c", "musl/src/math/exp2l.c", diff --git a/src/libs/wasi_libc.zig b/src/libs/wasi_libc.zig index 1ca5ba3e70..49090795ec 100644 --- a/src/libs/wasi_libc.zig +++ b/src/libs/wasi_libc.zig @@ -710,8 +710,6 @@ const libc_top_half_src_files = [_][]const u8{ "musl/src/math/erf.c", "musl/src/math/erff.c", "musl/src/math/erfl.c", - "musl/src/math/exp10.c", - "musl/src/math/exp10f.c", "musl/src/math/exp10l.c", "musl/src/math/exp2f_data.c", "musl/src/math/exp2l.c",