MCPcopy Index your code
hub / github.com/RustPython/RustPython / inner_pow

Function inner_pow

crates/vm/src/builtins/complex.rs:153–171  ·  view source on GitHub ↗
(v1: Complex64, v2: Complex64, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

151}
152
153fn inner_pow(v1: Complex64, v2: Complex64, vm: &VirtualMachine) -> PyResult<Complex64> {
154 if v1.is_zero() {
155 return if v2.re < 0.0 || v2.im != 0.0 {
156 let msg = format!("{v1} cannot be raised to a negative or complex power");
157 Err(vm.new_zero_division_error(msg))
158 } else if v2.is_zero() {
159 Ok(Complex64::new(1.0, 0.0))
160 } else {
161 Ok(Complex64::new(0.0, 0.0))
162 };
163 }
164
165 let ans = powc(v1, v2);
166 if ans.is_infinite() && !(v1.is_infinite() || v2.is_infinite()) {
167 Err(vm.new_overflow_error("complex exponentiation overflow"))
168 } else {
169 Ok(ans)
170 }
171}
172
173// num-complex changed their powc() implementation in 0.4.4, making it incompatible
174// with what the regression tests expect. this is that old formula.

Callers

nothing calls this directly

Calls 5

newFunction · 0.85
powcFunction · 0.85
ErrClass · 0.50
is_zeroMethod · 0.45
is_infiniteMethod · 0.45

Tested by

no test coverage detected