authorgravatar for iokg04@gmail.comIOKG04 <iokg04@gmail.com> 2025-07-22 13:15:43+02:00
committergravatar for iokg04@gmail.comIOKG04 <iokg04@gmail.com> 2025-07-22 13:35:55+02:00
log84ae54fbe64a15301317716e7f901d81585332d5
tree267187210435e50673405d4e79b518420f03252c
parenta91b4aab734ec17273ca8ea5e4a8afabd6193107

`@rem()` and `@mod()` take `denominator != 0`, not just `denominator > 0`

https://github.com/ziglang/zig/issues/23635 I also added tests for `@rem()` with `denominator < 0` cause there were none before I hope I added them in the correct place, if not I can change it ofc

2 files changed, 4 insertions(+), 2 deletions(-)

doc/langref.html.in+2-2
...@@ -5179,7 +5179,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -5179,7 +5179,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
5179 <pre>{#syntax#}@mod(numerator: T, denominator: T) T{#endsyntax#}</pre>5179 <pre>{#syntax#}@mod(numerator: T, denominator: T) T{#endsyntax#}</pre>
5180 <p>5180 <p>
5181 Modulus division. For unsigned integers this is the same as5181 Modulus division. For unsigned integers this is the same as
5182 {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator > 0{#endsyntax#}, otherwise the5182 {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#}, otherwise the
5183 operation will result in a {#link|Remainder Division by Zero#} when runtime safety checks are enabled.5183 operation will result in a {#link|Remainder Division by Zero#} when runtime safety checks are enabled.
5184 </p>5184 </p>
5185 <ul>5185 <ul>
...@@ -5284,7 +5284,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -5284,7 +5284,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
5284 <pre>{#syntax#}@rem(numerator: T, denominator: T) T{#endsyntax#}</pre>5284 <pre>{#syntax#}@rem(numerator: T, denominator: T) T{#endsyntax#}</pre>
5285 <p>5285 <p>
5286 Remainder division. For unsigned integers this is the same as5286 Remainder division. For unsigned integers this is the same as
5287 {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator > 0{#endsyntax#}, otherwise the5287 {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#}, otherwise the
5288 operation will result in a {#link|Remainder Division by Zero#} when runtime safety checks are enabled.5288 operation will result in a {#link|Remainder Division by Zero#} when runtime safety checks are enabled.
5289 </p>5289 </p>
5290 <ul>5290 <ul>
test/behavior/math.zig+2
...@@ -531,6 +531,8 @@ fn testIntDivision() !void {...@@ -531,6 +531,8 @@ fn testIntDivision() !void {
531 try expect(rem(i32, 10, 12) == 10);531 try expect(rem(i32, 10, 12) == 10);
532 try expect(rem(i32, -14, 12) == -2);532 try expect(rem(i32, -14, 12) == -2);
533 try expect(rem(i32, -2, 12) == -2);533 try expect(rem(i32, -2, 12) == -2);
534 try expect(rem(i32, 118, -12) == 10);
535 try expect(rem(i32, -14, -12) == -2);
534 try expect(rem(i16, -118, 12) == -10);536 try expect(rem(i16, -118, 12) == -10);
535537
536 try expect(divTrunc(i20, 20, -5) == -4);538 try expect(divTrunc(i20, 20, -5) == -4);