Skip to content

Commit 49e67ce

Browse files
committed
std.math.divCeil: move compile error to top
1 parent 933bfcf commit 49e67ce

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/std/math.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,10 @@ fn testDivFloor() void {
623623

624624
pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
625625
@setRuntimeSafety(false);
626-
if (denominator == 0) return error.DivisionByZero;
626+
if (!(comptime std.meta.trait.isNumber(T)))
627+
@compileError("divCeil unsupported on " ++ @typeName(T));
628+
if (denominator == 0)
629+
return error.DivisionByZero;
627630
const info = @typeInfo(T);
628631
switch (info) {
629632
.ComptimeFloat, .Float => return @ceil(numerator / denominator),
@@ -637,7 +640,7 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
637640
return @divFloor(numerator - 1, denominator) + 1;
638641
return @divTrunc(numerator, denominator);
639642
},
640-
else => @compileError("divCeil unsupported on " ++ @typeName(T)),
643+
else => unreachable,
641644
}
642645
}
643646

0 commit comments

Comments
 (0)