Skip to content

Commit dcc8043

Browse files
authored
Merge pull request #3037 from owljoa/fix-math-remainder-test
Fix failed test remainder in test_math
2 parents 478dce5 + 516df29 commit dcc8043

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

Lib/test/test_math.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,6 @@ def testRadians(self):
12961296
self.ftest('radians(-45)', math.radians(-45), -math.pi/4)
12971297
self.ftest('radians(0)', math.radians(0), 0)
12981298

1299-
# TODO: RUSTPYTHON
1300-
@unittest.expectedFailure
13011299
@requires_IEEE_754
13021300
def testRemainder(self):
13031301
from fractions import Fraction

vm/src/stdlib/math.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,10 @@ fn math_fmod(x: IntoPyFloat, y: IntoPyFloat, vm: &VirtualMachine) -> PyResult<f6
678678
fn math_remainder(x: IntoPyFloat, y: IntoPyFloat, vm: &VirtualMachine) -> PyResult<f64> {
679679
let x = x.to_f64();
680680
let y = y.to_f64();
681+
681682
if x.is_finite() && y.is_finite() {
682683
if y == 0.0 {
683-
return Ok(std::f64::NAN);
684+
return Err(vm.new_value_error("math domain error".to_owned()));
684685
}
685686

686687
let absx = x.abs();
@@ -696,20 +697,17 @@ fn math_remainder(x: IntoPyFloat, y: IntoPyFloat, vm: &VirtualMachine) -> PyResu
696697

697698
return Ok(1.0_f64.copysign(x) * r);
698699
}
699-
700-
if x.is_nan() {
701-
return Ok(x);
702-
}
703-
if y.is_nan() {
704-
return Ok(y);
700+
if x.is_infinite() && !y.is_nan() {
701+
return Err(vm.new_value_error("math domain error".to_owned()));
705702
}
706-
if x.is_infinite() {
707-
return Ok(std::f64::NAN);
703+
if x.is_nan() || y.is_nan() {
704+
return Ok(f64::NAN);
708705
}
709706
if y.is_infinite() {
710-
return Err(vm.new_value_error("math domain error".to_owned()));
707+
Ok(x)
708+
} else {
709+
Err(vm.new_value_error("math domain error".to_owned()))
711710
}
712-
Ok(x)
713711
}
714712

715713
#[derive(FromArgs)]

0 commit comments

Comments
 (0)