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) {...@@ -20,6 +20,10 @@ pub fn round(x: anytype) @TypeOf(x) {
20 f32 => round32(x),20 f32 => round32(x),
21 f64 => round64(x),21 f64 => round64(x),
22 f128 => round128(x),22 f128 => round128(x),
23
24 // TODO this is not correct for some targets
25 c_longdouble => @floatCast(c_longdouble, round128(x)),
26
23 else => @compileError("round not implemented for " ++ @typeName(T)),27 else => @compileError("round not implemented for " ++ @typeName(T)),
24 };28 };
25}29}
lib/std/special/c.zig+9-1
...@@ -98,6 +98,7 @@ comptime {...@@ -98,6 +98,7 @@ comptime {
9898
99 @export(round, .{ .name = "round", .linkage = .Strong });99 @export(round, .{ .name = "round", .linkage = .Strong });
100 @export(roundf, .{ .name = "roundf", .linkage = .Strong });100 @export(roundf, .{ .name = "roundf", .linkage = .Strong });
101 @export(roundl, .{ .name = "roundl", .linkage = .Strong });
101102
102 @export(fmin, .{ .name = "fmin", .linkage = .Strong });103 @export(fmin, .{ .name = "fmin", .linkage = .Strong });
103 @export(fminf, .{ .name = "fminf", .linkage = .Strong });104 @export(fminf, .{ .name = "fminf", .linkage = .Strong });
...@@ -575,11 +576,18 @@ fn fabsf(a: f32) callconv(.C) f32 {...@@ -575,11 +576,18 @@ fn fabsf(a: f32) callconv(.C) f32 {
575 return math.fabs(a);576 return math.fabs(a);
576}577}
577578
579fn roundf(a: f32) callconv(.C) f32 {
580 return math.round(a);
581}
582
578fn round(a: f64) callconv(.C) f64 {583fn round(a: f64) callconv(.C) f64 {
579 return math.round(a);584 return math.round(a);
580}585}
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 }
583 return math.round(a);591 return math.round(a);
584}592}
585593