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
51795179 <pre>{#syntax#}@mod(numerator: T, denominator: T) T{#endsyntax#}</pre>
51805180 <p>
51815181 Modulus division. For unsigned integers this is the same as
5182 {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator > 0{#endsyntax#}, otherwise the
5182 {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#}, otherwise the
51835183 operation will result in a {#link|Remainder Division by Zero#} when runtime safety checks are enabled.
51845184 </p>
51855185 <ul>
......@@ -5284,7 +5284,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
52845284 <pre>{#syntax#}@rem(numerator: T, denominator: T) T{#endsyntax#}</pre>
52855285 <p>
52865286 Remainder division. For unsigned integers this is the same as
5287 {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator > 0{#endsyntax#}, otherwise the
5287 {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#}, otherwise the
52885288 operation will result in a {#link|Remainder Division by Zero#} when runtime safety checks are enabled.
52895289 </p>
52905290 <ul>
test/behavior/math.zig+2
......@@ -531,6 +531,8 @@ fn testIntDivision() !void {
531531 try expect(rem(i32, 10, 12) == 10);
532532 try expect(rem(i32, -14, 12) == -2);
533533 try expect(rem(i32, -2, 12) == -2);
534 try expect(rem(i32, 118, -12) == 10);
535 try expect(rem(i32, -14, -12) == -2);
534536 try expect(rem(i16, -118, 12) == -10);
535537
536538 try expect(divTrunc(i20, 20, -5) == -4);