authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-14 00:08:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-14 00:11:46-07:00
log2a50a4629b19af1e72f55a41f45398be61bb7db1
tree4f55ec26c93bf5dd887ae6261d41c4212f025456
parent547e6f6ee1c789fbcedd54ba28a69c1626e1465d

freestanding libc: include roundl


2 files changed, 13 insertions(+), 1 deletions(-)

lib/std/math/round.zig+4
......@@ -20,6 +20,10 @@ pub fn round(x: anytype) @TypeOf(x) {
2020 f32 => round32(x),
2121 f64 => round64(x),
2222 f128 => round128(x),
23
24 // TODO this is not correct for some targets
25 c_longdouble => @floatCast(c_longdouble, round128(x)),
26
2327 else => @compileError("round not implemented for " ++ @typeName(T)),
2428 };
2529}
lib/std/special/c.zig+9-1
......@@ -98,6 +98,7 @@ comptime {
9898
9999 @export(round, .{ .name = "round", .linkage = .Strong });
100100 @export(roundf, .{ .name = "roundf", .linkage = .Strong });
101 @export(roundl, .{ .name = "roundl", .linkage = .Strong });
101102
102103 @export(fmin, .{ .name = "fmin", .linkage = .Strong });
103104 @export(fminf, .{ .name = "fminf", .linkage = .Strong });
......@@ -575,11 +576,18 @@ fn fabsf(a: f32) callconv(.C) f32 {
575576 return math.fabs(a);
576577}
577578
579fn roundf(a: f32) callconv(.C) f32 {
580 return math.round(a);
581}
582
578583fn round(a: f64) callconv(.C) f64 {
579584 return math.round(a);
580585}
581586
582fn roundf(a: f32) callconv(.C) f32 {
587fn roundl(a: c_longdouble) callconv(.C) c_longdouble {
588 if (!long_double_is_f128) {
589 @panic("TODO implement this");
590 }
583591 return math.round(a);
584592}
585593