diff --git a/src/primitive.jl b/src/primitive.jl index f3fd0c2..9bb3bb9 100644 --- a/src/primitive.jl +++ b/src/primitive.jl @@ -106,6 +106,8 @@ end ex = :($ex; TaylorScalar($([Symbol('v', i) for i in 1:N]...))) return :(@inbounds $ex) end +@inline *(a::TaylorScalar{T1, N}, b::TaylorScalar{T2, N}) where {T1,T2,N} = *(promote(a,b)...) +@inline /(a::TaylorScalar{T1, N}, b::TaylorScalar{T2, N}) where {T1,T2,N} = *(promote(a,b)...) @generated function ^(t::TaylorScalar{T, N}, n::S) where {S <: Number, T, N} ex = quote diff --git a/src/scalar.jl b/src/scalar.jl index e69c950..53fae9f 100644 --- a/src/scalar.jl +++ b/src/scalar.jl @@ -72,6 +72,9 @@ function promote_rule(::Type{TaylorScalar{T, N}}, ::Type{S}) where {T, S, N} TaylorScalar{promote_type(T, S), N} end +function promote_rule(::Type{TaylorScalar{T1, N}}, ::Type{TaylorScalar{T2,N}}) where {T1, T2, N} +TaylorScalar{promote_type(T1,T2), N} +end # Number-like convention (I patched them after removing <: Number) @@ -79,6 +82,9 @@ convert(::Type{TaylorScalar{T, N}}, x::TaylorScalar{T, N}) where {T, N} = x function convert(::Type{TaylorScalar{T, N}}, x::S) where {T, S, N} TaylorScalar{T, N}(convert(T, x)) end +function convert(::Type{TaylorScalar{T1,N}},x::TaylorScalar{T2,N}) where {T1,T2,N} + TaylorScalar{T1,N}(convert.(T1,value(x))) +end @inline +(a::Number, b::TaylorScalar) = TaylorScalar((a + value(b)[1]), value(b)[2:end]...) @inline -(a::Number, b::TaylorScalar) = TaylorScalar((a - value(b)[1]), .-value(b)[2:end]...) @inline *(a::Number, b::TaylorScalar) = TaylorScalar((a .* value(b))...)