Skip to content

Commit 490db0a

Browse files
author
Nicolas Trinquier
committed
Add support for complex type for the to_complex function
1 parent eebdbfe commit 490db0a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

vm/src/obj/objcomplex.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ impl PyComplexRef {
6767
}
6868

6969
fn to_complex(value: PyObjectRef, vm: &VirtualMachine) -> PyResult<Option<Complex64>> {
70-
if objtype::isinstance(&value, &vm.ctx.int_type()) {
70+
if objtype::isinstance(&value, &vm.ctx.complex_type()) {
71+
Ok(Some(get_value(&value)))
72+
} else if objtype::isinstance(&value, &vm.ctx.int_type()) {
7173
match objint::get_value(&value).to_f64() {
7274
Some(v) => Ok(Some(Complex64::new(v, 0.0))),
7375
None => Err(vm.new_overflow_error("int too large to convert to float".to_string())),

0 commit comments

Comments
 (0)