JuliaPhysics / JuliaPhysics/Unitful.jl
Should `uconvert` (inconsistently) change its argument's precision?
- Dominant language
- Julia
- Stars
- 675
- Forks
- 124
- Avg merge
- 3h 38m
- Merged PRs (30d)
- 1
Description
In the following example, `uconvert` returns an object of different, `Float64`, precision from its `Float32`-based argument:
```julia
julia> dia = cbrt(1.0f0u"l")
1.0f0 L^1/3
julia> typeof(dia)
Quantity{Float32,𝐋,Unitful.FreeUnits{(L^1/3,),𝐋,nothing}}
julia> typeof(uconvert(Unitful.m, dia))
Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}
```
I expect unit conversions not to change the underlying precision, even more when `Unitful.jl`'s design include a precision parameter in its types.
Moreover, as a consistency note, other tests showed that the above mentioned behavior is inconsistent as well, thus making it hard to predict the exact return type of `uconvert` calls:
```julia
julia> oth = 1.0f0u"dm"
1.0f0 dm
julia> uconvert(Unitful.m, oth)
0.1f0 m
julia> typeof(uconvert(Unitful.m, oth))
Quantity{Float32,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}
```
Apologies if this is a duplicate, I scanned through the opened issues and none seemed to fit.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the two Julia REPL examples involving uconvert(Unitful.m, dia) and uconvert(Unitful.m, oth), then trace the conversion behavior in Unitful.jl. Done means conversions preserve the input's Float32 precision consistently, including the cbrt-based quantity, with tests covering both examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100