From 54af72fc0832c33d875a8df85cafb37db18cc561 Mon Sep 17 00:00:00 2001 From: Oskar Laverny Date: Tue, 7 Feb 2023 23:22:10 +0100 Subject: [PATCH] Modify scalar rules for +,-,/,* --- src/scalar.jl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/scalar.jl b/src/scalar.jl index 391b4e7..e69c950 100644 --- a/src/scalar.jl +++ b/src/scalar.jl @@ -79,8 +79,14 @@ 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 -for op in (:+, :-, :*, :/) - @eval @inline $op(a::TaylorScalar, b::Number) = $op(promote(a, b)...) - @eval @inline $op(a::Number, b::TaylorScalar) = $op(promote(a, b)...) -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))...) +@inline /(a::Number, b::TaylorScalar) = /(promote(a, b)...) + +@inline +(a::TaylorScalar, b::Number) = TaylorScalar((value(a)[1] + b), value(a)[2:end]...) +@inline -(a::TaylorScalar, b::Number) = TaylorScalar((value(a)[1] - b), value(a)[2:end]...) +@inline *(a::TaylorScalar, b::Number) = TaylorScalar((value(a) .* b)...) +@inline /(a::TaylorScalar, b::Number) = TaylorScalar((value(a) ./ b)...) + transpose(t::TaylorScalar) = t