Skip to content

Commit 2ed6f21

Browse files
authored
adjust evalpoly; close #313 (#400)
1 parent 6153edc commit 2ed6f21

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/contrib.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,22 @@ end
4949

5050
evalpoly(x, p::AbstractVector) = _evalpoly(x, p)
5151

52+
# https://discourse.julialang.org/t/i-have-a-much-faster-version-of-evalpoly-why-is-it-faster/79899; improvement *and* closes #313
5253
function _evalpoly(x::S, p) where {S}
53-
N = length(p)
54-
ex = p[end]*_one(x)
55-
for i in N-1:-1:1
56-
ex = _muladd(ex, x, p[i])
54+
i = lastindex(p)
55+
56+
@inbounds out = p[i]*_one(x)
57+
i -= 1
58+
59+
while i >= firstindex(p)
60+
@inbounds out = _muladd(out, x, p[i])
61+
i -= 1
5762
end
58-
ex
63+
64+
return out
5965
end
6066

67+
6168
function evalpoly(z::Complex, p::Tuple)
6269
if @generated
6370
N = length(p.parameters)

0 commit comments

Comments
 (0)