Skip to content

Commit cf94695

Browse files
authored
New method for derivative of constant ImmutableDensePolynomial (#615)
* Include a method for derivative of constant `ImmutableDensePolynomial` (N=1). The method returns the zero `ImmutableDensePolynomial. This is a possible fix of a bug, since previously derivative of an `ImmutablePolynomial` returned an unusable polynomial of type `ImmutablePolynomial{Union{},:x,0}`. * Improved derivative for constant `ImmutablePolynomial`. `derivative(p)` now returns `zero(p)`.
1 parent 607acca commit cf94695

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/polynomials/standard-basis/immutable-polynomial.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,11 @@ end
142142

143143
# special cases are much more performant
144144
derivative(p::ImmutableDensePolynomial{B,T,X,0}) where {B<:StandardBasis,T,X} = p
145+
derivative(p::ImmutableDensePolynomial{B,T,X,1}) where {B<:StandardBasis,T,X} = zero(p)
146+
145147
function derivative(p::ImmutableDensePolynomial{B,T,X,N}) where {B<:StandardBasis,T,X,N}
146148
N == 0 && return p
149+
N == 1 && return zero(p)
147150
hasnan(p) && return ImmutableDensePolynomial{B,T,X,1}(zero(T)/zero(T)) # NaN{T}
148151
cs = ntuple(i -> i*p.coeffs[i+1], Val(N-1))
149152
R = eltype(cs)

0 commit comments

Comments
 (0)