Skip to content

Commit

Permalink
Revert std.math.divCeil for CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratakor committed Oct 21, 2024
1 parent 8493fcc commit 95e150c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/std/math.zig
Original file line number Diff line number Diff line change
Expand Up @@ -895,10 +895,24 @@ fn testDivFloor() !void {
/// infinity. Returns an error on overflow or when denominator is
/// zero.
pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
// TODO: replace with @divCeil
@setRuntimeSafety(false);
if (denominator == 0) return error.DivisionByZero;
if (@typeInfo(T) == .int and @typeInfo(T).int.signedness == .signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
return @divCeil(numerator, denominator);
const info = @typeInfo(T);
switch (info) {
.comptime_float, .float => return @ceil(numerator / denominator),
.comptime_int, .int => {
if (numerator < 0 and denominator < 0) {
if (info == .int and numerator == minInt(T) and denominator == -1)
return error.Overflow;
return @divFloor(numerator + 1, denominator) + 1;
}
if (numerator > 0 and denominator > 0)
return @divFloor(numerator - 1, denominator) + 1;
return @divTrunc(numerator, denominator);
},
else => @compileError("divCeil unsupported on " ++ @typeName(T)),
}
}

test divCeil {
Expand Down

0 comments on commit 95e150c

Please sign in to comment.