diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index 6b421bc55..c90c063cd 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -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]: diff --git a/stdlib/src/math.rs b/stdlib/src/math.rs index b2437563a..c8e0c12b5 100644 --- a/stdlib/src/math.rs +++ b/stdlib/src/math.rs @@ -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 { + 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]