Skip to content

Commit 3ecffe6

Browse files
authored
math.big, docs: document the behaviour of % for negative numbers; in V: -10 % 7 == -3 (#24604)
1 parent ebde7bc commit 3ecffe6

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

doc/docs.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8293,6 +8293,9 @@ Assignment Operators
82938293
&&= ||=
82948294
```
82958295
8296+
Note: in V, `assert -10 % 7 == -3` passes. In programming, the sign of the remainder
8297+
depends upon the signs of divisor and dividend.
8298+
82968299
## Other online resources
82978300
82988301
### [V contributing guide](https://github.com/vlang/v/blob/master/CONTRIBUTING.md)

vlib/math/big/integer.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ pub fn (dividend Integer) / (divisor Integer) Integer {
470470
//
471471
// WARNING: this method will panic if `divisor == 0`. For a modular division method that
472472
// returns a Result refer to `mod_checked`.
473+
// Note: in V, `assert big.integer_from_i64(-10) % big.integer_from_i64(7) == big.integer_from_i64(-3)` passes.
474+
// In other words, the result is negative 3, and is NOT positive 4.
473475
@[inline]
474476
pub fn (dividend Integer) % (divisor Integer) Integer {
475477
if dividend.signum == -1 {

0 commit comments

Comments
 (0)