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.

thanks!

That is exactly the reason why I never do 2x. Yes, I know it looks neat and there are many topics discussing this and I know that the core julia devs like/love this feature and defend it, but I make enough confusion in my code on my own, don’t need help from outside :smiley:

Fair enough, being consistent is key.

Would it be a good idea to make the precendence of implicit multiplication lower than most explicit operators? That should be more intuitive. E.g. 1/2e would be 1/(2e) instead of (1/2)e? I’m not sure of the implementation difficulty though.

Isn’t the whole point of this thread that 1/2e is 1/(2e)?

As others have mentioned, it’s debatable whether the current behavior of juxtaposition was a good choice or not. But even if most people were to agree that a different behavior would be better, it would break a lot of existing code. So realistically, it’s not going to be changed.

This is an older post, sir, but it checks out:

Realisticly yes, that’s very true. I still have some hope that maybe a certain major version would allow breaking changes, somehow still supporting old code, although chances are extremely slim. Even that post is from 6 years ago… It’s a bit sad.