motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit e588e3873cdb4a7f8e03085d83453f9f3d5e36a7 (tree)
parent b28e9e42e07ae553fc35fb47c1ace619405c2b5c
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Tue,  8 Feb 2022 23:30:23 +0100

stage2: export trunc, truncf and truncl

Diffstat:
Mlib/std/special/c.zig | 20++++++++++++++++++++
1 file changed, 20 insertions(+), 0 deletions(-)

diff --git a/lib/std/special/c.zig b/lib/std/special/c.zig @@ -6,7 +6,9 @@ const std = @import("std"); const builtin = @import("builtin"); +const math = std.math; const native_os = builtin.os.tag; +const long_double_is_f128 = builtin.target.longDoubleIsF128(); comptime { // When the self-hosted compiler is further along, all the logic from c_stage1.zig will @@ -15,6 +17,9 @@ comptime { if (builtin.zig_backend != .stage1) { @export(memset, .{ .name = "memset", .linkage = .Strong }); @export(memcpy, .{ .name = "memcpy", .linkage = .Strong }); + @export(trunc, .{ .name = "trunc", .linkage = .Strong }); + @export(truncf, .{ .name = "truncf", .linkage = .Strong }); + @export(truncl, .{ .name = "truncl", .linkage = .Strong }); } else { _ = @import("c_stage1.zig"); } @@ -74,3 +79,18 @@ fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, len: usize) callconv( return dest; } + +fn trunc(a: f64) f64 { + return math.trunc(a); +} + +fn truncf(a: f32) f32 { + return math.trunc(a); +} + +fn truncl(a: c_longdouble) c_longdouble { + if (!long_double_is_f128) { + @panic("TODO implement this"); + } + return math.trunc(a); +}