Skip to content

Commit 9f462d1

Browse files
Handle edge case values for abstol and span with ITP (#749)
Co-authored-by: Oscar Smith <[email protected]>
1 parent 68dea21 commit 9f462d1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/BracketingNonlinearSolve/src/itp.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,13 @@ function SciMLBase.__solve(
9696
span = right - left
9797
k1 = alg.scaled_k1 * span^(1 - k2) # k1 > 0
9898
n0 = alg.n0
99-
n_h = exponent(span / (2 * ϵ))
100-
ϵ_s = ϵ * exp2(n_h + n0)
99+
if span / 2 > ϵ * floatmax(typeof(span))
100+
# Workaround for when span / (2 * ϵ) == Inf
101+
ϵ_s = span / 2 * exp2(n0)
102+
else
103+
n_h = exponent(span / (2 * ϵ))
104+
ϵ_s = ϵ * exp2(n_h) * exp2(n0)
105+
end
101106
T0 = zero(fl)
102107

103108
i = 1

lib/BracketingNonlinearSolve/test/rootfind_tests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ end
7474
@test result_tol > ϵ
7575
end
7676
end
77+
78+
# Some solvers support abstol=0.0 and converge to floating point precision
79+
@testset for alg in (Bisection(), ITP(), Brent())
80+
sol = solve(prob, alg; abstol = 0.0)
81+
# Test that solution is to floating point precision
82+
@test sol.retcode == ReturnCode.FloatingPointLimit
83+
@test quadratic_f(sol.left, 2.0) < 0
84+
@test quadratic_f(sol.right, 2.0) > 0
85+
@test nextfloat(sol.left) == sol.right
86+
end
7787
end
7888

7989
@testitem "Flipped Signs and Reversed Tspan" setup=[RootfindingTestSnippet] tags=[:core] begin

0 commit comments

Comments
 (0)