The results of SIGNED_INT::div_euclid and SIGNED_INT::rem_euclid are always incorrect when a % b != 0 && a.is_negative() (where a is the dividend and b is the divisor).
I tried something similar to this code:
fn main() {
assert_eq!(div(-32768, -32767), (1, 1));
}
fn div(num: i16, div: i16) -> (i16, i16) {
(num.div_euclid(div), num.rem_euclid(div))
}
I expected to see this happen:
The assert should not fire.
Instead, this happened:
The assert fired. The return value is (2, 32766) instead of (1, 1).
More general test case on playground
Meta
This bug exists in the latest stable, beta and nightly.
The bug appears to have been present since 1.38, when div_euclid and rem_euclid where introduced.
The profile (release or debug) makes no difference.
The results of
SIGNED_INT::div_euclidandSIGNED_INT::rem_euclidare always incorrect whena % b != 0 && a.is_negative()(whereais the dividend andbis the divisor).I tried something similar to this code:
I expected to see this happen:
The assert should not fire.
Instead, this happened:
The assert fired. The return value is
(2, 32766)instead of(1, 1).More general test case on playground
Meta
This bug exists in the latest stable, beta and nightly.
The bug appears to have been present since 1.38, when
div_euclidandrem_euclidwhere introduced.The profile (release or debug) makes no difference.