Skip to content

Commit

Permalink
Merge pull request #58 from simonbyrne/sb/isapprox
Browse files Browse the repository at this point in the history
fix isapprox units
  • Loading branch information
ajkeller34 authored Mar 6, 2017
2 parents b714b69 + 4409f44 commit ead2d96
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ead2d96

Please sign in to comment.