zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 86b92809635607ff357ce96902e2aaf83c3fd029 (tree)
parent d0dceae736edb43d4c217306a2b0445277f184ce
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Fri, 22 Oct 2021 10:47:42 -0700

zig libc: export floorl and ceill

needed since self-hosted now contains calls to `@divFloor` and
`@divTrunc` for 128-bit floats.

Diffstat:
Mlib/std/math/ceil.zig | 4++++
Mlib/std/math/floor.zig | 4++++
Mlib/std/special/c_stage1.zig | 31++++++++++++++++++++-----------
3 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/lib/std/math/ceil.zig b/lib/std/math/ceil.zig @@ -20,6 +20,10 @@ pub fn ceil(x: anytype) @TypeOf(x) { f32 => ceil32(x), f64 => ceil64(x), f128 => ceil128(x), + + // TODO this is not correct for some targets + c_longdouble => @floatCast(c_longdouble, ceil128(x)), + else => @compileError("ceil not implemented for " ++ @typeName(T)), }; } diff --git a/lib/std/math/floor.zig b/lib/std/math/floor.zig @@ -21,6 +21,10 @@ pub fn floor(x: anytype) @TypeOf(x) { f32 => floor32(x), f64 => floor64(x), f128 => floor128(x), + + // TODO this is not correct for some targets + c_longdouble => @floatCast(c_longdouble, floor128(x)), + else => @compileError("floor not implemented for " ++ @typeName(T)), }; } diff --git a/lib/std/special/c_stage1.zig b/lib/std/special/c_stage1.zig @@ -644,32 +644,41 @@ export fn fmod(x: f64, y: f64) f64 { export fn floorf(x: f32) f32 { return math.floor(x); } - -export fn ceilf(x: f32) f32 { - return math.ceil(x); -} - export fn floor(x: f64) f64 { return math.floor(x); } +export fn floorl(x: c_longdouble) c_longdouble { + if (!long_double_is_f128) { + @panic("TODO implement this"); + } + return math.floor(x); +} +export fn ceilf(x: f32) f32 { + return math.ceil(x); +} export fn ceil(x: f64) f64 { return math.ceil(x); } - -export fn fmal(a: c_longdouble, b: c_longdouble, c: c_longdouble) c_longdouble { +export fn ceill(x: c_longdouble) c_longdouble { if (!long_double_is_f128) { @panic("TODO implement this"); } - return math.fma(c_longdouble, a, b, c); + return math.ceil(x); +} + +export fn fmaf(a: f32, b: f32, c: f32) f32 { + return math.fma(f32, a, b, c); } export fn fma(a: f64, b: f64, c: f64) f64 { return math.fma(f64, a, b, c); } - -export fn fmaf(a: f32, b: f32, c: f32) f32 { - return math.fma(f32, a, b, c); +export fn fmal(a: c_longdouble, b: c_longdouble, c: c_longdouble) c_longdouble { + if (!long_double_is_f128) { + @panic("TODO implement this"); + } + return math.fma(c_longdouble, a, b, c); } export fn sin(a: f64) f64 {