Hi,
I’m just getting started with Julia and I’ve read that Julia does automatic conversion and promotion of variables, thus
U = 0
U = U + 1im
works properly. However, the following code
U = zeros(4)
U[2] = 1im
gives the error
ERROR: InexactError: Float64(0 + 1im)
Stacktrace:
[1] Real at .\complex.jl:37 [inlined]
[2] convert at .\number.jl:7 [inlined]
[3] setindex!(::Array{Float64,1}, ::Complex{Int64}, ::Int64) at .\array.jl:847
[4] top-level scope at REPL[9]:1
and I do not understand why.
4 posts - 2 participants