Skip to content

Commit

Permalink
Fix issue #110.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkeller34 committed Dec 5, 2017
1 parent 2429f48 commit e6f35cb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/logarithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ Base. *(x::Gain, y::Quantity) = *(y,x)
# Division
Base. /(x::Level, y::Number) = (leveltype(x))(linear(x) / y)
Base. /(x::Level, y::Quantity) = linear(x) / y
Base. /(x::Quantity, y::Level) = x / linear(y)
Base. /(x::Level, y::Level) = linear(x) / linear(y)
Base. /(x::Level{L,S}, y::Gain{L}) where {L,S} = Level{L,S}(fromlog(L, S, ustrip(x) - y.val))
Base. //(x::Level, y::Number) = (leveltype(x))(linear(x) // y)
Expand Down
6 changes: 4 additions & 2 deletions src/quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ end
//(x::Units, y::Number) = (1//y) * x

/(x::Quantity, y::Quantity) = Quantity(/(x.val, y.val), unit(x) / unit(y))
/(x::Quantity, y::Number) = Quantity(/(x.val, y), unit(x) / unit(y))
/(x::Number, y::Quantity) = Quantity(/(x, y.val), unit(x) / unit(y))
//(x::Quantity, y::Quantity) = Quantity(//(x.val, y.val), unit(x) / unit(y))
//(x::Quantity, y::Number) = Quantity(//(x.val, y), unit(x))
//(x::Number, y::Quantity) = Quantity(//(x, y.val), inv(unit(y)))
//(x::Quantity, y::Number) = Quantity(//(x.val, y), unit(x) // unit(y))
//(x::Number, y::Quantity) = Quantity(//(x, y.val), unit(x) / unit(y))

# ambiguity resolution
//(x::Quantity, y::Complex) = Quantity(//(x.val, y), unit(x))
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ end
@test @inferred(false*1kg) === 0kg # Boolean multiplication (F)
end
@testset "> Division" begin
@test 360° / 2 === 180.0° # Issue 110
@test 360° // 2 === 180°//1
@test 2m // 5s == (2//5)*(m/s) # Units propagate through rationals
@test (2//3)*m // 5 == (2//15)*m # Quantity // Real
@test 5.0m // s === 5.0m/s # Quantity // Unit. Just pass units through
Expand Down Expand Up @@ -529,7 +531,7 @@ 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 eps
@test eps(1.0u"s") == eps(1.0)u"s"
@test eps(typeof(1.0u"s")) == eps(Float64)u"s"
Expand Down

0 comments on commit e6f35cb

Please sign in to comment.