Skip to content

Commit a3b6d13

Browse files
committed
Add promotion rule
1 parent 10112cf commit a3b6d13

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/function_registration.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ end
5555
# special cases
5656
Base.:^(x::Expression,y::T) where T <: Integer = Operation(Base.:^, Expression[x, y])
5757
Base.:^(x::Expression,y::T) where T <: Rational = Operation(Base.:^, Expression[x, y])
58-
Base.conj(x::Expression) = Operation(Base.conj, [x])
59-
Base.muladd(a::Expression, b::Expression, c::Expression) = a * b + c
6058

59+
@register Base.conj(x)
6160
@register Base.getindex(x,i)
6261
Base.getindex(x::Operation,i::Int64) = Operation(getindex,[x,i])

src/operations.jl

+4
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ Operation(x) = convert(Operation, x)
6666
#convert to Expr
6767
Base.Expr(op::Operation) = simplified_expr(op)
6868
Base.convert(::Type{Expr},x::Operation) = Expr(x)
69+
70+
# promotion
71+
Base.promote_rule(::Type{<:Constant}, ::Type{<:Operation}) = Operation
72+
Base.promote_rule(::Type{<:Operation}, ::Type{<:Constant}) = Operation

test/direct.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ function test_worldage()
8282
end
8383
test_worldage()
8484

85-
@test muladd(x, y, z) == x * y + z
85+
@test_nowarn muladd(x, y, z)
8686
@test_nowarn [x, y, z]'

0 commit comments

Comments
 (0)