mirror of
https://github.com/vlang/v.git
synced 2025-09-09 07:15:50 -04:00
math.big, docs: document the behaviour of % for negative numbers; in V: -10 % 7 == -3 (#24604)
This commit is contained in:
parent
ebde7bc85e
commit
3ecffe68ff
@ -8293,6 +8293,9 @@ Assignment Operators
|
||||
&&= ||=
|
||||
```
|
||||
|
||||
Note: in V, `assert -10 % 7 == -3` passes. In programming, the sign of the remainder
|
||||
depends upon the signs of divisor and dividend.
|
||||
|
||||
## Other online resources
|
||||
|
||||
### [V contributing guide](https://github.com/vlang/v/blob/master/CONTRIBUTING.md)
|
||||
|
@ -470,6 +470,8 @@ pub fn (dividend Integer) / (divisor Integer) Integer {
|
||||
//
|
||||
// WARNING: this method will panic if `divisor == 0`. For a modular division method that
|
||||
// returns a Result refer to `mod_checked`.
|
||||
// Note: in V, `assert big.integer_from_i64(-10) % big.integer_from_i64(7) == big.integer_from_i64(-3)` passes.
|
||||
// In other words, the result is negative 3, and is NOT positive 4.
|
||||
@[inline]
|
||||
pub fn (dividend Integer) % (divisor Integer) Integer {
|
||||
if dividend.signum == -1 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user