Skip to content

Commit

Permalink
better fix to #159
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani committed Jan 18, 2019
1 parent 4b2330b commit 2bb0ccf
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/Polynomials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -560,20 +560,11 @@ function polyder(p::Poly{T}, order::Int=1) where {T}
_polyder(p, order)
end

# _int(T) returns matching Integer type to T
# to avoid overflow in `prod` usage below
_int(::Type{T}) where {T <: Union{Integer, Int8, Int16, Int64, Int128, BigInt}} = T
_int(::Type{Float16}) = Int16
_int(::Type{Float32}) = Int32
_int(::Type{Float64}) = Int64
_int(::Type{BigFloat}) = BigInt
_int(x) = Int

function _polyder(p::Poly{T}, order::Int=1) where {T}
n = length(p)
a2 = Vector{T}(undef, n-order)
for i = order:n-1
a2[i-order+1] = p[i] * prod((one(_int(T)) * (i-order+1)):i)
a2[i-order+1] = reduce(*, (i-order+1):i, init=p[i])
end

return Poly(a2, p.var)
Expand Down

0 comments on commit 2bb0ccf

Please sign in to comment.