@@ -209,9 +209,10 @@ function chop!(p::AbstractPolynomial{T};
209209 rtol:: Real = Base. rtoldefault (real (T)),
210210 atol:: Real = 0 ,) where {T}
211211 isempty (coeffs (p)) && return p
212+ tol = norm (coeffs (p)) * rtol + atol
212213 for i = lastindex (p): - 1 : 0
213214 val = p[i]
214- if ! isapprox (val, zero (T); rtol = rtol, atol = atol)
215+ if abs (val) > tol # !isapprox(val, zero(T); rtol = rtol, atol = atol)
215216 resize! (p. coeffs, i + 1 );
216217 return p
217218 end
@@ -520,7 +521,7 @@ function Base.divrem(num::P, den::O) where {P <: AbstractPolynomial,O <: Abstrac
520521end
521522
522523"""
523- gcd(a::AbstractPolynomial, b::AbstractPolynomial)
524+ gcd(a::AbstractPolynomial, b::AbstractPolynomial; atol::Real=0, rtol::Real=Base.rtoldefault )
524525
525526Find the greatest common denominator of two polynomials recursively using
526527[Euclid's algorithm](http://en.wikipedia.org/wiki/Polynomial_greatest_common_divisor#Euclid.27s_algorithm).
@@ -535,15 +536,18 @@ Polynomial(4.0 - 6.0*x + 2.0*x^2)
535536
536537```
537538"""
538- function Base. gcd (p1:: AbstractPolynomial{T} , p2:: AbstractPolynomial{S} ) where {T,S}
539+ function Base. gcd (p1:: AbstractPolynomial{T} , p2:: AbstractPolynomial{S} ;
540+ atol:: Real = zero (real (promote_type (T,S))),
541+ rtol:: Real = Base. rtoldefault (real (promote_type (T,S)))
542+ ) where {T,S}
539543 r₀, r₁ = promote (p1, p2)
540544 iter = 1
541545 itermax = length (r₁)
542546
543547 while ! iszero (r₁) && iter ≤ itermax
544548 _, rtemp = divrem (r₀, r₁)
545549 r₀ = r₁
546- r₁ = truncate (rtemp)
550+ r₁ = truncate (rtemp; atol = atol, rtol = rtol )
547551 iter += 1
548552 end
549553 return r₀
0 commit comments