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

Idea for definition of conversion constants #81

Open
giordano opened this issue May 12, 2017 · 2 comments
Open

Idea for definition of conversion constants #81

giordano opened this issue May 12, 2017 · 2 comments

Comments

@giordano
Copy link
Collaborator

giordano commented May 12, 2017

Currently, the package isn't very arbitrary-precision-friendly, because conversion constants are often of Float64 type. My idea is to define them as Irrational:

julia> using Unitful

julia> Base.@irrational μ 1.256637061435917295385e-06 (4 * big(π) * (1//10) ^ 7)

julia> μ0 = μ * Unitful.H / Unitful.m 
μ = 1.2566370614359... H m^-1

julia> float(μ)
1.2566370614359173e-6

julia> float(Unitful.μ0.val)
1.2566370614359173e-6

julia> big(μ)
1.256637061435917295385057353311801153678867759750042328389977836923126562514468e-06

julia> big(float(μ))
1.256637061435917288506887261323452520400678622536361217498779296875000000000000e-06

julia> big(Unitful.μ0.val)
1.256637061435917288506887261323452520400678622536361217498779296875000000000000e-06

The last three lines show that in this way the conversion factor has full precision as a BigFloat.

Edit: I initially proposed to define a type that was a simplification of Irrational, but in the end there wasn't much difference between my custom type and Irrational.

@ajkeller34
Copy link
Collaborator

Sorry for not getting back to you earlier. I like this idea a lot. I'm a little worried that we'd get collisions because someone else might define Irrational{:μ}, otherwise it seems great.

In practice, I'd imagine we could avoid this by using the irrational macro with very unique names like _Unitful_μ. Unique Irrational{:_Unitful_μ} methods would result, as well as a _Unitful_μ symbol. Then we could just say μ = _Unitful_μ so that the symbol is cleaner but we still avoid type collisions.

Also, while I defined float for quantities, I neglected to define big apparently. That'd need to be done too.

I'll get to this eventually but would also welcome a PR if you're feeling up for it.

@giordano
Copy link
Collaborator Author

Thank you! I like your approach to avoid type collision.

I might have some time to bake a PR, but not anytime soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants