Skip to content

Add documentation for logunit #769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/logarithm.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ displaying logarithmic quantities:

```@docs
Unitful.linear
Unitful.logunit
Unitful.reflevel
Unitful.uconvertp
Unitful.uconvertrp
Expand Down
23 changes: 23 additions & 0 deletions src/logarithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}()

Expand Down
2 changes: 2 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading