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

using logarithmic quantities #217

Closed
m-wells opened this issue Mar 27, 2019 · 0 comments
Closed

using logarithmic quantities #217

m-wells opened this issue Mar 27, 2019 · 0 comments

Comments

@m-wells
Copy link

m-wells commented Mar 27, 2019

(I posted this in an old pull request #103 and realized nobody would ever see it there)

I've been struggling with this all day and finally got it to work. I had to do a lot of digging and I think the documentation could benefit from some clarification. I deal with logarithmic quantities all the time in astronomy so this is quite useful to me.

julia> using Unitful

julia> import Unitful:d

julia> @logscale Log₁₀ "Log₁₀" LogBase10 10 1 false
Log₁₀

julia> @logunit log₁₀d "log₁₀(days)" LogBase10 1d
log₁₀(days)

julia> Unitful.isrootpower_dim(::typeof(dimension(d))) = false

julia> foo = 3*log₁₀d
3.0 log₁₀(days)

julia> uconvert(u"d", foo)
1000.0 d

julia> bar = 0.3*log₁₀d
0.3 log₁₀(days)

julia> uconvert(u"d", bar)
1.9952623149688795 d

The isrootpower_dim is required to avoid the following:

julia> foo = 3*log₁₀d
ERROR: undefined behavior. Please file an issue with the code needed to reproduce.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] isrootpower_dim(::Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}) at /home/mark/.julia/packages/Unitful/W0mMi/src/logarithm.jl:200
 [3] isrootpower(::Quantity{Int64,𝐓,Unitful.FreeUnits{(d,),𝐓,nothing}}) at /home/mark/.julia/packages/Unitful/W0mMi/src/logarithm.jl:199
 [4] fromlog(::Type, ::Quantity{Int64,𝐓,Unitful.FreeUnits{(d,),𝐓,nothing}}, ::Int64) at /home/mark/.julia/packages/Unitful/W0mMi/src/logarithm.jl:116
 [5] *(::Int64, ::Unitful.MixedUnits{Level{Unitful.LogInfo{:LogBase10,10,1},1 d,T} where T<:Number,Unitful.FreeUnits{(),NoDims,nothing}}) at /home/mark/.julia/packages/Unitful/W0mMi/src/logarithm.jl:147
 [6] top-level scope at none:0
@m-wells m-wells closed this as completed Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant