A Julia package for physical units. Available here. Inspired by:
We want to support not only SI units but also any other unit system. We also want to minimize or in some cases eliminate the run-time penalty of units. There should be facilities for dimensional analysis. All of this should integrate easily with the usual mathematical operations and collections that are defined in Julia.
- This package requires Julia 0.6. Older versions will not be supported.
Unitful aims for generality, but has some useful functionality out of the box.
- Base dimensions like length, mass, time, etc. are defined.
- Derived dimensions like volume, energy, momentum, etc. are defined.
- Base and derived SI units with their power-of-ten prefixes are defined.
- Some other common units are defined, without power-of-ten prefixes.
- Sensible default promotion behavior is specified.
Take a look at
src/pkgdefaults.jl for a complete list. Note that some unit abbreviations conflict with other definitions or syntax:
inchis used instead of
inconflicts with Julia syntax
minuteis used instead of
minis a commonly used function
hris used instead of
his revered as the Planck constant
Important note on namespaces
Units, dimensions, and fundamental constants are not exported from Unitful. This is to avoid proliferating symbols in your namespace unnecessarily. You can retrieve them from Unitful in one of three ways:
- Use the
- Explicitly import from the
Unitfulpackage to bring specific symbols into the calling namespace.
using Unitful.DefaultSymbolswill bring the following symbols into the calling namespace:
𝐋,𝐌,𝐓,𝐈,𝚯,𝐉,𝐍for length, mass, time, current, temperature,
luminosity, and amount, respectively.
- Base and derived SI units, with SI prefixes (except for
cd, which conflicts with
If you have been using the SIUnits.jl package, this is not unlike typing
using SIUnits.ShortUnits with that package.
julia> 1u"kg" == 1000u"g" # Equivalence implies unit conversion true julia> !(1u"kg" === 1000u"g") # ...and yet we can distinguish these... true julia> 1u"kg" === 1u"kg" # ...and these are indistinguishable. true
In the next examples we assume we have brought some units into our namespace, e.g. using
m = u"m", etc.
julia> uconvert(°C, 212°F) 100//1 °C julia> uconvert(μm/(m*°F), 9μm/(m*°C)) 5//1 °F^-1 μm m^-1 julia> mod(1hr+3minute+5s, 24s) 17//1 s
test/runtests.jl for more usage examples.