An Int will be automatically converted to for example Float64 if you try to 
assign an int to a Float64 array.

julia> a = Float64[1.0, 2.0]
2-element Array{Float64,1}:
 1.0
 2.0

julia> a[2] = 3
3

julia> a
2-element Array{Float64,1}:
 1.0
 3.0



On Thursday, January 7, 2016 at 4:20:55 PM UTC+1, [email protected] wrote:
>
>
>
> Le jeudi 7 janvier 2016 16:15:56 UTC+1, Kristoffer Carlsson a écrit :
>>
>> Not sure why it promotes to Any but anyway, you most likely want to use x 
>> = Float64[1.0, 2.0] or another concrete Real type unless you plan to mix 
>> the type of the items in the array.
>>
>
>> The type Real is an abstract type and anyone is free to define a new type 
>> that is a subtype of Real. The compiler can therefore to no assumptions at 
>> all about what items will be in the array so if you care about performance 
>> you should use a concrete type.
>>
>  
> Yes that was the idea, more precisely the user is likely to give either 
> Int or Float64 in this Array. So I guess I need to use only Array{Float64} 
> and convert any possible Int given by the user to a Float64.
>

Reply via email to