Skip to content

Commit 4f05ad6

Browse files
committed
remove type instability in polyval
1 parent 679bbcf commit 4f05ad6

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Polynomials.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ function polyval{T,S}(p::Poly{T}, x::S)
286286
R = promote_type(T,S)
287287
lenp = length(p)
288288
if lenp == 0
289-
return zero(R)
289+
return zero(R) * x
290290
else
291-
y = convert(R, p[end])
291+
y = convert(R, p[end]) + 0*x
292292
for i = (endof(p)-1):-1:0
293293
y = p[i] + x*y
294294
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ p4 = Poly([1,3,3,1,0,0])
1212
p5 = Poly([1,4,6,4,1,0,0,0,0,0,0,0,0,0,0,0,0,0])
1313
pN = Poly([276,3,87,15,24,0])
1414
pR = Poly([3//4, -2//1, 1//1])
15+
X = Poly([0.0, 1.0])
1516
p1000 = Poly(randn(1000))
1617

1718
@test length(pNULL) == 1
@@ -41,6 +42,8 @@ sprint(show, pNULL)
4142
@test polyval(pN, -.125) == 276.9609375
4243
@test polyval(pNULL, 10) == 0
4344
@test polyval(p0, -10) == 0
45+
@test isa(polyval(p0, X), Poly)
46+
@test isa(polyval(p1, X), Poly)
4447
@test polyval(poly([1//2, 3//2]), 1//2) == 0//1
4548
@test polyder(polyint(pN)) == pN
4649
@test polyder(pR) == Poly([-2//1,2//1])

0 commit comments

Comments
 (0)