From 9bd63b4bd42855b8b44609e466daeee8f47762a6 Mon Sep 17 00:00:00 2001 From: Andrew Keller Date: Wed, 5 Jul 2017 11:42:58 -0700 Subject: [PATCH] Implement Base.rtoldefault for Quantity types --- NEWS.md | 4 ++++ src/Unitful.jl | 1 + test/runtests.jl | 4 +++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index afee15a6..b089980b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +- v0.2.6 + - Fix and close [#52](https://github.com/ajkeller34/Unitful.jl/issues/52). + - Implement `Base.rtoldefault` for Quantity types + (needed for AxisArrays [#52](https://github.com/JuliaArrays/AxisArrays.jl/pull/52)). - v0.2.5 - Fix and close [#79](https://github.com/ajkeller34/Unitful.jl/issues/79). - Add support for `round(T, ::DimensionlessQuantity)` where `T <: Integer` diff --git a/src/Unitful.jl b/src/Unitful.jl index 708694bc..cdd95ca7 100644 --- a/src/Unitful.jl +++ b/src/Unitful.jl @@ -782,6 +782,7 @@ isless(x::Number, y::Quantity) = _isless(promote(x,y)...) .<=(x::Number, y::Quantity) = x <= y end +Base.rtoldefault{T,D,U}(::Type{Quantity{T,D,U}}) = Base.rtoldefault(T) 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=uconvert(unit(y), atol).val, kwargs...) function isapprox(x::Quantity, y::Quantity; kwargs...) diff --git a/test/runtests.jl b/test/runtests.jl index 306bf107..4d9618f9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -365,7 +365,7 @@ end end @testset "Mathematics" begin - @testset "> Ordered comparisons" begin + @testset "> Comparisons" begin # make sure we are just picking one of the arguments, without surprising conversions # happening to the units... @test min(1FreeUnits(hr), 1FreeUnits(s)) === 1FreeUnits(s) @@ -403,6 +403,8 @@ end @test_throws DimensionError 1m < 1 @test_throws DimensionError 1 < 1m @test_throws DimensionError 1mm/m < 1m + @test Base.rtoldefault(typeof(1.0u"m")) === Base.rtoldefault(typeof(1.0)) + @test Base.rtoldefault(typeof(1u"m")) === Base.rtoldefault(Int) end @testset "> Addition and subtraction" begin @test @inferred(+(1A)) == 1A # Unary addition