@@ -12,8 +12,10 @@ export degree, coeffs, variable, printpoly
12
12
export polyval, polyint, polyder, roots, polyfit
13
13
export Pade, padeval
14
14
15
+ import Compat. lastindex
16
+
15
17
import 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
17
19
import Base: show, print, * , / , // , - , + , == , isapprox, divrem, div, rem, eltype
18
20
import Base: promote_rule, truncate, chop, conj, transpose, hash
19
21
import Base: isequal
@@ -141,7 +143,7 @@ eltype(::Poly{T}) where {T} = T
141
143
eltype (:: Type{Poly{T}} ) where {T} = Poly{T}
142
144
143
145
length (p:: Poly ) = length (coeffs (p))
144
- endof (p:: Poly ) = length (p) - 1
146
+ lastindex (p:: Poly ) = length (p) - 1
145
147
146
148
start (p:: Poly ) = start (coeffs (p)) - 1
147
149
next (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}
448
450
return zero (R) * x
449
451
else
450
452
y = convert (R, p[end ])
451
- for i = (endof (p)- 1 ): - 1 : 0
453
+ for i = (lastindex (p)- 1 ): - 1 : 0
452
454
y = p[i] + x* y
453
455
end
454
456
return y
@@ -475,8 +477,9 @@ julia> polyint(Poly([1, 0, -1]), 2)
475
477
Poly(2.0 + 1.0⋅x - 0.3333333333333333⋅x^3)
476
478
```
477
479
"""
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
+
480
483
481
484
# if we have coefficients that have `NaN` representation
482
485
function polyint (p:: Poly{T} , k:: S ) where {T<: Union{Real,Complex} ,S<: Number }
@@ -542,8 +545,8 @@ julia> polyder(Poly([1, 3, -1]), 2)
542
545
Poly(-2)
543
546
```
544
547
"""
545
- # if we have coefficients that can represent `NaN`s
546
548
function polyder (p:: Poly{T} , order:: Int = 1 ) where {T<: Union{Real,Complex} }
549
+ # if we have coefficients that can represent `NaN`s
547
550
n = length (p)
548
551
order < 0 && error (" Order of derivative must be non-negative" )
549
552
order == 0 && return p
@@ -628,7 +631,7 @@ function roots(p::Poly{T}) where {T}
628
631
while p[end - num_trailing_zeros] ≈ zero (T)
629
632
num_trailing_zeros += 1
630
633
end
631
- n = endof (p)- (num_leading_zeros + num_trailing_zeros)
634
+ n = lastindex (p)- (num_leading_zeros + num_trailing_zeros)
632
635
n < 1 && return zeros (R, length (p) - num_trailing_zeros - 1 )
633
636
634
637
companion = @compat diagm (- 1 => ones (R, n- 1 ))
0 commit comments