Skip to content

Commit 330f8fa

Browse files
committed
cquantile_newton(): refactor using newton()
1 parent fc90778 commit 330f8fa

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/quantilealgs.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,11 @@ end
7676

7777
function cquantile_newton(d::ContinuousUnivariateDistribution, p::Real, xs::Real=mode(d), tol::Real=1e-12)
7878
f(x) = (ccdf(d, x)-p) / pdf(d, x)
79+
# FIXME: can this be expressed via `promote_type()`? Test coverage missing.
7980
x = xs + f(xs)
8081
T = typeof(x)
8182
if 0 < p < 1
82-
x0 = T(xs)
83-
while abs(x-x0) > max(abs(x),abs(x0)) * tol
84-
x0 = x
85-
x = x0 + f(x0)
86-
end
87-
return x
83+
return newton(f, T(xs), tol)
8884
elseif p == 1
8985
return T(minimum(d))
9086
elseif p == 0

0 commit comments

Comments
 (0)