@@ -20,17 +20,21 @@ function Bisection(; exact_left = false, exact_right = false)
2020end
2121
2222function SciMLBase. solve (prob:: IntervalNonlinearProblem , alg:: Bisection , args... ;
23- maxiters = 1000 ,
23+ maxiters = 1000 , abstol = min ( eps (prob . tspan[ 1 ]), eps (prob . tspan[ 2 ])),
2424 kwargs... )
2525 f = Base. Fix2 (prob. f, prob. p)
2626 left, right = prob. tspan
2727 fl, fr = f (left), f (right)
28-
2928 if iszero (fl)
3029 return SciMLBase. build_solution (prob, alg, left, fl;
3130 retcode = ReturnCode. ExactSolutionLeft, left = left,
3231 right = right)
3332 end
33+ if iszero (fr)
34+ return SciMLBase. build_solution (prob, alg, right, fr;
35+ retcode = ReturnCode. ExactSolutionRight, left = left,
36+ right = right)
37+ end
3438
3539 i = 1
3640 if ! iszero (fr)
@@ -41,6 +45,11 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Bisection, args...
4145 retcode = ReturnCode. FloatingPointLimit,
4246 left = left, right = right)
4347 fm = f (mid)
48+ if abs ((right - left) / 2 ) < abstol
49+ return SciMLBase. build_solution (prob, alg, mid, fm;
50+ retcode = ReturnCode. Success,
51+ left = left, right = right)
52+ end
4453 if iszero (fm)
4554 right = mid
4655 break
@@ -63,6 +72,11 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Bisection, args...
6372 retcode = ReturnCode. FloatingPointLimit,
6473 left = left, right = right)
6574 fm = f (mid)
75+ if abs ((right - left) / 2 ) < abstol
76+ return SciMLBase. build_solution (prob, alg, mid, fm;
77+ retcode = ReturnCode. Success,
78+ left = left, right = right)
79+ end
6680 if iszero (fm)
6781 right = mid
6882 fr = fm
0 commit comments