Unitful.jl
Unitful.jl copied to clipboard
Question: How to decompose units into sub-units?
If I have a unit that I know is energy/length^3 is there a way I can pull out the unit for energy and the unit for length separately?
Thanks!
There is no easy way built into this package, but you could use the following function to extract the individual units of a Units object into a Tuple:
function unit_tuple(u::Unitful.Units{N}) where N
length(N) == 1 ? (Unitful.FreeUnits(u),) : map(x -> Unitful.FreeUnits{(x,),dimension(x),nothing}(), N)
end
The branch for length(N) == 1 is only necessary for affine units (without it, unittuple(°C) would return K).