Skip to content

Instantly share code, notes, and snippets.

@mathpup
mathpup / PolyExt.jl
Last active October 1, 2021 12:21
Extension of Polynomial.jl to support polynomial division. Also adds some handy conversions and promotion rules.
import Base.convert, Base.promote_rule
using Polynomial
convert{T<:FloatingPoint}(::Type{Poly{T}}, p::Poly) = return Poly(convert(Vector{T}, p.a))
convert{T<:Rational}(::Type{Poly{T}}, p::Poly) = Poly(convert(Vector{T}, p.a))
convert{T<:Integer}(::Type{Poly{T}}, p::Poly) = Poly(convert(Vector{T}, p.a))
promote_rule{T<:FloatingPoint, S<:FloatingPoint}(::Type{Poly{T}}, ::Type{Poly{S}}) =
Poly{promote_type(T, S)}