Skip to content

Commit

Permalink
Merge pull request #74 from ajkeller34/isapprox
Browse files Browse the repository at this point in the history
Fix isapprox problem introduced in 0.2.0
  • Loading branch information
ajkeller34 authored Mar 29, 2017
2 parents 94006dd + 1b3d7c5 commit 8f77d03
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
- v0.2.1
- Fixed `isapprox` bug.
- Added `DimensionlessQuantity` methods for `exp`, `exp10`, `exp2`, `expm1`, `log1p`,
`log2` [#71](https://github.com/ajkeller34/Unitful.jl/pull/71).
- v0.2.0
- `Units{N,D}` is now an abstract type. Different concrete types for units give different
behavior under conversion and promotion. The currently implemented concrete types are:
Expand All @@ -11,7 +15,7 @@
still use the old names for now, but please switch over to using `...Units` instead
of `...Unit` in this release as the old names will be removed in a future release.
- `c` is now a unit, to permit converting mass into `MeV/c^2`, for example. `c0` is
still a quantity equal to the speed of light in vacuum, in units of `m/s`
still a quantity equal to the speed of light in vacuum, in units of `m/s`
[#67](https://github.com/ajkeller34/Unitful.jl/issues/67).
- v0.1.5
- Patch for Julia PR [#20889](https://github.com/JuliaLang/julia/pull/20889), which
Expand Down
5 changes: 4 additions & 1 deletion src/Unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,10 @@ 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=uconvert(unit(y), atol).val, kwargs...)
isapprox(x::Quantity, y::Quantity; kwargs...) = isapprox(promote(x,y); kwargs...)
function isapprox(x::Quantity, y::Quantity; kwargs...)
dimension(x) != dimension(y) && return false
return isapprox(promote(x,y)...; kwargs...)
end
isapprox(x::Quantity, y::Number; kwargs...) = isapprox(uconvert(NoUnits, x), y; kwargs...)
isapprox(x::Number, y::Quantity; kwargs...) = isapprox(y, x; kwargs...)

Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ end
@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)

# Test promotion behavior
@test !isapprox(1.0u"m", 1.0u"s")
@test isapprox(1.0u"m", 1000.0u"mm")
@test_throws ErrorException isapprox(1.0*FixedUnits(u"m"), 1000.0*FixedUnits(u"mm"))
end
end

Expand Down

0 comments on commit 8f77d03

Please sign in to comment.