Question about `exp` with imaginary argument

I do not understand the result in the second case

julia> exp(2π/3 * 1im)
-0.4999999999999998 + 0.8660254037844387im
julia> exp(2π/3im)
-0.4999999999999998 - 0.8660254037844387im
julia> cis(2π/3)
-0.4999999999999998 + 0.8660254037844387im

Why there is a minus sign for the imag part ? :thinking:

This has nothing to do with exp, but with what you’re passing as argument:

julia> 2π/3im
0.0 - 2.0943951023931953im

julia> 2π/3 * im
0.0 + 2.0943951023931953im

juxtaposition has higher precedence than /, 2π/3im is (2 * π) / (3 * im), not (2 * π / 3) * im. My perhaps controversial suggestion is to avoid it if you don’t want surprises, as cute as it is.

5 Likes

thanks!