Merge pull request #3037 from owljoa/fix-math-remainder-test

Fix failed test remainder in test_math
This commit is contained in:
Jeong YunWon
2021-09-12 00:12:12 +09:00
committed by GitHub
2 changed files with 11 additions and 15 deletions

View File

@@ -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

View File

@@ -678,9 +678,10 @@ fn math_fmod(x: IntoPyFloat, y: IntoPyFloat, vm: &VirtualMachine) -> PyResult<f6
fn math_remainder(x: IntoPyFloat, y: IntoPyFloat, vm: &VirtualMachine) -> PyResult<f64> {
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)]