Skip to content
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

Add documentation for logunit #769

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -432,6 +432,7 @@ displaying logarithmic quantities:
## API

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

Expand Down