We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6153edc commit 2ed6f21Copy full SHA for 2ed6f21
src/contrib.jl
@@ -49,15 +49,22 @@ end
49
50
evalpoly(x, p::AbstractVector) = _evalpoly(x, p)
51
52
+# https://discourse.julialang.org/t/i-have-a-much-faster-version-of-evalpoly-why-is-it-faster/79899; improvement *and* closes #313
53
function _evalpoly(x::S, p) where {S}
- N = length(p)
54
- ex = p[end]*_one(x)
55
- for i in N-1:-1:1
56
- ex = _muladd(ex, x, p[i])
+ i = lastindex(p)
+
+ @inbounds out = p[i]*_one(x)
57
+ i -= 1
58
59
+ while i >= firstindex(p)
60
+ @inbounds out = _muladd(out, x, p[i])
61
62
end
- ex
63
64
+ return out
65
66
67
68
function evalpoly(z::Complex, p::Tuple)
69
if @generated
70
N = length(p.parameters)
0 commit comments