Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant use complex numbers in processing "pow()" function #371

Open
flamingowrangler2869 opened this issue Nov 26, 2022 · 1 comment
Open

Comments

@flamingowrangler2869
Copy link

Native python pow() can take complex numbers:
>>> pow((0+1j), 2) squaring i
(-1+0j) results in -1

However, processing's pow() cannot, and thus
print(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 run

And it's not print()'s fault, because
print(complex(1,1)) results in (1+1j) and everything after is run

@flamingowrangler2869
Copy link
Author

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)²

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant