mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 11:40:18 +01:00
py/objfloat: Support raising a negative number to a fractional power.
This returns a complex number, following CPython behaviour. For ports that don't have complex numbers enabled this will raise a ValueError which gives a fail-safe for scripts that were written assuming complex numbers exist.
This commit is contained in:
@@ -53,6 +53,10 @@ print(type(hash(1j)))
|
||||
# float on lhs should delegate to complex
|
||||
print(1.2 + 3j)
|
||||
|
||||
# negative base and fractional power should create a complex
|
||||
ans = (-1) ** 2.3; print("%.5g %.5g" % (ans.real, ans.imag))
|
||||
ans = (-1.2) ** -3.4; print("%.5g %.5g" % (ans.real, ans.imag))
|
||||
|
||||
# check printing of inf/nan
|
||||
print(float('nan') * 1j)
|
||||
print(float('inf') * (1 + 1j))
|
||||
|
||||
Reference in New Issue
Block a user