Overflow is encountered during and innocent looking linear interpolation/extrapolation:
Interpolate linearly two points (1,1) and (10000,10000) and then find the value at 10001 by linear extrapolation.
The following code does it
julia> itpi = LinearInterpolation([1,10000],[1,10000]; extrapolation_bc=Line())
2-element extrapolate(interpolate((::Vector{Int64},), ::Vector{Int64}, Gridded(Linear())), Line()) with element type Float64:
Ratios.SimpleRatio{Int64}(99980001, 99980001)
Ratios.SimpleRatio{Int64}(999800010000, 99980001)
julia> convert(Float64,itpi(10001))
773.9376918087789
The result is clearly incorrect because the correct answer is 10001. Looking at the displayed ratios, I guess that an integer overflow is what happened here. There are no problems with smaller numbers:
julia> itp = LinearInterpolation([1,2],[1,2]; extrapolation_bc=Line())
2-element extrapolate(interpolate((::Vector{Int64},), ::Vector{Int64}, Gridded(Linear())), Line()) with element type Float64:
Ratios.SimpleRatio{Int64}(1, 1)
Ratios.SimpleRatio{Int64}(2, 1)
julia> convert(Float64,itp(3))
3.0
or with the floating point data:
julia> itpf = LinearInterpolation([1.0,10000.0],[1.0,10000.0]; extrapolation_bc=Line())
2-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Line()) with element type Float64:
1.0
10000.0
julia> convert(Float64,itpf(10001.0))
10001.0
I am hesitating if this should be regarded (and filed) as an Issue. In general the responsibility for the overflow problems is on the application programmer, right? But shouldn’t the interpolation function give some warning here? The parameters of the problem look innocent, don’t they?
Overflow is encountered during and innocent looking linear interpolation/extrapolation:
The result is clearly incorrect because the correct answer is 10001. Looking at the displayed ratios, I guess that an integer overflow is what happened here. There are no problems with smaller numbers:
or with the floating point data:
I am hesitating if this should be regarded (and filed) as an Issue. In general the responsibility for the overflow problems is on the application programmer, right? But shouldn’t the interpolation function give some warning here? The parameters of the problem look innocent, don’t they?