Skip to content

Commit 5e621bd

Browse files
committed
newton(): extract converged()
1 parent a319a7a commit 5e621bd

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/quantilealgs.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ quantile_bisect(d::ContinuousUnivariateDistribution, p::Real) =
4848
# http://www.statsci.org/smyth/pubs/qinvgaussPreprint.pdf
4949

5050
function newton(f, xs::T=mode(d), tol::Real=1e-12) where {T}
51+
converged(a,b) = abs(a-b) <= max(abs(a),abs(b)) * tol
5152
x = xs + f(xs)
5253
@assert typeof(x) === T
5354
x0 = T(xs)
54-
while abs(x-x0) > max(abs(x),abs(x0)) * tol
55+
while !converged(x, x0)
5556
x0 = x
5657
x = x0 + f(x0)
5758
end

0 commit comments

Comments
 (0)