Weird behavior in Complex Numbers

Hello, i am getting this behavior:

julia> a = 1.5 + 3//4im
1.5 - 0.75im

What I expected was:

julia> a = 1.5 + 3//4im
1.5 + 0.75im

Can any one tell me why?

try

julia> a = 1.5 + (3//4)im

2 Likes

Multiplication by juxtaposition has higher precedence than //, so what you’re actually computing is 3//(4im). You can see how an expression is lowered for example with:

julia> Meta.@lower 3//4im
:($(Expr(:thunk, CodeInfo(
1 ─ %1 = 4im
│   %2 = 3 // %1
└──      return %2
))))
5 Likes

And by /, it turns out. So you can write this, which is nice to know!

julia> 1/2π == 1/(2π)
true

Also:

julia> 1/2*π == 0.5π
true

julia> 1/2big(π) == 1/(2*big(π))
true
1 Like

Thank you. I can sleep in peace today :slight_smile: