commit 2a50a4629b19af1e72f55a41f45398be61bb7db1 (tree)
parent 547e6f6ee1c789fbcedd54ba28a69c1626e1465d
Author: Andrew Kelley <andrew@ziglang.org>
Date: Mon, 14 Mar 2022 00:08:31 -0700
freestanding libc: include roundl
Diffstat:
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/lib/std/math/round.zig b/lib/std/math/round.zig
@@ -20,6 +20,10 @@ pub fn round(x: anytype) @TypeOf(x) {
f32 => round32(x),
f64 => round64(x),
f128 => round128(x),
+
+ // TODO this is not correct for some targets
+ c_longdouble => @floatCast(c_longdouble, round128(x)),
+
else => @compileError("round not implemented for " ++ @typeName(T)),
};
}
diff --git a/lib/std/special/c.zig b/lib/std/special/c.zig
@@ -98,6 +98,7 @@ comptime {
@export(round, .{ .name = "round", .linkage = .Strong });
@export(roundf, .{ .name = "roundf", .linkage = .Strong });
+ @export(roundl, .{ .name = "roundl", .linkage = .Strong });
@export(fmin, .{ .name = "fmin", .linkage = .Strong });
@export(fminf, .{ .name = "fminf", .linkage = .Strong });
@@ -575,11 +576,18 @@ fn fabsf(a: f32) callconv(.C) f32 {
return math.fabs(a);
}
+fn roundf(a: f32) callconv(.C) f32 {
+ return math.round(a);
+}
+
fn round(a: f64) callconv(.C) f64 {
return math.round(a);
}
-fn roundf(a: f32) callconv(.C) f32 {
+fn roundl(a: c_longdouble) callconv(.C) c_longdouble {
+ if (!long_double_is_f128) {
+ @panic("TODO implement this");
+ }
return math.round(a);
}