diff --git a/Project.toml b/Project.toml index 21aeb57..5b8f6f1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Roots" uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" -version = "2.1.3" +version = "2.1.4" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" diff --git a/src/convergence.jl b/src/convergence.jl index b8a50dd..c33a11c 100644 --- a/src/convergence.jl +++ b/src/convergence.jl @@ -273,10 +273,10 @@ When the algorithm terminates, this function decides the stopped value or return function decide_convergence( M::AbstractNonBracketingMethod, F, - state::AbstractUnivariateZeroState, + state::AbstractUnivariateZeroState{T,S}, options, val, -) +) where {T, S} xn0, xn1 = state.xn0, state.xn1 fxn1 = state.fxn1 val ∈ (:f_converged, :exact_zero, :converged) && return xn1 @@ -303,7 +303,7 @@ function decide_convergence( end end - NaN * xn1 + nan(T) * xn1 end # assumes stopped = :x_converged diff --git a/src/hybrid.jl b/src/hybrid.jl index 712bf5d..40d7e1a 100644 --- a/src/hybrid.jl +++ b/src/hybrid.jl @@ -42,7 +42,7 @@ function solve!( quad_ctr = 0 flag = :not_converged ctr = 0 - α = NaN * state.xn1 + α = nan(typeof(state.xn1)) * state.xn1 while true ctr += 1 flag, converged = assess_convergence(M, state, options) diff --git a/test/test_allocations.jl b/test/test_allocations.jl index ed3ab56..4f941e1 100644 --- a/test/test_allocations.jl +++ b/test/test_allocations.jl @@ -93,6 +93,11 @@ import BenchmarkTools @test BenchmarkTools.@ballocated(solve(ZeroProblem($f, $x0), $M, $p)) == 0 @test BenchmarkTools.@ballocated(solve(ZeroProblem($f, $x0), $M; p=$p)) == 0 end + + # issue #423 type instability + for M in Ms + @test @inferred solve(ZeroProblem(sin, 3.0f0)) ≈ pi + end end @testset "simple: zero allocations" begin