Skip to content

Commit

Permalink
fix multiplication of particles and quantity
Browse files Browse the repository at this point in the history
closes #152
  • Loading branch information
baggepinnen committed Jan 7, 2025
1 parent f4a9bd6 commit 26a6d10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/UnitfulExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ for PT in MonteCarloMeasurements.ParticleSymbols
$PT{Quantity{NT,D,U},N}($(op).(p.particles , y))
end

function Base.$f(p::$PT{T,N}, y::Quantity{S,D,U}) where {S, D, U, T <: Quantity, N}
function Base.$f(p::$PT{T,N}, y::Quantity{S,D,U}) where {S, D, U, T <: Number, N}
QT = Base.promote_op($op, T, typeof(y))
$PT{QT,N}($(op).(p.particles, y))
end

# Below is just the reverse signature of above
function Base.$f(y::Quantity{S,D,U}, p::$PT{T,N}) where {S, D, U, T <: Quantity, N}
function Base.$f(y::Quantity{S,D,U}, p::$PT{T,N}) where {S, D, U, T <: Number, N}
QT = Base.promote_op($op, typeof(y), T)
$PT{QT,N}($(op).(y, p.particles))
end
Expand Down
7 changes: 7 additions & 0 deletions test/test_unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ register_primitive(unitful_testfunction) # must be outside testset

d1 = upreferred(a)
@test d1 (0.200 + 0.020*PT())u"s"

# Issue #152
x = PT()
z = 123u"m"
y = z * x
@test y isa PT{<:Quantity}
@test ustrip(u"cm", x*y) isa PT{Float64}
end

end

0 comments on commit 26a6d10

Please sign in to comment.