Skip to content

Commit

Permalink
Refactor disambiguities
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Nov 23, 2023
1 parent 0f6dd0c commit 8205e49
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/disambiguities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,6 @@ end
# Assorted calls found by Aqua: ################################################
################################################################################

function Complex(q::AbstractRealQuantity)
@assert iszero(dimension(q)) "$(typeof(q)): $(q) has dimensions! Use `ustrip` instead."
return Complex(ustrip(q))
end
function Complex{T}(q::AbstractRealQuantity) where {T<:Real}
@assert iszero(dimension(q)) "$(typeof(q)): $(q) has dimensions! Use `ustrip` instead."
return Complex{T}(ustrip(q))
end
function Bool(q::AbstractRealQuantity)
@assert iszero(dimension(q)) "$(typeof(q)): $(q) has dimensions! Use `ustrip` instead."
return Bool(ustrip(q))
end
for type in (Signed, Float64, Float32, Rational), op in (:flipsign, :copysign)
@eval function Base.$(op)(x::$type, y::AbstractRealQuantity)
return $(op)(x, ustrip(y))
Expand All @@ -72,8 +60,16 @@ for type in (Complex, Complex{Bool})
function Base.:*(l::AbstractRealQuantity, r::$type)
new_quantity(typeof(l), ustrip(l) * r, dimension(l))
end
function $type(q::AbstractRealQuantity) where {T<:Real}
@assert iszero(dimension(q)) "$(typeof(q)): $(q) has dimensions! Use `ustrip` instead."
return $type(ustrip(q))
end
end
end
function Bool(q::AbstractRealQuantity)
@assert iszero(dimension(q)) "$(typeof(q)): $(q) has dimensions! Use `ustrip` instead."
return Bool(ustrip(q))
end
function Base.:/(l::Complex, r::AbstractRealQuantity)
new_quantity(typeof(r), l / ustrip(r), inv(dimension(r)))
end
Expand Down

0 comments on commit 8205e49

Please sign in to comment.