Skip to content

Commit 80feacf

Browse files
authored
Merge be53711 into 49623e0
2 parents 49623e0 + be53711 commit 80feacf

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/quantities.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,19 @@ for (i,j) in zip((:<, :isless), (:_lt, :_isless))
274274
@eval @inline ($j)(x::AbstractQuantity{T,D,U}, y::AbstractQuantity{T,D,U}) where {T,D,U} = ($i)(x.val,y.val)
275275
@eval @inline ($j)(x::AbstractQuantity{T,D,U1}, y::AbstractQuantity{T,D,U2}) where {T,D,U1,U2} = ($i)(promote(x,y)...)
276276
@eval @inline ($j)(x::AbstractQuantity{T,D1,U1}, y::AbstractQuantity{T,D2,U2}) where {T,D1,D2,U1,U2} = throw(DimensionError(x,y))
277+
278+
# comparison with dimensionless zero:
279+
NodimsQuantity{T} = DimensionlessQuantity{T,FreeUnits{(),NoDims,nothing}}
280+
@eval @inline ($j)(x::$NodimsQuantity{T}, y::ScalarQuantity{T,D,U}) where {T,D,U} =
281+
iszero(x) && !(y isa AffineQuantity) ?
282+
($i)(x.val,y.val) :
283+
throw(DimensionError(x,y))
284+
@eval @inline ($j)(x::ScalarQuantity{T,D,U}, y::$NodimsQuantity{T}) where {T,D,U} =
285+
iszero(y) && !(x isa AffineQuantity) ?
286+
($i)(x.val,y.val) :
287+
throw(DimensionError(x,y))
288+
# disambiguation:
289+
@eval @inline ($j)(x::$NodimsQuantity{T}, y::$NodimsQuantity{T}) where {T} = ($i)(x.val,y.val)
277290
end
278291

279292
Base.rtoldefault(::Type{<:AbstractQuantity{T,D,U}}) where {T,D,U} = Base.rtoldefault(T)

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,13 @@ Base.:*(x::MatNum, y::MatNum) = MatNum(x.mat*y.mat)
565565
@test @inferred(1 > 1μm/m)
566566
@test @inferred(1μm/m < 1mm/m)
567567
@test @inferred(1mm/m > 1μm/m)
568+
@test @inferred(0 < 2m)
569+
@test !@inferred(2mm < 0)
568570
@test_throws DimensionError 1m < 1kg
569571
@test_throws DimensionError 1m < 1
570572
@test_throws DimensionError 1 < 1m
571573
@test_throws DimensionError 1mm/m < 1m
574+
@test_throws DimensionError 0 < 100°C
572575
@test Base.rtoldefault(typeof(1.0u"m")) === Base.rtoldefault(typeof(1.0))
573576
@test Base.rtoldefault(typeof(1u"m")) === Base.rtoldefault(Int)
574577
end

0 commit comments

Comments
 (0)