Reputation: 105
I have a problem in Julia, when the array length is variable and contains a division.
For example
length_of_array = n * (n + 1) / 2
array = Array{Float64,1}(length_of_array)
It returns an error related to "convert".
Thank you for your time.
Upvotes: 1
Views: 92
Reputation: 12644
You can only use integers to index into arrays. Division, /
, always returns floats, hence the error. Instead of /
, use the div
function. You can also use the unicode operator, ÷
, like this
length_of_array = (n * (n + 1)) ÷ 2
Upvotes: 1