mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
Fix mod_
This commit is contained in:
1 parent
62aa942bf5
commit
9e8e5a1e81
1 file changed
+5
-4
@@ -336,11 +336,12 @@ pub fn div(v1: f64, v2: f64) -> Option<f64> {
|
||||
|
||||
pub fn mod_(v1: f64, v2: f64) -> Option<f64> {
|
||||
if v2 != 0.0 {
|
||||
let mut val = v1 % v2;
|
||||
if (val < 0.0) != (v2 < 0.0) {
|
||||
val += v2;
|
||||
let val = v1 % v2;
|
||||
match (v1.signum() as i32, v2.signum() as i32) {
|
||||
(1, 1) | (-1, -1) => Some(val),
|
||||
_ if (v1 == 0.0) || (v1.abs() == v2.abs()) => Some(val.copysign(v2)),
|
||||
_ => Some((val + v2).copysign(v2)),
|
||||
}
|
||||
Some(val)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user