mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Merge pull request #2263 from hyperbora/fix-math-acos-and-asin
fix math.acos and math.asin
This commit is contained in:
@@ -249,7 +249,6 @@ class MathTests(unittest.TestCase):
|
||||
self.ftest('e', math.e, 2.718281828459045235360287)
|
||||
self.assertEqual(math.tau, 2*math.pi)
|
||||
|
||||
@unittest.skip('TODO: RUSTPYTHON')
|
||||
def testAcos(self):
|
||||
self.assertRaises(TypeError, math.acos)
|
||||
self.ftest('acos(-1)', math.acos(-1), math.pi)
|
||||
@@ -272,7 +271,6 @@ class MathTests(unittest.TestCase):
|
||||
self.assertRaises(ValueError, math.acosh, NINF)
|
||||
self.assertTrue(math.isnan(math.acosh(NAN)))
|
||||
|
||||
@unittest.skip('TODO: RUSTPYTHON')
|
||||
def testAsin(self):
|
||||
self.assertRaises(TypeError, math.asin)
|
||||
self.ftest('asin(-1)', math.asin(-1), -math.pi/2)
|
||||
|
||||
@@ -136,8 +136,24 @@ fn math_sqrt(value: IntoPyFloat, vm: &VirtualMachine) -> PyResult<f64> {
|
||||
}
|
||||
|
||||
// Trigonometric functions:
|
||||
make_math_func!(math_acos, acos);
|
||||
make_math_func!(math_asin, asin);
|
||||
fn math_acos(x: IntoPyFloat, vm: &VirtualMachine) -> PyResult<f64> {
|
||||
let x = x.to_f64();
|
||||
if x.is_nan() || (-1.0_f64..=1.0_f64).contains(&x) {
|
||||
Ok(x.acos())
|
||||
} else {
|
||||
Err(vm.new_value_error("math domain error".to_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
fn math_asin(x: IntoPyFloat, vm: &VirtualMachine) -> PyResult<f64> {
|
||||
let x = x.to_f64();
|
||||
if x.is_nan() || (-1.0_f64..=1.0_f64).contains(&x) {
|
||||
Ok(x.asin())
|
||||
} else {
|
||||
Err(vm.new_value_error("math domain error".to_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
make_math_func!(math_atan, atan);
|
||||
|
||||
fn math_atan2(y: IntoPyFloat, x: IntoPyFloat) -> f64 {
|
||||
|
||||
Reference in New Issue
Block a user