Skip to content

Commit 53a9a33

Browse files
committed
Print non-reals with parentheses
1 parent 5c7f069 commit 53a9a33

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/utils.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ Base.show(io::IO, d::AbstractDimensions) =
8484
s = replace(s, r"\s*$" => "")
8585
print(io, s)
8686
end
87-
Base.show(io::IO, q::AbstractQuantity) = print(io, ustrip(q), " ", dimension(q))
87+
Base.show(io::IO, q::AbstractQuantity{<:Real}) = print(io, ustrip(q), " ", dimension(q))
88+
Base.show(io::IO, q::AbstractQuantity) = print(io, "(", ustrip(q), ") ", dimension(q))
8889

8990
function dimension_name(::AbstractDimensions, k::Symbol)
9091
default_dimensions = (length="m", mass="kg", time="s", current="A", temperature="K", luminosity="cd", amount="mol")

test/unittests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ using Test
123123
@test_throws DimensionError 1.0 - Quantity(one(T), D, length=1)
124124
end
125125

126+
@test string((0.5 + 0.5im)*u"km/s") == "(500.0 + 500.0im) m s⁻¹"
127+
126128
x = Quantity(-1.2, length=2 // 5)
127129

128130
@test abs(x) == Quantity(1.2, length=2 // 5)

0 commit comments

Comments
 (0)