StepRange and arithmetics


#1

in 0.7-beta2, StepRange + Number “rounds” differently than Vector + Number. Should I be surprised?

Example:

x = -10.0:0.1:5.0
z1 = x[1] + 10
z2 = x[1:2] .+ 10
z3 = collect(x[1:2]) .+ 10
println(z1," ",z2[1]," ",z3[1])

gives

0.0 5.127595883936577e-30 0.0

#2

Try looking at the types of the resulting values.


#3

OK, they are clearly Float64, StepRangeLen{Float64,…}, and Array{Float64} respectively.

I expected them to behave the same when used in simple computations (here plus 10), but that does not seem to be the case. Where can I read up on this?


#4

Ranges use higher precision internally. This was discussed in a few pull requests but I’m not at my computer right now.