zig/lib/c/math.zig
Pivok d4217e2119 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>
2026-02-11 19:39:40 +01:00

160 lines
3.9 KiB
Zig

const builtin = @import("builtin");
const std = @import("std");
const math = std.math;
const symbol = @import("../c.zig").symbol;
comptime {
if (builtin.target.isMinGW()) {
symbol(&isnan, "isnan");
symbol(&isnan, "__isnan");
symbol(&isnanf, "isnanf");
symbol(&isnanf, "__isnanf");
symbol(&isnanl, "isnanl");
symbol(&isnanl, "__isnanl");
symbol(&math.nan(f64), "__QNAN");
symbol(&math.snan(f64), "__SNAN");
symbol(&math.inf(f64), "__INF");
symbol(&math.floatTrueMin(f64), "__DENORM");
symbol(&math.nan(f32), "__QNANF");
symbol(&math.snan(f32), "__SNANF");
symbol(&math.inf(f32), "__INFF");
symbol(&math.floatTrueMin(f32), "__DENORMF");
symbol(&math.nan(c_longdouble), "__QNANL");
symbol(&math.snan(c_longdouble), "__SNANL");
symbol(&math.inf(c_longdouble), "__INFL");
symbol(&math.floatTrueMin(c_longdouble), "__DENORML");
}
if (builtin.target.isMinGW() or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
symbol(&hypotf, "hypotf");
symbol(&hypotl, "hypotl");
symbol(&nan, "nan");
symbol(&nanf, "nanf");
symbol(&nanl, "nanl");
}
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
symbol(&acos, "acos");
symbol(&atanf, "atanf");
symbol(&atan, "atan");
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()) {
symbol(&copysignf, "copysignf");
symbol(&copysign, "copysign");
}
symbol(&copysignl, "copysignl");
}
fn acos(x: f64) callconv(.c) f64 {
return math.acos(x);
}
fn atanf(x: f32) callconv(.c) f32 {
return math.atan(x);
}
fn atan(x: f64) callconv(.c) f64 {
return math.atan(x);
}
fn atanl(x: c_longdouble) callconv(.c) c_longdouble {
return switch (@typeInfo(@TypeOf(x)).float.bits) {
16 => math.atan(@as(f16, @floatCast(x))),
32 => math.atan(@as(f32, @floatCast(x))),
64 => math.atan(@as(f64, @floatCast(x))),
80 => math.atan(@as(f80, @floatCast(x))),
128 => math.atan(@as(f128, @floatCast(x))),
else => unreachable,
};
}
fn isnan(x: f64) callconv(.c) c_int {
return if (math.isNan(x)) 1 else 0;
}
fn isnanf(x: f32) callconv(.c) c_int {
return if (math.isNan(x)) 1 else 0;
}
fn isnanl(x: c_longdouble) callconv(.c) c_int {
return if (math.isNan(x)) 1 else 0;
}
fn nan(_: [*:0]const c_char) callconv(.c) f64 {
return math.nan(f64);
}
fn nanf(_: [*:0]const c_char) callconv(.c) f32 {
return math.nan(f32);
}
fn nanl(_: [*:0]const c_char) callconv(.c) c_longdouble {
return math.nan(c_longdouble);
}
fn copysignf(x: f32, y: f32) callconv(.c) f32 {
return math.copysign(x, y);
}
fn copysign(x: f64, y: f64) callconv(.c) f64 {
return math.copysign(x, y);
}
fn copysignl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
return math.copysign(x, y);
}
fn cbrt(x: f64) callconv(.c) f64 {
return math.cbrt(x);
}
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);
}
fn hypotf(x: f32, y: f32) callconv(.c) f32 {
return math.hypot(x, y);
}
fn hypotl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
return math.hypot(x, y);
}
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);
}