diff --git a/src/quantities.jl b/src/quantities.jl index 00277387..e7fa001b 100644 --- a/src/quantities.jl +++ b/src/quantities.jl @@ -274,6 +274,9 @@ for (i,j) in zip((:<, :isless), (:_lt, :_isless)) @eval @inline ($j)(x::AbstractQuantity{T,D,U}, y::AbstractQuantity{T,D,U}) where {T,D,U} = ($i)(x.val,y.val) @eval @inline ($j)(x::AbstractQuantity{T,D,U1}, y::AbstractQuantity{T,D,U2}) where {T,D,U1,U2} = ($i)(promote(x,y)...) @eval @inline ($j)(x::AbstractQuantity{T,D1,U1}, y::AbstractQuantity{T,D2,U2}) where {T,D1,D2,U1,U2} = throw(DimensionError(x,y)) + + @eval @inline ($j)(x::DimensionlessQuantity{T,FreeUnits{(),NoDims,nothing}}, y::ScalarQuantity{T,D,U}) where {T,D,U} = iszero(x) ? ($i)(x.val,y.val) : throw(DimensionError(x,y)) + @eval @inline ($j)(x::ScalarQuantity{T,D,U}, y::DimensionlessQuantity{T,FreeUnits{(),NoDims,nothing}}) where {T,D,U} = iszero(y) ? ($i)(x.val,y.val) : throw(DimensionError(x,y)) end Base.rtoldefault(::Type{<:AbstractQuantity{T,D,U}}) where {T,D,U} = Base.rtoldefault(T) diff --git a/test/runtests.jl b/test/runtests.jl index 583c5cd3..6741273c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -565,10 +565,13 @@ Base.:*(x::MatNum, y::MatNum) = MatNum(x.mat*y.mat) @test @inferred(1 > 1μm/m) @test @inferred(1μm/m < 1mm/m) @test @inferred(1mm/m > 1μm/m) + @test @inferred(0 < 2m) + @test !@inferred(2mm < 0) @test_throws DimensionError 1m < 1kg @test_throws DimensionError 1m < 1 @test_throws DimensionError 1 < 1m @test_throws DimensionError 1mm/m < 1m + @test_throws DimensionError 0 < 100°C @test Base.rtoldefault(typeof(1.0u"m")) === Base.rtoldefault(typeof(1.0)) @test Base.rtoldefault(typeof(1u"m")) === Base.rtoldefault(Int) end