@@ -12,8 +12,10 @@ export degree, coeffs, variable, printpoly
1212export polyval, polyint, polyder, roots, polyfit
1313export Pade, padeval
1414
15+ import Compat. lastindex
16+
1517import Base: start, next, done, length, size, eltype, collect, eachindex
16- import Base: endof, getindex, setindex!, copy, zero, one, convert, gcd
18+ import Base: getindex, setindex!, copy, zero, one, convert, gcd
1719import Base: show, print, * , / , // , - , + , == , isapprox, divrem, div, rem, eltype
1820import Base: promote_rule, truncate, chop, conj, transpose, hash
1921import Base: isequal
@@ -141,7 +143,7 @@ eltype(::Poly{T}) where {T} = T
141143eltype (:: Type{Poly{T}} ) where {T} = Poly{T}
142144
143145length (p:: Poly ) = length (coeffs (p))
144- endof (p:: Poly ) = length (p) - 1
146+ lastindex (p:: Poly ) = length (p) - 1
145147
146148start (p:: Poly ) = start (coeffs (p)) - 1
147149next (p:: Poly , state) = (temp = fill! (similar (coeffs (p)), 0 ); temp[state+ 1 ] = p[state]; (Poly (temp), state+ 1 ))
@@ -448,7 +450,7 @@ function polyval(p::Poly{T}, x::S) where {T,S}
448450 return zero (R) * x
449451 else
450452 y = convert (R, p[end ])
451- for i = (endof (p)- 1 ): - 1 : 0
453+ for i = (lastindex (p)- 1 ): - 1 : 0
452454 y = p[i] + x* y
453455 end
454456 return y
@@ -475,8 +477,9 @@ julia> polyint(Poly([1, 0, -1]), 2)
475477Poly(2.0 + 1.0⋅x - 0.3333333333333333⋅x^3)
476478```
477479"""
478- # if we do not have any initial condition, assume k = zero(Int)
479- polyint (p:: Poly{T} ) where {T} = polyint (p, 0 )
480+ polyint (p:: Poly{T} ) where {T} = polyint (p, 0 ) # if we do not have any initial
481+ # condition, assume k = zero(Int)
482+
480483
481484# if we have coefficients that have `NaN` representation
482485function polyint (p:: Poly{T} , k:: S ) where {T<: Union{Real,Complex} ,S<: Number }
@@ -542,8 +545,8 @@ julia> polyder(Poly([1, 3, -1]), 2)
542545Poly(-2)
543546```
544547"""
545- # if we have coefficients that can represent `NaN`s
546548function polyder (p:: Poly{T} , order:: Int = 1 ) where {T<: Union{Real,Complex} }
549+ # if we have coefficients that can represent `NaN`s
547550 n = length (p)
548551 order < 0 && error (" Order of derivative must be non-negative" )
549552 order == 0 && return p
@@ -628,7 +631,7 @@ function roots(p::Poly{T}) where {T}
628631 while p[end - num_trailing_zeros] ≈ zero (T)
629632 num_trailing_zeros += 1
630633 end
631- n = endof (p)- (num_leading_zeros + num_trailing_zeros)
634+ n = lastindex (p)- (num_leading_zeros + num_trailing_zeros)
632635 n < 1 && return zeros (R, length (p) - num_trailing_zeros - 1 )
633636
634637 companion = @compat diagm (- 1 => ones (R, n- 1 ))
0 commit comments