Skip to content

Commit cd0b2c3

Browse files
committed
std/math/big: add Int.Rem
1 parent 667142f commit cd0b2c3

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

std/math/big/int.jule

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@ impl Int {
259259
self.neg = len(self.abs) > 0 && x.neg != y.neg // 0 has no sign
260260
}
261261

262+
// Sets self to the remainder x%y for y != 0.
263+
// If y == 0, a division-by-zero run-time panic occurs.
264+
// Implements truncated modulus (like Jule); see [Int.QuoRem] for more details.
265+
fn Rem(mut *self, &x: *Int, &y: *Int) {
266+
mut q := []Word(nil)
267+
divW(&q, &self.abs, x.abs, y.abs)
268+
self.neg = len(self.abs) > 0 && x.neg // 0 has no sign
269+
}
270+
262271
// Sets self to the quotient x/y for y != 0.
263272
// If y == 0, a division-by-zero runtime panic occurs.
264273
// Implements Euclidean division; see [Int.DivMod] for more details.

0 commit comments

Comments
 (0)