Skip to content

Commit 84ae54f

Browse files
committed
@rem() and @mod() take denominator != 0, not just denominator > 0
#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
1 parent a91b4aa commit 84ae54f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

doc/langref.html.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

0 commit comments

Comments
 (0)