Skip to content

Commit 182f365

Browse files
committed
fix bisection to make it not return tprev
1 parent 608b806 commit 182f365

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/callbacks.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ end
567567
# rough implementation, needs multiple type handling
568568
# always ensures that if r = bisection(f, (x0, x1))
569569
# then either f(nextfloat(r)) == 0 or f(nextfloat(r)) * f(r) < 0
570-
function bisection(f, tup, tdir; maxiters=100)
570+
function bisection(f, tup, tdir; maxiters=100, noleft=false)
571571
x0, x1 = tup
572572
fx0x1 = f(x0) * f(x1)
573573
fzero = zero(fx0x1)
@@ -600,7 +600,7 @@ function bisection(f, tup, tdir; maxiters=100)
600600
end
601601
end
602602
end
603-
(left === mid || right === mid) && return left
603+
(left === mid || right === mid) && return ((left === tup[1]) && noleft ? right : left)
604604
if sign(y) === sign(f(left))
605605
left = mid
606606
else
@@ -650,7 +650,7 @@ function find_callback_time(integrator,callback::ContinuousCallback,counter)
650650
end
651651
iter == 12 && error("Double callback crossing floating pointer reducer errored. Report this issue.")
652652
end
653-
Θ = bisection(zero_func, (bottom_t, top_t), integrator.tdir)
653+
Θ = bisection(zero_func, (bottom_t, top_t), integrator.tdir; noleft=(bottom_t==integrator.tprev))
654654
integrator.last_event_error = ODE_DEFAULT_NORM(zero_func(Θ), Θ)
655655
end
656656
#Θ = prevfloat(...)

0 commit comments

Comments
 (0)