aboutsummaryrefslogtreecommitdiff
path: root/lib/std/math.zig
diff options
context:
space:
mode:
authorKate Tsuyu <kate@kxt.io>2020-08-28 09:55:50 -0400
committerKate Tsuyu <kate@kxt.io>2020-08-28 09:55:50 -0400
commit14b6fb88fb98580f09fc9092493d537ef3810d77 (patch)
treeaf7174b9eca02a5746a1c39eacbd35178fc43604 /lib/std/math.zig
parentaacfef17d5273abeb50cb41d5f5687408d6458b7 (diff)
downloadzig-14b6fb88fb98580f09fc9092493d537ef3810d77.tar.gz
zig-14b6fb88fb98580f09fc9092493d537ef3810d77.zip
std.math.divCeil: handle floats correctlier
Diffstat (limited to 'lib/std/math.zig')
-rw-r--r--lib/std/math.zig5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/std/math.zig b/lib/std/math.zig
index 3daf643a79..fef33ead9b 100644
--- a/lib/std/math.zig
+++ b/lib/std/math.zig
@@ -624,7 +624,10 @@ 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);
+ if (@typeInfo(T) == .Float) {
+ if (denominator == 0) return error.DivisionByZero;
+ return @ceil(numerator / denominator);
+ }
return (try divFloor(T, numerator - 1, denominator)) + 1;
}