diff --git a/src/Unitful.jl b/src/Unitful.jl index 9eb3339d..1a732189 100644 --- a/src/Unitful.jl +++ b/src/Unitful.jl @@ -787,7 +787,7 @@ isless(x::Number, y::Quantity) = _isless(promote(x,y)...) end isapprox{T,D,U}(x::Quantity{T,D,U}, y::Quantity{T,D,U}; atol=zero(Quantity{real(T),D,U}), kwargs...) = - isapprox(x.val, y.val; atol=atol.val, kwargs...) + isapprox(x.val, y.val; atol=uconvert(unit(y), atol).val, kwargs...) isapprox(x::Quantity, y::Quantity; kwargs...) = isapprox(uconvert(unit(y), x).val, y.val; kwargs...) isapprox(x::Quantity, y::Number; kwargs...) = isapprox(uconvert(NoUnits, x), y; kwargs...) isapprox(x::Number, y::Quantity; kwargs...) = isapprox(y,x; kwargs...) diff --git a/test/runtests.jl b/test/runtests.jl index 9bd03c64..9338e8ba 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -397,6 +397,8 @@ end @test isapprox(1.0u"m", 1.1u"m"; atol=0.2u"m") @test !isapprox(1.0u"m", 1.1u"m"; atol=0.05u"m") + @test isapprox(1.0u"m", 1.1u"m"; atol=200u"mm") + @test !isapprox(1.0u"m", 1.1u"m"; atol=50u"mm") @test isapprox(1.0u"m", 1.1u"m"; rtol=0.2) @test !isapprox(1.0u"m", 1.1u"m"; rtol=0.05) end