Skip to content

Commit 38ef94a

Browse files
committed
Clean up zero and oneunit
1 parent 5779e63 commit 38ef94a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/utils.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ Base.one(q::Quantity) = one(typeof(q))
5555
Base.one(d::Dimensions) = one(typeof(d))
5656

5757
# Additive identities:
58-
Base.zero(q::Q) where {T,Q<:Quantity{T}} = Quantity(zero(ustrip(q)), dimension(q))
59-
Base.zero(::D) where {D<:Dimensions} = error("There is no such thing as an additive identity for a `Dimensions` object, as + is only defined for `Quantity`.")
60-
Base.zero(::Type{Q}) where {Q<:Quantity} = error("Cannot create an additive identity for a `Quantity` type, as the dimensions are unknown. Please use `zero(::Quantity)` instead.")
61-
Base.zero(::Type{D}) where {D<:Dimensions} = error("There is no such thing as an additive identity for a `Dimensions` type, as + is only defined for `Quantity`.")
58+
Base.zero(q::Quantity) = Quantity(zero(ustrip(q)), dimension(q))
59+
Base.zero(::Dimensions) = error("There is no such thing as an additive identity for a `Dimensions` object, as + is only defined for `Quantity`.")
60+
Base.zero(::Type{<:Quantity}) = error("Cannot create an additive identity for a `Quantity` type, as the dimensions are unknown. Please use `zero(::Quantity)` instead.")
61+
Base.zero(::Type{<:Dimensions}) = error("There is no such thing as an additive identity for a `Dimensions` type, as + is only defined for `Quantity`.")
6262

6363
# Dimensionful 1:
64-
Base.oneunit(q::Q) where {T,Q<:Quantity{T}} = Quantity(oneunit(ustrip(q)), dimension(q))
65-
Base.oneunit(::Type{Q}) where {Q<:Quantity} = error("Cannot create a dimensionful 1 for a `Quantity` type without knowing the dimensions. Please use `oneunit(::Quantity)` instead.")
66-
Base.oneunit(::D) where {D<:Dimensions} = error("There is no such thing as a dimensionful 1 for a `Dimensions` object, as + is only defined for `Quantity`.")
67-
Base.oneunit(::Type{D}) where {D<:Dimensions} = error("There is no such thing as a dimensionful 1 for a `Dimensions` type, as + is only defined for `Quantity`.")
64+
Base.oneunit(q::Quantity) = Quantity(oneunit(ustrip(q)), dimension(q))
65+
Base.oneunit(::Dimensions) = error("There is no such thing as a dimensionful 1 for a `Dimensions` object, as + is only defined for `Quantity`.")
66+
Base.oneunit(::Type{<:Quantity}) = error("Cannot create a dimensionful 1 for a `Quantity` type without knowing the dimensions. Please use `oneunit(::Quantity)` instead.")
67+
Base.oneunit(::Type{<:Dimensions}) = error("There is no such thing as a dimensionful 1 for a `Dimensions` type, as + is only defined for `Quantity`.")
6868

6969
Base.show(io::IO, d::Dimensions) =
7070
let tmp_io = IOBuffer()

0 commit comments

Comments
 (0)