Skip to content

Commit a1437a5

Browse files
committed
fix math.sqrt
1 parent 4f638ae commit a1437a5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Lib/test/test_math.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,6 @@ def testSinh(self):
14551455
self.assertEqual(math.sinh(NINF), NINF)
14561456
self.assertTrue(math.isnan(math.sinh(NAN)))
14571457

1458-
@unittest.skip('TODO: RUSTPYTHON')
14591458
def testSqrt(self):
14601459
self.assertRaises(TypeError, math.sqrt)
14611460
self.ftest('sqrt(0)', math.sqrt(0), 0)

vm/src/stdlib/math.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ fn math_pow(x: IntoPyFloat, y: IntoPyFloat) -> f64 {
127127
x.to_f64().powf(y.to_f64())
128128
}
129129

130-
make_math_func!(math_sqrt, sqrt);
130+
fn math_sqrt(value: IntoPyFloat, vm: &VirtualMachine) -> PyResult<f64> {
131+
let value = value.to_f64();
132+
if value.is_sign_negative() {
133+
return Err(vm.new_value_error("math domain error".to_owned()));
134+
}
135+
Ok(value.sqrt())
136+
}
131137

132138
// Trigonometric functions:
133139
make_math_func!(math_acos, acos);

0 commit comments

Comments
 (0)