diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index 7b989428c..267f4c990 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -1296,8 +1296,6 @@ class MathTests(unittest.TestCase): self.ftest('radians(-45)', math.radians(-45), -math.pi/4) self.ftest('radians(0)', math.radians(0), 0) - # TODO: RUSTPYTHON - @unittest.expectedFailure @requires_IEEE_754 def testRemainder(self): from fractions import Fraction diff --git a/vm/src/stdlib/math.rs b/vm/src/stdlib/math.rs index 00597bed1..1b062ca16 100644 --- a/vm/src/stdlib/math.rs +++ b/vm/src/stdlib/math.rs @@ -678,9 +678,10 @@ fn math_fmod(x: IntoPyFloat, y: IntoPyFloat, vm: &VirtualMachine) -> PyResult PyResult { let x = x.to_f64(); let y = y.to_f64(); + if x.is_finite() && y.is_finite() { if y == 0.0 { - return Ok(std::f64::NAN); + return Err(vm.new_value_error("math domain error".to_owned())); } let absx = x.abs(); @@ -696,20 +697,17 @@ fn math_remainder(x: IntoPyFloat, y: IntoPyFloat, vm: &VirtualMachine) -> PyResu return Ok(1.0_f64.copysign(x) * r); } - - if x.is_nan() { - return Ok(x); - } - if y.is_nan() { - return Ok(y); - } - if x.is_infinite() { - return Ok(std::f64::NAN); - } - if y.is_infinite() { + if x.is_infinite() && !y.is_nan() { return Err(vm.new_value_error("math domain error".to_owned())); } - Ok(x) + if x.is_nan() || y.is_nan() { + return Ok(f64::NAN); + } + if y.is_infinite() { + Ok(x) + } else { + Err(vm.new_value_error("math domain error".to_owned())) + } } #[derive(FromArgs)]