@@ -172,7 +172,11 @@ In-place version of [`truncate`](@ref)
172
172
"""
173
173
function truncate! (p:: AbstractPolynomial{T} ;
174
174
rtol:: Real = Base. rtoldefault (real (T)),
175
- atol:: Real = 0 ,) where {T}
175
+ atol:: Real = 0 ,) where {T}
176
+
177
+ #
178
+
179
+
176
180
max_coeff = maximum (abs, coeffs (p))
177
181
thresh = max_coeff * rtol + atol
178
182
map! (c-> abs (c) <= thresh ? zero (T) : c, coeffs (p), coeffs (p))
@@ -392,7 +396,7 @@ Base.broadcastable(p::AbstractPolynomial) = Ref(p)
392
396
function basis (:: Type{P} , k:: Int , _var:: SymbolLike = :x ; var= _var) where {P <: AbstractPolynomial }
393
397
zs = zeros (Int, k+ 1 )
394
398
zs[end ] = 1
395
- P (zs, var)
399
+ ⟒ (P){ eltype (P)} (zs, var)
396
400
end
397
401
basis (p:: P , k:: Int , _var:: SymbolLike = :x ; var= _var) where {P<: AbstractPolynomial } = basis (P, k, var)
398
402
@@ -452,15 +456,15 @@ Base.hash(p::AbstractPolynomial, h::UInt) = hash(p.var, hash(coeffs(p), h))
452
456
453
457
Returns a representation of 0 as the given polynomial.
454
458
"""
455
- Base. zero (:: Type{P} , var= :x ) where {P <: AbstractPolynomial } = P (zeros (eltype (P), 1 ), var)
459
+ Base. zero (:: Type{P} , var= :x ) where {P <: AbstractPolynomial } = ⟒ (P) (zeros (eltype (P), 1 ), var)
456
460
Base. zero (p:: P ) where {P <: AbstractPolynomial } = zero (P, p. var)
457
461
"""
458
462
one(::Type{<:AbstractPolynomial})
459
463
one(::AbstractPolynomial)
460
464
461
465
Returns a representation of 1 as the given polynomial.
462
466
"""
463
- Base. one (:: Type{P} , var= :x ) where {P <: AbstractPolynomial } = P (ones (eltype (P),1 ), var)
467
+ Base. one (:: Type{P} , var= :x ) where {P <: AbstractPolynomial } = ⟒ (P) (ones (eltype (P),1 ), var)
464
468
Base. one (p:: P ) where {P <: AbstractPolynomial } = one (P, p. var)
465
469
466
470
Base. oneunit (:: Type{P} , args... ) where {P <: AbstractPolynomial } = one (P, args... )
@@ -556,11 +560,11 @@ Base.:(==)(p1::AbstractPolynomial, p2::AbstractPolynomial) =
556
560
Base.:(== )(p:: AbstractPolynomial , n:: Number ) = degree (p) <= 0 && p[0 ] == n
557
561
Base.:(== )(n:: Number , p:: AbstractPolynomial ) = p == n
558
562
563
+
559
564
function Base. isapprox (p1:: AbstractPolynomial{T} ,
560
565
p2:: AbstractPolynomial{S} ;
561
566
rtol:: Real = (Base. rtoldefault (T, S, 0 )),
562
- atol:: Real = 0 ,) where {T,S}
563
-
567
+ atol:: Real = 0 ,) where {T,S}
564
568
p1, p2 = promote (p1, p2)
565
569
check_same_variable (p1, p2) || error (" p1 and p2 must have same var" )
566
570
p1t = truncate (p1; rtol = rtol, atol = atol)
@@ -569,7 +573,6 @@ function Base.isapprox(p1::AbstractPolynomial{T},
569
573
return false
570
574
end
571
575
isapprox (coeffs (p1t), coeffs (p2t), rtol = rtol, atol = atol)
572
-
573
576
end
574
577
575
578
function Base. isapprox (p1:: AbstractPolynomial{T} ,
@@ -583,6 +586,7 @@ function Base.isapprox(p1::AbstractPolynomial{T},
583
586
isapprox (coeffs (p1t), [n], rtol = rtol, atol = atol)
584
587
end
585
588
589
+
586
590
Base. isapprox (n:: S ,
587
591
p1:: AbstractPolynomial{T} ;
588
592
rtol:: Real = (Base. rtoldefault (T, S, 0 )),
0 commit comments