Skip to content

Commit bea1d54

Browse files
committed
Fix 0.4 deprecated bindings. Fix test and rename tests.jl to runtests.jl
1 parent fe7a074 commit bea1d54

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

REQUIRE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
julia 0.3
2+
Compat

src/Polynomials.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module Polynomials
44
#todo: sparse polynomials?
55

6+
using Compat
7+
68
export Poly, polyval, polyint, polyder, poly, roots
79
export Pade, padeval
810

@@ -11,7 +13,7 @@ import Base: show, print, *, /, //, -, +, ==, divrem, rem, eltype
1113
import Base: promote_rule
1214

1315
eps{T}(::Type{T}) = zero(T)
14-
eps{F<:FloatingPoint}(x::Type{F}) = Base.eps(F)
16+
eps{F<:AbstractFloat}(x::Type{F}) = Base.eps(F)
1517
eps{T}(x::Type{Complex{T}}) = eps(T)
1618

1719
immutable Poly{T<:Number}
@@ -22,7 +24,7 @@ immutable Poly{T<:Number}
2224
end
2325
end
2426

25-
Poly{T<:Number}(a::Vector{T}, var::Union(String,Symbol,Char)=:x) = Poly{T}(a, var)
27+
@compat Poly{T<:Number}(a::Vector{T}, var::Union{AbstractString,Symbol,Char}=:x) = Poly{T}(a, var)
2628

2729
convert{T}(::Type{Poly{T}}, p::Poly) = Poly(convert(Vector{T}, p.a), p.var)
2830
convert{T, S<:Number}(::Type{Poly{T}}, x::S) = Poly(promote_type(T, S)[x])
@@ -304,7 +306,7 @@ function poly{T}(r::AbstractVector{T}, var=:x)
304306
return Poly(reverse(c), var)
305307
end
306308
poly(A::Matrix, var=:x) = poly(eig(A)[1], var)
307-
poly(A::Matrix, var::String) = poly(eig(A)[1], symbol(var))
309+
poly(A::Matrix, var::AbstractString) = poly(eig(A)[1], symbol(var))
308310
poly(A::Matrix, var::Char) = poly(eig(A)[1], symbol(var))
309311

310312
roots{T}(p::Poly{Rational{T}}) = roots(convert(Poly{promote_type(T, Float64)}, p))

src/pade.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Pade{T<:Number,S<:Number}(p::Poly{T}, q::Poly{S}) = Pade{T,S}(p,q)
1313

1414
function Pade{T}(c::Poly{T},m::Int,n::Int)
1515
@assert m+n < length(c)
16-
rold,rnew = Poly([zeros(T,m+n+1),one(T)],c.var),Poly(c.a[1:m+n+1],c.var)
16+
rold,rnew = Poly([zeros(T,m+n+1);one(T)],c.var),Poly(c.a[1:m+n+1],c.var)
1717
uold,vold = Poly([one(T)],c.var),Poly([zero(T)],c.var)
1818
unew,vnew = vold,uold
1919
for i=1:n
@@ -30,4 +30,4 @@ function Pade{T}(c::Poly{T},m::Int,n::Int)
3030
end
3131
Pade(rnew/vnew[0],vnew/vnew[0])
3232
end
33-
padeval{T}(PQ::Pade{T},x) = polyval(PQ.p,x)./polyval(PQ.q,x)
33+
padeval{T}(PQ::Pade{T},x) = polyval(PQ.p,x)./polyval(PQ.q,x)

test/tests.jl renamed to test/runtests.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# assert file to test polynomial implementation
2+
using Compat
23
using Base.Test
34
using Polynomials
45

@@ -32,7 +33,7 @@ sprint(show, pNULL)
3233
@test pNULL^3 == pNULL
3334
@test pNULL*pNULL == pNULL
3435

35-
@test map(Polynomials.degree, [pNULL,p0,p1,p2,p3,p4,p5,pN,pR,p1000]) == [0,0,0,1,2,3,4,4,2,999]
36+
@test map(Polynomials.degree, [pNULL,p0,p1,p2,p3,p4,p5,pN,pR,p1000]) == [0,0,0,1,2,3,4,4,2,999]
3637

3738
@test polyval(pN, -.125) == 276.9609375
3839
@test polyval(pNULL, 10) == 0
@@ -95,26 +96,27 @@ pcpy2 = copy(pcpy1)
9596
#Tests for Pade approximants
9697

9798
println("Test for the exponential function.")
98-
a = Poly(1.//convert(Vector{Int},gamma(1:17)),"x")
99+
a = Poly(1.//convert(Vector{BigInt},gamma(BigFloat(1):BigFloat(17))),"x")
99100
PQexp = Pade(a,8,8)
100-
@test padeval(PQexp,1.0) == exp(1.0)
101-
@test padeval(PQexp,-1.0) == exp(-1.0)
101+
@test isapprox(convert(Float64, padeval(PQexp,1.0)), exp(1.0))
102+
@test isapprox(convert(Float64, padeval(PQexp,-1.0)), exp(-1.0))
102103

103104
println("Test for the sine function.")
104-
b = Poly(convert(Vector{BigInt},sinpi((0:16)/2)).//convert(Vector{BigInt},gamma(BigFloat("1.0"):BigFloat("17.0"))),"x")
105+
b = Poly(convert(Vector{BigInt},sinpi((0:16)/2)).//convert(Vector{BigInt},gamma(BigFloat(1):BigFloat(17))),"x")
105106
PQsin = Pade(b,8,7)
106-
@test isapprox(padeval(PQsin,1.0),sin(1.0))
107-
@test isapprox(padeval(PQsin,-1.0),sin(-1.0))
107+
@test isapprox(convert(Float64, padeval(PQsin,1.0)), sin(1.0))
108+
@test isapprox(convert(Float64, padeval(PQsin,-1.0)),sin(-1.0))
108109

109110
println("Test for the cosine function.")
110-
c = Poly(convert(Vector{BigInt},sinpi((1:17)/2)).//convert(Vector{BigInt},gamma(BigFloat("1.0"):BigFloat("17.0"))),"x")
111+
c = Poly(convert(Vector{BigInt},sinpi((1:17)/2)).//convert(Vector{BigInt},gamma(BigFloat(1):BigFloat(17))),"x")
111112
PQcos = Pade(c,8,8)
112-
@test isapprox(padeval(PQcos,1.0),cos(1.0))
113-
@test isapprox(padeval(PQcos,-1.0),cos(-1.0))
113+
@test isapprox(convert(Float64, padeval(PQcos,1.0)), cos(1.0))
114+
@test isapprox(convert(Float64, padeval(PQcos,-1.0)), cos(-1.0))
114115

115116
println("Test for the summation of a factorially divergent series.")
116-
d = Poly(convert(Vector{BigInt},(-1).^(0:60).*gamma(BigFloat("1.0"):BigFloat("61.0"))).//1,"x")
117+
d = Poly(convert(Vector{BigInt},(-1).^(0:60).*gamma(BigFloat(1):BigFloat(61.0))).//1,"x")
117118
PQexpint = Pade(d,30,30)
118-
println("The approximate sum of the divergent series is: ",float64(padeval(PQexpint,1.0)))
119+
@compat println("The approximate sum of the divergent series is: ", Float64(padeval(PQexpint,1.0)))
119120
println("The approximate sum of the convergent series is: ",exp(1)*(-γ-sum([(-1).^k/k./gamma(k+1) for k=1:20])))
120-
@test isapprox(padeval(PQexpint,1.0) , exp(1)*(-γ-sum([(-1).^k/k./gamma(k+1) for k=1:20])))
121+
@test isapprox(convert(Float64, padeval(PQexpint,1.0)),
122+
exp(1)*(-γ-sum([(-1).^k/k./gamma(k+1) for k=1:20])))

0 commit comments

Comments
 (0)