mirror of
https://github.com/ziglang/zig.git
synced 2024-11-16 17:15:37 +00:00
std.math.divCeil: move compile error back down
This commit is contained in:
parent
49e67ce0e8
commit
340871f061
@ -623,10 +623,7 @@ fn testDivFloor() void {
|
||||
|
||||
pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
|
||||
@setRuntimeSafety(false);
|
||||
if (!(comptime std.meta.trait.isNumber(T)))
|
||||
@compileError("divCeil unsupported on " ++ @typeName(T));
|
||||
if (denominator == 0)
|
||||
return error.DivisionByZero;
|
||||
if (comptime std.meta.trait.isNumber(T) and denominator == 0) return error.DivisionByZero;
|
||||
const info = @typeInfo(T);
|
||||
switch (info) {
|
||||
.ComptimeFloat, .Float => return @ceil(numerator / denominator),
|
||||
@ -640,7 +637,7 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
|
||||
return @divFloor(numerator - 1, denominator) + 1;
|
||||
return @divTrunc(numerator, denominator);
|
||||
},
|
||||
else => unreachable,
|
||||
else => @compileError("divCeil unsupported on " ++ @typeName(T)),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user