Skip to content

Commit

Permalink
Implement zero for affine quantities.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkeller34 committed Nov 1, 2018
1 parent 705ff3a commit 5909934
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,9 @@ for f in (:floor, :ceil, :trunc, :round)
end

zero(x::Quantity) = Quantity(zero(x.val), unit(x))
zero(x::AffineQuantity) =
throw(AffineError("no additive identity element of type $(typeof(x))."))
zero(x::AffineQuantity) = Quantity(zero(x.val), absoluteunit(x))
zero(x::Type{Quantity{T,D,U}}) where {T,D,U<:ScalarUnits} = zero(T)*U()
zero(x::Type{Quantity{T,D,U}}) where {T,D,U<:AffineUnits} =
throw(AffineError("no additive identity element of type $(typeof(x))."))
zero(x::Type{Quantity{T,D,U}}) where {T,D,U<:AffineUnits} = zero(T)*absoluteunit(U())

one(x::Quantity) = one(x.val)
one(x::AffineQuantity) =
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ end
@test_throws AffineError (32°F) / 2
@test_throws AffineError 2 / (32°F)

@test_throws AffineError zero(100°C)
@test_throws AffineError zero(typeof(100°C))
@test zero(100°C) === 0K
@test zero(typeof(100°C)) === 0K
@test_throws AffineError one(100°C)
@test_throws AffineError one(typeof(100°C))
@test_throws AffineError oneunit(100°C)
Expand Down

0 comments on commit 5909934

Please sign in to comment.