From 2a733051bb5da245ac377f8771a482a85fb88519 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 24 Oct 2021 19:17:55 +0200 Subject: [PATCH] libc: Export truncl With the usual caveat of it being wrong for targets where c_longdouble is not f128. --- lib/std/math/trunc.zig | 4 ++++ lib/std/special/c_stage1.zig | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/lib/std/math/trunc.zig b/lib/std/math/trunc.zig index eab9a8b0c7..32bd7fb0aa 100644 --- a/lib/std/math/trunc.zig +++ b/lib/std/math/trunc.zig @@ -21,6 +21,10 @@ pub fn trunc(x: anytype) @TypeOf(x) { f32 => trunc32(x), f64 => trunc64(x), f128 => trunc128(x), + + // TODO this is not correct for some targets + c_longdouble => @floatCast(c_longdouble, trunc128(x)), + else => @compileError("trunc not implemented for " ++ @typeName(T)), }; } diff --git a/lib/std/special/c_stage1.zig b/lib/std/special/c_stage1.zig index c0323b1ae7..1bb28e79df 100644 --- a/lib/std/special/c_stage1.zig +++ b/lib/std/special/c_stage1.zig @@ -763,6 +763,13 @@ export fn truncf(a: f32) f32 { return math.trunc(a); } +export fn truncl(a: c_longdouble) c_longdouble { + if (!long_double_is_f128) { + @panic("TODO implement this"); + } + return math.trunc(a); +} + export fn round(a: f64) f64 { return math.round(a); }