Skip to content

Commit e0e7c82

Browse files
authored
Merge pull request #10463 from dhalbert/complex-parsing-fix
py/parsenum: Fix parsing complex literals with negative real part
2 parents ce71e9e + d808eff commit e0e7c82

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
@@ -228,13 +228,13 @@ mp_obj_t mp_parse_num_float(const char *str, size_t len, bool allow_imag, mp_lex
228228

229229
const char *top = str + len;
230230
mp_float_t dec_val = 0;
231-
bool dec_neg = false;
232231

233232
#if MICROPY_PY_BUILTINS_COMPLEX
234233
unsigned int real_imag_state = REAL_IMAG_STATE_START;
235234
mp_float_t dec_real = 0;
236-
parse_start:
235+
parse_start:;
237236
#endif
237+
bool dec_neg = false;
238238

239239
// skip leading space
240240
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)