From 19b5776cca43e6b6f9f36d24050c6d88183e4aa1 Mon Sep 17 00:00:00 2001 From: Chris Garling Date: Sun, 16 Feb 2025 22:58:49 -0500 Subject: [PATCH 1/6] Add docstring for `logunit` --- src/logarithm.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/logarithm.jl b/src/logarithm.jl index 3d679eaa..6ee8013d 100644 --- a/src/logarithm.jl +++ b/src/logarithm.jl @@ -9,6 +9,24 @@ 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 units associated with a logarithmic `Quantity`, a logarithmically-scaled +`Quantity` type, or a `Quantity` type with mixed logarithmic / linear scaling. + +Examples: +```jldoctest +julia> using Unitful + +julia> logunit(1*u"dB") +dB + +julia> logunit(u"dB") +dB +``` +""" +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}}() From f927270bf298bca219e2a2b4765b00a85e7f603a Mon Sep 17 00:00:00 2001 From: Chris Garling Date: Sun, 16 Feb 2025 23:00:57 -0500 Subject: [PATCH 2/6] Add `logunit` to the API docs --- docs/src/logarithm.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/logarithm.md b/docs/src/logarithm.md index c773c7ed..eda7b026 100644 --- a/docs/src/logarithm.md +++ b/docs/src/logarithm.md @@ -432,6 +432,7 @@ displaying logarithmic quantities: ## API ```@docs + Unitful.logunit Unitful.linear Unitful.reflevel Unitful.uconvertp From be37b19476d5fccea60aab0e2a96a3c773cdcec6 Mon Sep 17 00:00:00 2001 From: Chris Garling Date: Thu, 6 Mar 2025 22:17:24 -0500 Subject: [PATCH 3/6] Correct logunit docstring Valid arguments to logunit are technically not `Quantity` so be more careful about wording --- src/logarithm.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/logarithm.jl b/src/logarithm.jl index 6ee8013d..f702f8fb 100644 --- a/src/logarithm.jl +++ b/src/logarithm.jl @@ -12,8 +12,8 @@ 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 units associated with a logarithmic `Quantity`, a logarithmically-scaled -`Quantity` type, or a `Quantity` type with mixed logarithmic / linear scaling. +Returns the units associated with a `LogScaled` instance, a `LogScaled` type, +or a `MixedUnits`. Examples: ```jldoctest From 14360f09af2e10d8accc25cc2f16867995917788 Mon Sep 17 00:00:00 2001 From: Chris Garling Date: Mon, 19 May 2025 19:47:36 -0400 Subject: [PATCH 4/6] Implement sostock's feedback --- src/logarithm.jl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/logarithm.jl b/src/logarithm.jl index f702f8fb..346a45c4 100644 --- a/src/logarithm.jl +++ b/src/logarithm.jl @@ -12,8 +12,8 @@ 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 units associated with a `LogScaled` instance, a `LogScaled` type, -or a `MixedUnits`. +Returns the logarithmic "units" associated with a `LogScaled` instance, a +`LogScaled` type, or a `MixedUnits`. Examples: ```jldoctest @@ -24,7 +24,12 @@ 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}}() From 2735d372ce1335fded2533c0551b8c1cf94c0d9a Mon Sep 17 00:00:00 2001 From: Chris Garling Date: Mon, 19 May 2025 19:50:52 -0400 Subject: [PATCH 5/6] Add ref from unit to logunit --- src/utils.jl | 2 ++ 1 file changed, 2 insertions(+) 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() From 5a4daea540d39305db13d4513183d1570938be9b Mon Sep 17 00:00:00 2001 From: Chris Garling Date: Tue, 3 Jun 2025 08:23:52 -0400 Subject: [PATCH 6/6] respect alphabetical ordering --- docs/src/logarithm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/logarithm.md b/docs/src/logarithm.md index eda7b026..116f2197 100644 --- a/docs/src/logarithm.md +++ b/docs/src/logarithm.md @@ -432,8 +432,8 @@ displaying logarithmic quantities: ## API ```@docs - Unitful.logunit Unitful.linear + Unitful.logunit Unitful.reflevel Unitful.uconvertp Unitful.uconvertrp