summaryrefslogtreecommitdiffstatshomepage
path: root/py/objcomplex.c
diff options
context:
space:
mode:
authorAndrew Leech <andrew.leech@planetinnovation.com.au>2022-07-04 17:35:46 +1000
committerDamien George <damien@micropython.org>2022-07-25 14:23:34 +1000
commit1e87b56219c69306d77a887cac3d29146180f113 (patch)
treec2e0dd58749e4ec4644407660a73d7db3201d940 /py/objcomplex.c
parentfa15aed0f718562871288aa174e91507a134db28 (diff)
downloadmicropython-1e87b56219c69306d77a887cac3d29146180f113.tar.gz
micropython-1e87b56219c69306d77a887cac3d29146180f113.zip
py/obj: Add support for __float__ and __complex__ functions.
Diffstat (limited to 'py/objcomplex.c')
-rw-r--r--py/objcomplex.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/py/objcomplex.c b/py/objcomplex.c
index 157617e156..3c4cb66140 100644
--- a/py/objcomplex.c
+++ b/py/objcomplex.c
@@ -88,6 +88,10 @@ STATIC mp_obj_t complex_make_new(const mp_obj_type_t *type_in, size_t n_args, si
// a complex, just return it
return args[0];
} else {
+ mp_float_t real, imag;
+ if (mp_obj_get_complex_maybe(args[0], &real, &imag)) {
+ return mp_obj_new_complex(real, imag);
+ }
// something else, try to cast it to a complex
return mp_obj_new_complex(mp_obj_get_float(args[0]), 0);
}