mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 16:24:51 +00:00
std.math.divCeil: handle floats correctly
This commit is contained in:
parent
9dfb917c20
commit
aacfef17d5
@ -624,6 +624,7 @@ fn testDivFloor() void {
|
||||
pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
|
||||
@setRuntimeSafety(false);
|
||||
if (numerator <= 0) return divTrunc(T, numerator, denominator);
|
||||
if (@typeInfo(T) == .Float) return @ceil(numerator / denominator);
|
||||
return (try divFloor(T, numerator - 1, denominator)) + 1;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user