Array index math to be Int64


#1

Hi
I am trying to fill in an array such that information in in the middle. However, I find that I need to cast the Rational (or even Real for that matter) into an Int64 before I can actually use it to index into the array.

Any way I can do this better / avoid the ugly casts.

bump = (2/3 - 1/3 * cos.(ω * tInput))
inputSignal = zeros(t)
startIdx =  Int64(length(t)//2 - length(tInput)//2)
inputSignal[startIdx:startIdx + length(tInput) - 1] = bump

Cheers!
J


#2
julia> div(13,2),typeof(div(13,2))
(6, Int64)
# same thing, but prettier:
julia> 13÷2,typeof(13÷2)
(6, Int64)

If you already looked in the manual but didn’t see this, please suggest where elaboration would seem helpful (or better, file an issue/PR).

One can also use round or bit-shifts, but div seems cleanest here.