Skip to content

Commit 2ce63b1

Browse files
jeplerComplexSymbol
authored andcommitted
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 <jepler@gmail.com>
1 parent 0a98f3a commit 2ce63b1

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

py/parsenum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ mp_obj_t mp_parse_num_float(const char *str, size_t len, bool allow_imag, mp_lex
227227

228228
const char *top = str + len;
229229
mp_float_t dec_val = 0;
230-
bool dec_neg = false;
231230

232231
#if MICROPY_PY_BUILTINS_COMPLEX
233232
unsigned int real_imag_state = REAL_IMAG_STATE_START;
234233
mp_float_t dec_real = 0;
235-
parse_start:
234+
parse_start:;
236235
#endif
236+
bool dec_neg = false;
237237

238238
// skip leading space
239239
for (; str < top && unichar_isspace(*str); str++) {

tests/float/complex1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
print(complex("1+j"))
1313
print(complex("1+2j"))
1414
print(complex("-1-2j"))
15+
print(complex("-1+2j"))
1516
print(complex("+1-2j"))
1617
print(complex(" -1-2j "))
1718
print(complex(" +1-2j "))
19+
print(complex(" -1+2j "))
1820
print(complex("nanj"))
1921
print(complex("nan-infj"))
2022
print(complex(1, 2))

0 commit comments

Comments
 (0)
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