Open flamingowrangler2869 opened 1 year ago
Partially solved by making my own complex power function:
def cpow(z,n): # z^n where z ∈ ℂ, n ∈ ℤ
re = z.real
im = z.imag
r = sqrt(re**2 + im**2) # magnitude of z
c = atan(im/re) # angle of z
y = r**n * (cos(n*c)+sin(n*c)*1j) # r^n ⋅ (cos(nc)+isin(nc))
return y
cpow(2+3j, 2)
= -5.00000038632+11.9999998424j
≈ -5+12i = (2+3i)²
Native python
pow()
can take complex numbers:>>> pow((0+1j), 2)
squaring i(-1+0j)
results in -1However, processing's
pow()
cannot, and thusprint(pow((0+1j), 2))
exact same function but in a print function results in nothing being printed and nothing else after that line will be runAnd it's not
print()
's fault, becauseprint(complex(1,1))
results in(1+1j)
and everything after is run