Skip to content

Commit aaae566

Browse files
authored
Raise error on power with negative number (RustPython#5143)
1 parent 28f0fa4 commit aaae566

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

Lib/test/test_complex.py

-2
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ def test_divmod_zero_division(self):
236236
for a, b in ZERO_DIVISION:
237237
self.assertRaises(TypeError, divmod, a, b)
238238

239-
# TODO: RUSTPYTHON
240-
@unittest.expectedFailure
241239
def test_pow(self):
242240
self.assertAlmostEqual(pow(1+1j, 0+0j), 1.0)
243241
self.assertAlmostEqual(pow(0+0j, 2+0j), 0.0)

vm/src/builtins/complex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn inner_div(v1: Complex64, v2: Complex64, vm: &VirtualMachine) -> PyResult<Comp
103103

104104
fn inner_pow(v1: Complex64, v2: Complex64, vm: &VirtualMachine) -> PyResult<Complex64> {
105105
if v1.is_zero() {
106-
return if v2.im != 0.0 {
106+
return if v2.re < 0.0 || v2.im != 0.0 {
107107
let msg = format!("{v1} cannot be raised to a negative or complex power");
108108
Err(vm.new_zero_division_error(msg))
109109
} else if v2.is_zero() {

0 commit comments

Comments
 (0)