Skip to content

Commit

Permalink
Make Zero be a subtype of Number
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jul 23, 2024
1 parent 0e42a16 commit faf35f8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/rewrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ macro rewrite(args...)
return rewrite_and_return(args[1]; move_factors_into_sums = args[2].args[2])
end

struct Zero end
struct Zero <: Number end

# This method is called in various `promote_operation_fallback` methods if one
# of the arguments is `::Zero`.
Expand Down Expand Up @@ -62,7 +62,9 @@ Base.:*(z::Zero, ::Any) = z
Base.:*(::Any, z::Zero) = z
Base.:*(z::Zero, ::Zero) = z
Base.:+(::Zero, x::Any) = x
Base.:+(::Zero, x::Number) = x
Base.:+(x::Any, ::Zero) = x
Base.:+(x::Number, ::Zero) = x
Base.:+(z::Zero, ::Zero) = z
Base.:-(::Zero, x::Any) = -x
Base.:-(x::Any, ::Zero) = x
Expand Down

0 comments on commit faf35f8

Please sign in to comment.