You've already forked Core2forAWS-MicroPython
mirror of
https://github.com/m5stack/Core2forAWS-MicroPython.git
synced 2026-05-20 10:30:31 -07:00
33 lines
597 B
Python
33 lines
597 B
Python
# test basic complex number functionality
|
|
|
|
# constructor
|
|
print(complex(1))
|
|
print(complex(1.2))
|
|
print(complex(1.2j))
|
|
print(complex("1"))
|
|
print(complex("1.2"))
|
|
print(complex("1.2j"))
|
|
print(complex(1, 2))
|
|
print(complex(1j, 2j))
|
|
|
|
# unary ops
|
|
print(bool(1j))
|
|
print(+(1j))
|
|
print(-(1 + 2j))
|
|
|
|
# binary ops
|
|
print(1j + 2)
|
|
print(1j + 2j)
|
|
print(1j - 2)
|
|
print(1j - 2j)
|
|
print(1j * 2)
|
|
print(1j * 2j)
|
|
print(1j / 2)
|
|
print(1j / (1 + 2j))
|
|
ans = 1j ** 2.5; print("%.5g %.5g" % (ans.real, ans.imag))
|
|
ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag))
|
|
|
|
# builtin abs
|
|
print(abs(1j))
|
|
print("%.5g" % abs(1j + 2))
|