Skip to content

Commit 26c6ddb

Browse files
Merge pull request #2803 from SciML/fix-rational-int32-x86
Fix InexactError on X86 by using explicit Int64 in rational literals
2 parents de9ce8f + eb26d94 commit 26c6ddb

File tree

5 files changed

+54
-54
lines changed

5 files changed

+54
-54
lines changed

lib/OrdinaryDiffEqBDF/src/bdf_caches.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function alg_cache(alg::ABDF2, u, rate_prototype, ::Type{uEltypeNoUnits},
1515
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits},
1616
uprev, uprev2, f, t, dt, reltol, p, calck,
1717
::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
18-
γ, c = 2 // 3, 1
18+
γ, c = Int64(2) // 3, 1
1919
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits,
2020
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(false))
2121
eulercache = ImplicitEulerConstantCache(nlsolver)
@@ -45,7 +45,7 @@ function alg_cache(alg::ABDF2, u, rate_prototype, ::Type{uEltypeNoUnits},
4545
::Type{uBottomEltypeNoUnits},
4646
::Type{tTypeNoUnits}, uprev, uprev2, f, t, dt, reltol, p, calck,
4747
::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
48-
γ, c = 2 // 3, 1
48+
γ, c = Int64(2) // 3, 1
4949
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits,
5050
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true))
5151
fsalfirst = zero(rate_prototype)
@@ -104,7 +104,7 @@ function alg_cache(alg::SBDF, u, rate_prototype, ::Type{uEltypeNoUnits},
104104
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t,
105105
dt, reltol, p, calck,
106106
::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
107-
γ, c = 1 // 1, 1
107+
γ, c = Int64(1) // 1, 1
108108
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits,
109109
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(false))
110110

@@ -127,7 +127,7 @@ function alg_cache(alg::SBDF, u, rate_prototype, ::Type{uEltypeNoUnits},
127127
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t,
128128
dt, reltol, p, calck,
129129
::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
130-
γ, c = 1 // 1, 1
130+
γ, c = Int64(1) // 1, 1
131131
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits,
132132
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true))
133133
fsalfirst = zero(rate_prototype)
@@ -360,7 +360,7 @@ function alg_cache(alg::QNDF{MO}, u, rate_prototype, ::Type{uEltypeNoUnits},
360360
::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits
361361
} where {MO}
362362
max_order = MO
363-
γ, c = 1//1, 1
363+
γ, c = Int64(1)//1, 1
364364
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits,
365365
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(false))
366366
dtprev = one(dt)
@@ -380,7 +380,7 @@ function alg_cache(alg::QNDF{MO}, u, rate_prototype, ::Type{uEltypeNoUnits},
380380
end
381381
U = SArray(U)
382382

383-
γₖ = SVector(ntuple(k -> sum(tTypeNoUnits(1 // j) for j in 1:k), Val(max_order)))
383+
γₖ = SVector(ntuple(k -> sum(tTypeNoUnits(Int64(1) // j) for j in 1:k), Val(max_order)))
384384

385385
QNDFConstantCache(nlsolver, U, D, prevD, 1, 1, Val(max_order), dtprev, 0, 0, EEst1,
386386
EEst2, γₖ)
@@ -426,7 +426,7 @@ function alg_cache(alg::QNDF{MO}, u, rate_prototype, ::Type{uEltypeNoUnits},
426426
::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits
427427
} where {MO}
428428
max_order = MO
429-
γ, c = 1//1, 1
429+
γ, c = Int64(1)//1, 1
430430
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits,
431431
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true))
432432
fsalfirst = zero(rate_prototype)
@@ -459,7 +459,7 @@ function alg_cache(alg::QNDF{MO}, u, rate_prototype, ::Type{uEltypeNoUnits},
459459
U = SArray(U)
460460

461461
RU = Matrix(U)
462-
γₖ = SVector(ntuple(k -> sum(tTypeNoUnits(1 // j) for j in 1:k), Val(max_order)))
462+
γₖ = SVector(ntuple(k -> sum(tTypeNoUnits(Int64(1) // j) for j in 1:k), Val(max_order)))
463463

464464
QNDFCache(fsalfirst, dd, utilde, utildem1, utildep1, ϕ, u₀, nlsolver, U, RU, D, Dtmp,
465465
tmp2, prevD, 1, 1, Val(max_order), dtprev, 0, 0, EEst1, EEst2, γₖ, atmp,
@@ -541,15 +541,15 @@ function alg_cache(alg::FBDF{MO}, u, rate_prototype, ::Type{uEltypeNoUnits},
541541
dt, reltol, p, calck,
542542
::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits
543543
} where {MO}
544-
γ, c = 1//1, 1
544+
γ, c = Int64(1)//1, 1
545545
max_order = MO
546546
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits,
547547
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(false))
548548
bdf_coeffs = SA[1 -1 0 0 0 0;
549-
3//2 -2 1//2 0 0 0;
550-
11//6 -3 3//2 -1//3 0 0;
551-
25//12 -4 3 -4//3 1//4 0;
552-
137//60 -5 5 -10//3 5//4 -1//5]
549+
Int64(3)//2 -2 Int64(1)//2 0 0 0;
550+
Int64(11)//6 -3 Int64(3)//2 -Int64(1)//3 0 0;
551+
Int64(25)//12 -4 3 -Int64(4)//3 Int64(1)//4 0;
552+
Int64(137)//60 -5 5 -Int64(10)//3 Int64(5)//4 -Int64(1)//5]
553553
ts = zero(Vector{typeof(t)}(undef, max_order + 2)) #ts is the successful past points, it will be updated after successful step
554554
ts_tmp = similar(ts)
555555

@@ -616,16 +616,16 @@ function alg_cache(alg::FBDF{MO}, u, rate_prototype, ::Type{uEltypeNoUnits},
616616
dt, reltol, p, calck,
617617
::Val{true}) where {MO, uEltypeNoUnits, uBottomEltypeNoUnits,
618618
tTypeNoUnits}
619-
γ, c = 1//1, 1
619+
γ, c = Int64(1)//1, 1
620620
fsalfirst = zero(rate_prototype)
621621
max_order = MO
622622
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits,
623623
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true))
624624
bdf_coeffs = SA[1 -1 0 0 0 0;
625-
3//2 -2 1//2 0 0 0;
626-
11//6 -3 3//2 -1//3 0 0;
627-
25//12 -4 3 -4//3 1//4 0;
628-
137//60 -5 5 -10//3 5//4 -1//5]
625+
Int64(3)//2 -2 Int64(1)//2 0 0 0;
626+
Int64(11)//6 -3 Int64(3)//2 -Int64(1)//3 0 0;
627+
Int64(25)//12 -4 3 -Int64(4)//3 Int64(1)//4 0;
628+
Int64(137)//60 -5 5 -Int64(10)//3 Int64(5)//4 -Int64(1)//5]
629629
ts = Vector{typeof(t)}(undef, max_order + 2) #ts is the successful past points, it will be updated after successful step
630630
u_history = Matrix{eltype(u)}(undef, length(u), max_order + 2)
631631
order = 1

lib/OrdinaryDiffEqBDF/src/bdf_perform_step.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ end
2727

2828
fₙ₋₁ = integrator.fsalfirst
2929
ρ = dtₙ / dtₙ₋₁
30-
β₀ = 2 // 3
30+
β₀ = Int64(2) // 3
3131
β₁ = -- 1) / 3
3232
α₀ = 1
3333
α̂ = ρ^2 / 3
@@ -113,7 +113,7 @@ end
113113

114114
fₙ₋₁ = integrator.fsalfirst
115115
ρ = dtₙ / dtₙ₋₁
116-
β₀ = 2 // 3
116+
β₀ = Int64(2) // 3
117117
β₁ = -- 1) / 3
118118
α₀ = 1
119119
α̂ = ρ^2 / 3
@@ -152,7 +152,7 @@ end
152152
f(integrator.fsallast, uₙ, p, t + dtₙ)
153153
OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1)
154154
if integrator.opts.adaptive
155-
btilde0 = (dtₙ₋₁ + dtₙ) * 1 // 6
155+
btilde0 = (dtₙ₋₁ + dtₙ) * Int64(1) // 6
156156
btilde1 = 1 + dtₙ / dtₙ₋₁
157157
btilde2 = dtₙ / dtₙ₋₁
158158
@.. broadcast=false tmp=btilde0*
@@ -207,12 +207,12 @@ function perform_step!(integrator, cache::SBDFConstantCache, repeat_step = false
207207
if cnt == 1
208208
tmp = uprev + dt * du₂
209209
elseif cnt == 2
210-
tmp = γ * (2 * uprev - 1 // 2 * uprev2 + dt * (2 * du₂ - k₁))
210+
tmp = γ * (2 * uprev - Int64(1) // 2 * uprev2 + dt * (2 * du₂ - k₁))
211211
elseif cnt == 3
212212
tmp = γ *
213-
(3 * uprev - 3 // 2 * uprev2 + 1 // 3 * uprev3 + dt * (3 * (du₂ - k₁) + k₂))
213+
(3 * uprev - Int64(3) // 2 * uprev2 + Int64(1) // 3 * uprev3 + dt * (3 * (du₂ - k₁) + k₂))
214214
else
215-
tmp = γ * (4 * uprev - 3 * uprev2 + 4 // 3 * uprev3 - 1 // 4 * uprev4 +
215+
tmp = γ * (4 * uprev - 3 * uprev2 + Int64(4) // 3 * uprev3 - Int64(1) // 4 * uprev4 +
216216
dt * (4 * du₂ - 6 * k₁ + 4 * k₂ - k₃))
217217
end
218218
nlsolver.tmp = tmp
@@ -513,21 +513,21 @@ function perform_step!(integrator, cache::QNDF2ConstantCache, repeat_step = fals
513513
k = 2
514514
if cnt == 1 || cnt == 2
515515
κ = zero(alg.kappa)
516-
γ₁ = 1 // 1
517-
γ₂ = 1 // 1
516+
γ₁ = Int64(1) // 1
517+
γ₂ = Int64(1) // 1
518518
elseif dtₙ₋₁ != dtₙ₋₂
519519
κ = alg.kappa
520-
γ₁ = 1 // 1
521-
γ₂ = 1 // 1 + 1 // 2
520+
γ₁ = Int64(1) // 1
521+
γ₂ = Int64(1) // 1 + Int64(1) // 2
522522
ρ₁ = dt / dtₙ₋₁
523523
ρ₂ = dt / dtₙ₋₂
524524
D[1] = uprev - uprev2
525525
D[1] = D[1] * ρ₁
526526
D[2] = D[1] - ((uprev2 - uprev3) * ρ₂)
527527
else
528528
κ = alg.kappa
529-
γ₁ = 1 // 1
530-
γ₂ = 1 // 1 + 1 // 2
529+
γ₁ = Int64(1) // 1
530+
γ₂ = Int64(1) // 1 + Int64(1) // 2
531531
ρ = dt / dtₙ₋₁
532532
# backward diff
533533
D[1] = uprev - uprev2
@@ -623,21 +623,21 @@ function perform_step!(integrator, cache::QNDF2Cache, repeat_step = false)
623623
k = 2
624624
if cnt == 1 || cnt == 2
625625
κ = zero(alg.kappa)
626-
γ₁ = 1 // 1
627-
γ₂ = 1 // 1
626+
γ₁ = Int64(1) // 1
627+
γ₂ = Int64(1) // 1
628628
elseif dtₙ₋₁ != dtₙ₋₂
629629
κ = alg.kappa
630-
γ₁ = 1 // 1
631-
γ₂ = 1 // 1 + 1 // 2
630+
γ₁ = Int64(1) // 1
631+
γ₂ = Int64(1) // 1 + Int64(1) // 2
632632
ρ₁ = dt / dtₙ₋₁
633633
ρ₂ = dt / dtₙ₋₂
634634
@.. broadcast=false D[1]=uprev-uprev2
635635
@.. broadcast=false D[1]=D[1]*ρ₁
636636
@.. broadcast=false D[2]=D[1]-((uprev2-uprev3)*ρ₂)
637637
else
638638
κ = alg.kappa
639-
γ₁ = 1 // 1
640-
γ₂ = 1 // 1 + 1 // 2
639+
γ₁ = Int64(1) // 1
640+
γ₂ = Int64(1) // 1 + Int64(1) // 2
641641
ρ = dt / dtₙ₋₁
642642
# backward diff
643643
@.. broadcast=false D[1]=uprev-uprev2

lib/OrdinaryDiffEqBDF/src/bdf_utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function update_D!(D, dd, k)
9090
return nothing
9191
end
9292

93-
const γₖ = @SVector[sum(1 // j for j in 1:k) for k in 1:6]
93+
const γₖ = @SVector[sum(Int64(1) // j for j in 1:k) for k in 1:6]
9494

9595
function error_constant(integrator, alg::QNDF, k)
9696
@unpack γₖ = integrator.cache

lib/OrdinaryDiffEqBDF/src/dae_caches.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ function alg_cache(alg::DABDF2, du, u, res_prototype, rate_prototype,
6363
::Type{tTypeNoUnits},
6464
uprev, uprev2, f, t, dt, reltol, p, calck,
6565
::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
66-
γ, c = 1 // 1, 1
67-
α = 1 // 1
66+
γ, c = Int64(1) // 1, 1
67+
α = Int64(1) // 1
6868
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, res_prototype, uEltypeNoUnits,
6969
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, α, Val(false))
7070
eulercache = DImplicitEulerConstantCache(nlsolver)
@@ -92,8 +92,8 @@ function alg_cache(alg::DABDF2, du, u, res_prototype, rate_prototype,
9292
::Type{uEltypeNoUnits}, ::Type{uBottomEltypeNoUnits},
9393
::Type{tTypeNoUnits}, uprev, uprev2, f, t, dt, reltol, p, calck,
9494
::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
95-
γ, c = 1 // 1, 1
96-
α = 1 // 1
95+
γ, c = Int64(1) // 1, 1
96+
α = Int64(1) // 1
9797
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, res_prototype, uEltypeNoUnits,
9898
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, α, Val(true))
9999
fsalfirst = zero(rate_prototype)
@@ -146,10 +146,10 @@ function alg_cache(alg::DFBDF{MO}, du, u, res_prototype, rate_prototype, uEltype
146146
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits,
147147
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(false))
148148
bdf_coeffs = SA[1 -1 0 0 0 0;
149-
2//3 -4//3 1//3 0 0 0;
150-
6//11 -18//11 9//11 -2//11 0 0;
151-
12//25 -48//25 36//25 -16//25 3//25 0;
152-
60//137 -300//137 300//137 -200//137 75//137 -12//137]
149+
Int64(2)//3 -Int64(4)//3 Int64(1)//3 0 0 0;
150+
Int64(6)//11 -Int64(18)//11 Int64(9)//11 -Int64(2)//11 0 0;
151+
Int64(12)//25 -Int64(48)//25 Int64(36)//25 -Int64(16)//25 Int64(3)//25 0;
152+
Int64(60)//137 -Int64(300)//137 Int64(300)//137 -Int64(200)//137 Int64(75)//137 -Int64(12)//137]
153153
ts = zero(Vector{typeof(t)}(undef, max_order + 2)) #ts is the successful past points, it will be updated after successful step
154154
ts_tmp = similar(ts)
155155

@@ -223,10 +223,10 @@ function alg_cache(alg::DFBDF{MO}, du, u, res_prototype, rate_prototype, uEltype
223223
25//12 -4 3 -4//3 1//4 0 ;
224224
137//60 -5 5 -10//3 5//4 -1//5]=#
225225
bdf_coeffs = SA[1 -1 0 0 0 0;
226-
2//3 -4//3 1//3 0 0 0;
227-
6//11 -18//11 9//11 -2//11 0 0;
228-
12//25 -48//25 36//25 -16//25 3//25 0;
229-
60//137 -300//137 300//137 -200//137 75//137 -12//137]
226+
Int64(2)//3 -Int64(4)//3 Int64(1)//3 0 0 0;
227+
Int64(6)//11 -Int64(18)//11 Int64(9)//11 -Int64(2)//11 0 0;
228+
Int64(12)//25 -Int64(48)//25 Int64(36)//25 -Int64(16)//25 Int64(3)//25 0;
229+
Int64(60)//137 -Int64(300)//137 Int64(300)//137 -Int64(200)//137 Int64(75)//137 -Int64(12)//137]
230230
ts = Vector{typeof(t)}(undef, max_order + 2) #ts is the successful past points, it will be updated after successful step
231231
u_history = Matrix{eltype(u)}(undef, length(u), max_order + 2)
232232
order = 1

lib/OrdinaryDiffEqBDF/src/dae_perform_step.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ end
122122
c1 = ρ^2 / (1 + 2ρ)
123123

124124
nlsolver.γ = (1 + ρ) / (1 + 2ρ)
125-
nlsolver.α = 1 // 1
125+
nlsolver.α = Int64(1) // 1
126126

127127
nlsolver.z = zero(uₙ)
128128

@@ -187,7 +187,7 @@ end
187187
c1 = ρ^2 / (1 + 2ρ)
188188

189189
nlsolver.γ = (1 + ρ) / (1 + 2ρ)
190-
nlsolver.α = 1 // 1
190+
nlsolver.α = Int64(1) // 1
191191
@.. broadcast=false nlsolver.tmp=-c1*uₙ₋₁+c1*uₙ₋₂
192192
nlsolver.z .= zero(eltype(z))
193193
z = nlsolve!(nlsolver, integrator, cache, repeat_step)
@@ -199,7 +199,7 @@ end
199199
@.. broadcast=false integrator.fsallast=du
200200
OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1)
201201
if integrator.opts.adaptive
202-
btilde0 = (dtₙ₋₁ + dtₙ) * 1 // 6
202+
btilde0 = (dtₙ₋₁ + dtₙ) * Int64(1) // 6
203203
btilde1 = 1 + ρ
204204
btilde2 = ρ
205205
@.. broadcast=false tmp=btilde0*
@@ -287,7 +287,7 @@ function perform_step!(integrator, cache::DFBDFConstantCache{max_order},
287287
nlsolver.tmp = tmp + cache.u₀
288288
nlsolver.z = zero(nlsolver.z)
289289
nlsolver.γ = bdf_coeffs[k, 1]
290-
nlsolver.α = 1 // 1
290+
nlsolver.α = Int64(1) // 1
291291
z = nlsolve!(nlsolver, integrator, cache, repeat_step)
292292
nlsolvefail(nlsolver) && return
293293
u = z + cache.u₀
@@ -403,7 +403,7 @@ function perform_step!(integrator, cache::DFBDFCache{max_order},
403403
@.. broadcast=false nlsolver.tmp=tmp+u₀
404404
@.. broadcast=false nlsolver.z=zero(eltype(nlsolver.z))
405405
nlsolver.γ = bdf_coeffs[k, 1]
406-
nlsolver.α = 1 // 1
406+
nlsolver.α = Int64(1) // 1
407407
z = nlsolve!(nlsolver, integrator, cache, repeat_step)
408408
nlsolvefail(nlsolver) && return
409409
@.. broadcast=false u=z+u₀

0 commit comments

Comments
 (0)