mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 01:24:49 +01:00
zig libc: exp10, exp10f, pow10, pow10f (#31163)
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>
This commit is contained in:
parent
96bd268c8c
commit
d4217e2119
5 changed files with 20 additions and 50 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
24
lib/libc/musl/src/math/exp10.c
vendored
24
lib/libc/musl/src/math/exp10.c
vendored
|
|
@ -1,24 +0,0 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
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);
|
||||
22
lib/libc/musl/src/math/exp10f.c
vendored
22
lib/libc/musl/src/math/exp10f.c
vendored
|
|
@ -1,22 +0,0 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
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);
|
||||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue