diff --git a/docs/src/logarithm.md b/docs/src/logarithm.md index c773c7ed..116f2197 100644 --- a/docs/src/logarithm.md +++ b/docs/src/logarithm.md @@ -433,6 +433,7 @@ displaying logarithmic quantities: ```@docs Unitful.linear + Unitful.logunit Unitful.reflevel Unitful.uconvertp Unitful.uconvertrp diff --git a/src/logarithm.jl b/src/logarithm.jl index 3d679eaa..346a45c4 100644 --- a/src/logarithm.jl +++ b/src/logarithm.jl @@ -9,6 +9,29 @@ function Base.float(x::Level{L,S}) where {L,S} return Level{L,S,typeof(v)}(v) end big(x::Level{L,S}) where {L,S} = Level{L,S}(big(x.val)) +""" + logunit(x::LogScaled) + logunit(x::Union{Type{<:LogScaled}, MixedUnits}) +Returns the logarithmic "units" associated with a `LogScaled` instance, a +`LogScaled` type, or a `MixedUnits`. + +Examples: +```jldoctest +julia> using Unitful + +julia> logunit(1*u"dB") +dB + +julia> logunit(u"dB") +dB + +julia> logunit(u"dB/s") +dB +``` + +See also: [`unit`](@ref). +""" +function logunit end logunit(x::Level{L,S}) where {L,S} = MixedUnits{Level{L,S}}() logunit(x::Type{T}) where {L,S,T<:Level{L,S}} = MixedUnits{Level{L,S}}() diff --git a/src/utils.jl b/src/utils.jl index 5d717015..5adb9356 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -114,6 +114,8 @@ true julia> unit(typeof(1.0u"m")) == u"m" true ``` + +See also: [`logunit`](@ref). """ @inline unit(x::AbstractQuantity{T,D,U}) where {T,D,U} = U() @inline unit(::Type{<:AbstractQuantity{T,D,U}}) where {T,D,U} = U()