Skip to content

Commit e0d095c

Browse files
committed
add uconvert method
1 parent 20efbe9 commit e0d095c

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/nominal.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ end
3131
"""
3232
nominal(p)
3333
34-
Return the nominal value of `p` (assumes that `p` has bee endowed with a nominal value using `with_nominal`).
34+
Return the nominal value of `p` (assumes that `p` has been endowed with a nominal value using `with_nominal`).
3535
"""
3636
nominal(p::AbstractParticles) = p[1]
3737
nominal(p::MvParticles) = nominal.(p)

src/particles.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ end
116116

117117
function Base.show(io::IO, ::MIME"text/plain", p::AbstractParticles{T,N}) where {T,N}
118118
sPT = MonteCarloMeasurements.shortform(p)
119-
print(io, "$(typeof(p))\n ", MonteCarloMeasurements.to_num_str(p, 6, 3))
119+
compact = get(io, :compact, false)
120+
if compact
121+
print(io, MonteCarloMeasurements.to_num_str(p, 6, 3))
122+
else
123+
print(io, "$(typeof(p))\n ", MonteCarloMeasurements.to_num_str(p, 6, 3))
124+
end
120125
end
121126

122127
function Base.show(io::IO, ::MIME"text/plain", z::Complex{<:AbstractParticles})

src/unitful.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ for PT in ParticleSymbols
2020
function Base.convert(::Type{$PT{Quantity{S,D,U},N}}, y::Quantity) where {S, D, U, T, N}
2121
$PT{Quantity{S,D,U},N}(fill(y, N))
2222
end
23+
24+
function Unitful.uconvert(a::Unitful.FreeUnits, y::$PT)
25+
$PT(Unitful.uconvert.(a, y.particles))
26+
end
2327
end
2428

2529
for op in (*, /)

test/test_unitful.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ register_primitive(unitful_testfunction) # must be outside testset
4343
@test 1u"m" + (1 ± 0.5)u"m" (2 ± 0.5)u"m"
4444

4545
typeof(promote(1u"V", (1.0 ± 0.1)u"V")) <: Tuple{Particles{<:Quantity}, Particles{<:Quantity}}
46+
47+
ρ = (2.7 ± 0.2)u"g/cm^3"
48+
mass = (250 ± 10)u"g"
49+
width = (30.5 ± 0.2)u"cm"
50+
l = (14.24 ± 0.2)u"m"
51+
thickness = u"μm"(mass/*width*l))
52+
@test thickness (21.3 ± 1.8)u"μm"
53+
4654
end
4755

4856
end

0 commit comments

Comments
 (0)