mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 20:20:14 +01:00
py/parsenum: Support parsing complex numbers of the form "a+bj".
To conform with CPython. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
committed by
Damien George
parent
7861eddd0f
commit
0172292762
@@ -7,6 +7,11 @@ print(complex(1.2j))
|
||||
print(complex("1"))
|
||||
print(complex("1.2"))
|
||||
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, 2))
|
||||
print(complex(1j, 2j))
|
||||
|
||||
@@ -72,6 +77,13 @@ print(float("-nan") * 1j)
|
||||
print(float("inf") * (1 + 1j))
|
||||
print(float("-inf") * (1 + 1j))
|
||||
|
||||
# malformed complex strings
|
||||
for test in ("1+2", "1j+2", "1+2j+3", "1+2+3j", "1 + 2j"):
|
||||
try:
|
||||
complex(test)
|
||||
except ValueError:
|
||||
print("ValueError", test)
|
||||
|
||||
# can't assign to attributes
|
||||
try:
|
||||
(1j).imag = 0
|
||||
|
||||
Reference in New Issue
Block a user