Skip to content

Commit 7ee9cdc

Browse files
committed
Improved derivative for constant ImmutablePolynomial. derivative(p) now returns zero(p).
1 parent e63df3d commit 7ee9cdc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +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-
function derivative(p::ImmutableDensePolynomial{B,T,X,1}) where {B<:StandardBasis,T,X}
146-
ImmutableDensePolynomial{B,T,X,1}(zero(T))
147-
end
145+
derivative(p::ImmutableDensePolynomial{B,T,X,1}) where {B<:StandardBasis,T,X} = zero(p)
146+
148147
function derivative(p::ImmutableDensePolynomial{B,T,X,N}) where {B<:StandardBasis,T,X,N}
149148
N == 0 && return p
149+
N == 1 && return zero(p)
150150
hasnan(p) && return ImmutableDensePolynomial{B,T,X,1}(zero(T)/zero(T)) # NaN{T}
151151
cs = ntuple(i -> i*p.coeffs[i+1], Val(N-1))
152152
R = eltype(cs)

0 commit comments

Comments
 (0)