Skip to content

Commit

Permalink
Add compile error for bad types
Browse files Browse the repository at this point in the history
  • Loading branch information
Fri3dNstuff committed Sep 20, 2024
1 parent ec69653 commit 7d0b2b4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/std/math/gcd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ pub fn gcd(a: anytype, b: anytype) @TypeOf(a, b) {
comptime_int => std.math.IntFittingRange(@min(a, b), @max(a, b)),
else => |T| T,
};
comptime std.debug.assert(@typeInfo(N).Int.signedness == .unsigned);
if (@typeInfo(N) != .int or @typeInfo(N).int.signedness != .unsigned) {
@compileError("`a` and `b` must be usigned integers");
}

// using an optimised form of Stein's algorithm:
// https://en.wikipedia.org/wiki/Binary_GCD_algorithm
Expand Down

0 comments on commit 7d0b2b4

Please sign in to comment.