Skip to content

Commit c88c69a

Browse files
committed
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
1 parent 3d8f6cf commit c88c69a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Lib/test/test_math.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,8 +1063,6 @@ def testLog(self):
10631063
self.assertEqual(math.log(INF), INF)
10641064
self.assertTrue(math.isnan(math.log(NAN)))
10651065

1066-
# TODO: RUSTPYTHON
1067-
@unittest.expectedFailure
10681066
def testLog1p(self):
10691067
self.assertRaises(TypeError, math.log1p)
10701068
for n in [2, 2**90, 2**300]:

stdlib/src/math.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,13 @@ mod math {
145145
}
146146

147147
#[pyfunction]
148-
fn log1p(x: ArgIntoFloat) -> f64 {
149-
(x.to_f64() + 1.0).ln()
148+
fn log1p(x: ArgIntoFloat, vm: &VirtualMachine) -> PyResult<f64> {
149+
let x = x.to_f64();
150+
if x.is_nan() || x > -1.0_f64 {
151+
Ok((x + 1.0_f64).ln())
152+
} else {
153+
Err(vm.new_value_error("math domain error".to_owned()))
154+
}
150155
}
151156

152157
#[pyfunction]

0 commit comments

Comments
 (0)