Skip to content

Commit

Permalink
Implement Base.rtoldefault for Quantity types
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkeller34 committed Jul 5, 2017
1 parent 9e3525d commit 9bd63b4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
1 change: 1 addition & 0 deletions src/Unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9bd63b4

Please sign in to comment.