There doesn’t seem to be an implementation for `atan`

when `x`

and `y`

are complex numbers. The currently implement `atan(y/x)`

is not a replacement, as it loses the information on which quadrants `x`

and `y`

are in.

This is important for spherical harmonics and converting to spherical coordinates in the complex domain.

One potential solution is the default Mathematica uses, which is to define:

atan(x::Complex,y::Complex) = - im * log( (x+y*im)/sqrt(x^2+y^2) )

You can test this does get the right quadrants with:

Using LinearAlgebra

maximum(

map(1:10000) do i

x = rand(-1.001:0.01:1.0) + rand(-1.001:0.01:1.0)*im

y = rand(-1.001:0.01:1.0) + rand(-1.001:0.01:1.0)im[cos(θ),sin(θ)] )

r = sqrt(x^2 + y^2) # note this is a complex number

θ = atan(y,x)

norm( [x,y] - r .

end

)

For several packages I now add this definition to use (what is in my field) standard coordinate transforms.