Skip to content

Commit

Permalink
Merge pull request PainterQubits#212 from giordano/ustrip-nounits
Browse files Browse the repository at this point in the history
Remove type annotation on last argument of ustrip methods
  • Loading branch information
ajkeller34 authored Jun 11, 2019
2 parents 7cd81f4 + 4a93bef commit 9f62987
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ julia> ustrip(Float64, u"m", 2u"mm") == 0.002
true
```
"""
@inline ustrip(u::Units, x::Quantity) = ustrip(uconvert(u, x))
@inline ustrip(T::Type, u::Units, x::Quantity) = convert(T, ustrip(u, x))
@inline ustrip(u::Units, x) = ustrip(uconvert(u, x))
@inline ustrip(T::Type, u::Units, x) = convert(T, ustrip(u, x))

"""
ustrip(x::Number)
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ end
@test @inferred(ustrip(m, 3.0m)) === 3.0
@test @inferred(ustrip(m, 2mm)) === 1//500
@test @inferred(ustrip(mm, 3.0m)) === 3000.0
@test @inferred(ustrip(NoUnits, 3.0m/1.0m)) === 3.0
@test @inferred(ustrip(NoUnits, 3.0m/1.0cm)) === 300.0
@test @inferred(ustrip(cm, missing)) === missing
@test @inferred(ustrip(NoUnits, missing)) === missing
@test_throws DimensionError ustrip(NoUnits, 3.0m/1.0s)
@test @inferred(ustrip(Float64, m, 2mm)) === 0.002
@test @inferred(ustrip(Int, mm, 2.0m)) === 2000
@test @inferred(ustrip(Float32, NoUnits, 5.0u"m"/2.0u"m")) === Float32(2.5)
@test @inferred(ustrip(Int, NoUnits, 3.0u"m"/1.0u"cm")) === 300
# convert
@test convert(typeof(1mm/m), 3) == 3000mm/m
@test convert(typeof(1mm/m), 3*NoUnits) == 3000mm/m
Expand Down

0 comments on commit 9f62987

Please sign in to comment.