From d808effab0354ae8f7f4663cbeaa2bad75d0c370 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 28 May 2025 20:49:29 +0200 Subject: [PATCH] py/parsenum: Fix parsing complex literals with negative real part. If a complex literal had a negative real part and a positive imaginary part, it was not parsed properly because the imaginary part also came out negative. Includes a test of complex parsing, which fails without this fix. Co-authored-by: ComplexSymbol <141301057+ComplexSymbol@users.noreply.github.com> Signed-off-by: Jeff Epler --- py/parsenum.c | 4 ++-- tests/float/complex1.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/py/parsenum.c b/py/parsenum.c index b7179acdf36ae..874216f08d005 100644 --- a/py/parsenum.c +++ b/py/parsenum.c @@ -228,13 +228,13 @@ mp_obj_t mp_parse_num_float(const char *str, size_t len, bool allow_imag, mp_lex const char *top = str + len; mp_float_t dec_val = 0; - bool dec_neg = false; #if MICROPY_PY_BUILTINS_COMPLEX unsigned int real_imag_state = REAL_IMAG_STATE_START; mp_float_t dec_real = 0; -parse_start: +parse_start:; #endif + bool dec_neg = false; // skip leading space for (; str < top && unichar_isspace(*str); str++) { diff --git a/tests/float/complex1.py b/tests/float/complex1.py index f4107a1390fee..0a1d98b9af3eb 100644 --- a/tests/float/complex1.py +++ b/tests/float/complex1.py @@ -12,9 +12,11 @@ print(complex("1+j")) print(complex("1+2j")) print(complex("-1-2j")) +print(complex("-1+2j")) print(complex("+1-2j")) print(complex(" -1-2j ")) print(complex(" +1-2j ")) +print(complex(" -1+2j ")) print(complex("nanj")) print(complex("nan-infj")) print(complex(1, 2)) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy