Fix math.log1p to pass some failed tests

Now math.log1p with less than or equal to negative one should raise
ValueError with "math domain error" message
This commit is contained in:
Tetramad
2021-10-25 11:10:34 +09:00
parent 3d8f6cf08d
commit c88c69a993
2 changed files with 7 additions and 4 deletions

View File

@@ -1063,8 +1063,6 @@ class MathTests(unittest.TestCase):
self.assertEqual(math.log(INF), INF)
self.assertTrue(math.isnan(math.log(NAN)))
# TODO: RUSTPYTHON
@unittest.expectedFailure
def testLog1p(self):
self.assertRaises(TypeError, math.log1p)
for n in [2, 2**90, 2**300]:

View File

@@ -145,8 +145,13 @@ mod math {
}
#[pyfunction]
fn log1p(x: ArgIntoFloat) -> f64 {
(x.to_f64() + 1.0).ln()
fn log1p(x: ArgIntoFloat, vm: &VirtualMachine) -> PyResult<f64> {
let x = x.to_f64();
if x.is_nan() || x > -1.0_f64 {
Ok((x + 1.0_f64).ln())
} else {
Err(vm.new_value_error("math domain error".to_owned()))
}
}
#[pyfunction]