Skip to content

Commit 9967bce

Browse files
authored
Close Issue #423 (#424)
* use typed NaN * add test * version bump
1 parent d528e90 commit 9967bce

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Roots"
22
uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
3-
version = "2.1.3"
3+
version = "2.1.4"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/convergence.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ When the algorithm terminates, this function decides the stopped value or return
273273
function decide_convergence(
274274
M::AbstractNonBracketingMethod,
275275
F,
276-
state::AbstractUnivariateZeroState,
276+
state::AbstractUnivariateZeroState{T,S},
277277
options,
278278
val,
279-
)
279+
) where {T, S}
280280
xn0, xn1 = state.xn0, state.xn1
281281
fxn1 = state.fxn1
282282
val (:f_converged, :exact_zero, :converged) && return xn1
@@ -303,7 +303,7 @@ function decide_convergence(
303303
end
304304
end
305305

306-
NaN * xn1
306+
nan(T) * xn1
307307
end
308308

309309
# assumes stopped = :x_converged

src/hybrid.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function solve!(
4242
quad_ctr = 0
4343
flag = :not_converged
4444
ctr = 0
45-
α = NaN * state.xn1
45+
α = nan(typeof(state.xn1)) * state.xn1
4646
while true
4747
ctr += 1
4848
flag, converged = assess_convergence(M, state, options)

test/test_allocations.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ import BenchmarkTools
9393
@test BenchmarkTools.@ballocated(solve(ZeroProblem($f, $x0), $M, $p)) == 0
9494
@test BenchmarkTools.@ballocated(solve(ZeroProblem($f, $x0), $M; p=$p)) == 0
9595
end
96+
97+
# issue #423 type instability
98+
for M in Ms
99+
@test @inferred solve(ZeroProblem(sin, 3.0f0)) pi
100+
end
96101
end
97102

98103
@testset "simple: zero allocations" begin

0 commit comments

Comments
 (0)