mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
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:
2
Lib/test/test_math.py
vendored
2
Lib/test/test_math.py
vendored
@@ -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]:
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user