From 49e67ce0e8a15e3701e01395c112c4e1ae331972 Mon Sep 17 00:00:00 2001 From: Kate Tsuyu Date: Sat, 29 Aug 2020 00:31:49 -0400 Subject: std.math.divCeil: move compile error to top --- lib/std/math.zig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/std') diff --git a/lib/std/math.zig b/lib/std/math.zig index f5aa9e4b36..a66d47412d 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -623,7 +623,10 @@ fn testDivFloor() void { pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T { @setRuntimeSafety(false); - if (denominator == 0) return error.DivisionByZero; + if (!(comptime std.meta.trait.isNumber(T))) + @compileError("divCeil unsupported on " ++ @typeName(T)); + if (denominator == 0) + return error.DivisionByZero; const info = @typeInfo(T); switch (info) { .ComptimeFloat, .Float => return @ceil(numerator / denominator), @@ -637,7 +640,7 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T { return @divFloor(numerator - 1, denominator) + 1; return @divTrunc(numerator, denominator); }, - else => @compileError("divCeil unsupported on " ++ @typeName(T)), + else => unreachable, } } -- cgit v1.2.3