Expand description
Representation of quantites, i.e. of unit valued scalars and arrays.
The units are checked at compile time and can be arbitrarily complex. Additional to simple scalar quantities, it also provides utilities for vector valued quantities, based on the ndarray crate, where all entries share the same unit.
For details on the available methods, see the documentation of the Quantity struct.
§SI Base Units and Associated Constants
The module contains the seven SI base units and their associated, exact-valued constants.
Unit | Unit symbol | Quantity | Associated constant | Associated constant name | Associated constant value |
---|---|---|---|---|---|
SECOND | $\text{s}$ | time | DVCS | Hyperfine transition frequency of Cs | $\Delta\nu_\text{Cs}=9192631770\,\text{Hz}$ |
METER | $\text{m}$ | length | CLIGHT | Speed of light | $c=299792458\,\frac{\text{m}}{\text{s}}$ |
KILOGRAM | $\text{kg}$ | mass | PLANCK | Planck constant | $h=6.62607015\times 10^{-34}\,\text{J}\cdot\text{s}$ |
AMPERE | $\text{A}$ | electric current | QE | Elementary charge | $e=1.602176634\times 10^{-19}\,\text{C}$ |
KELVIN | $\text{K}$ | thermodynamic temperature | KB | Boltzmann constant | $k_\text{B}=1.380649\times 10^{-23}\,\frac{\text{J}}{\text{K}}$ |
MOL | $\text{mol}$ | amount of substance | NAV | Avogadro constant | $N_\text{A}=6.02214076\times 10^{23}\,\text{mol}^{-1}$ |
CANDELA | $\text{cd}$ | luminous intensity | KCD | Luminous efficacy of $540\,\text{THz}$ radiation | $K_\text{cd}=683\,\frac{\text{lm}}{\text{W}}$ |
§Derived Units
Additionally, it contains the following derived units.
Unit | Unit symbol | Quantity | Definition |
---|---|---|---|
HERTZ | $\text{Hz}$ | frequency | $\text{s}^{-1}$ |
NEWTON | $\text{N}$ | force, weight | $\text{kg}\frac{\text{m}}{\text{s}^2}$ |
PASCAL | $\text{Pa}$ | pressure, stress | $\frac{\text{N}}{\text{m}^2}$ |
JOULE | $\text{J}$ | energy, work, heat | $\text{N}\text{m}$ |
WATT | $\text{W}$ | power, radiant flux | $\frac{\text{J}}{\text{s}}$ |
COULOMB | $\text{C}$ | electric charge | $\text{A}\text{s}$ |
VOLT | $\text{V}$ | electrical potential difference | $\frac{\text{W}}{\text{A}}$ |
FARAD | $\text{F}$ | capacitance | $\frac{\text{C}}{\text{V}}$ |
OHM | $\text{Ω}$ | resistance, impedance, reactance | $\frac{\text{V}}{\text{A}}$ |
SIEMENS | $\text{S}$ | electrical conductance | $\text{Ω}^{-1}$ |
WEBER | $\text{Wb}$ | magnetic flux | $\text{V}\text{s}$ |
TESLA | $\text{T}$ | magnetic flux density | $\frac{\text{Wb}}{\text{m}^2}$ |
HENRY | $\text{H}$ | inductance | $\frac{\text{Wb}}{\text{A}}$ |
§Additional units
For convenience, a number of commonly used units that are not directly combinations of SI base units is also included. These constants simplify the specification of properties, that are not given in SI units. However, as the representation of quantities is unique, they do not appear in formatted outputs.
Unit | Unit symbol | Quantity | Definition |
---|---|---|---|
ANGSTROM | $\text{\AA}$ | length | $10^{-10}\,\text{m}$ |
AMU | $\text{u}$ | mass | $1.6605390671738466\times 10^{-27}\,\text{kg}$ |
AU | $\text{au}$ | length | $149597870700\,\text{m}$ |
BAR | $\text{bar}$ | pressure | $10^5\,\text{Pa}$ |
CALORIE | $\text{cal}$ | energy | $4.184\,\text{J}$ |
CELSIUS | $^\circ\text{C}$ | temperature | $t\,^\circ\text{C}=\left(t+273.15\right)\,\text{K}$ |
DAY | $\text{d}$ | time | $86400\,\text{s}$ |
DEGREES | $^\circ$ | angle | $\frac{\pi}{180}\,\text{rad}$ |
GRAM | $\text{g}$ | mass | $10^{-3}\,\text{kg}$ |
HOUR | $\text{h}$ | time | $3600\,\text{s}$ |
LITER | $\text{l}$ | volume | $10^{-3}\,\text{m}^3$ |
MINUTE | $\text{min}$ | time | $60\,\text{s}$ |
RADIANS | $\text{rad}$ | angle |
§Additional constants
Constant | Name | Symbol | Value |
---|---|---|---|
G | Gravitational constant | $G$ | $6.6743\times 10^{-11}\,\frac{\text{m}^3}{\text{kg}\cdot\text{s}^2}$ |
RGAS | Ideal gas constant | $R=N_\text{Av}k_\text{B}$ | $8.31446261815324\,\frac{\text{J}}{\text{mol}\cdot\text{K}}$ |
§Prefixes
All units can be combined with the following prefixes:
Prefix | Prefix symbol | value | Prefix | Prefix symbol | value | |
---|---|---|---|---|---|---|
DECI | $\text{d}$ | $10^{-1}$ | DECA | $\text{da}$ | $10^{1}$ | |
CENTI | $\text{c}$ | $10^{-2}$ | HECTO | $\text{h}$ | $10^{2}$ | |
MILLI | $\text{m}$ | $10^{-3}$ | KILO | $\text{k}$ | $10^{3}$ | |
MICRO | $\text{µ}$ | $10^{-6}$ | MEGA | $\text{M}$ | $10^{6}$ | |
NANO | $\text{n}$ | $10^{-9}$ | GIGA | $\text{G}$ | $10^{9}$ | |
PICO | $\text{p}$ | $10^{-12}$ | TERA | $\text{T}$ | $10^{12}$ | |
FEMTO | $\text{f}$ | $10^{-15}$ | PETA | $\text{P}$ | $10^{15}$ | |
ATTO | $\text{a}$ | $10^{-18}$ | EXA | $\text{E}$ | $10^{18}$ | |
ZEPTO | $\text{z}$ | $10^{-21}$ | ZETTA | $\text{Z}$ | $10^{21}$ | |
YOCTO | $\text{y}$ | $10^{-24}$ | YOTTA | $\text{Y}$ | $10^{24}$ | |
RONTO | $\text{r}$ | $10^{-27}$ | RONNA | $\text{R}$ | $10^{27}$ | |
QUECTO | $\text{q}$ | $10^{-30}$ | QUETTA | $\text{Q}$ | $10^{30}$ |
§Examples
Calculate pressure of an ideal gas.
let temperature = 25.0 * CELSIUS;
let volume = 1.5 * METER.powi::<P3>();
let moles = 75.0 * MOL;
let pressure = moles * RGAS * temperature / volume;
println!("{:.5}", pressure); // 123.94785 kPa
Calculate the gravitational pull of the moon on the earth.
let mass_earth = 5.9724e24 * KILOGRAM;
let mass_moon = 7.346e22 * KILOGRAM;
let distance = 383.398 * KILO * METER;
let force = G * mass_earth * mass_moon / distance.powi::<P2>();
println!("{:.5e}", force); // 1.99208e26 N
Calculate the pressure distribution in the atmosphere using the barometric formula.
Array operations require the ndarray
feature.
let z = Length::linspace(1.0 * METER, 70.0 * KILO * METER, 10);
let g = 9.81 * METER / SECOND.powi::<P2>();
let m = 28.949 * GRAM / MOL;
let t = 10.0 * CELSIUS;
let p0 = BAR;
let pressure = (-z.clone() * m * g).convert_to(RGAS * t).mapv(f64::exp) * p0;
for i in 0..10 {
println!("z = {:8.5} p = {:9.5}", z.get(i), pressure.get(i));
}
// z = 1.00000 m p = 99.98794 kPa
// z = 7.77867 km p = 39.12796 kPa
// z = 15.55633 km p = 15.31182 kPa
// z = 23.33400 km p = 5.99192 kPa
// z = 31.11167 km p = 2.34480 kPa
// z = 38.88933 km p = 917.58301 Pa
// z = 46.66700 km p = 359.07479 Pa
// z = 54.44467 km p = 140.51557 Pa
// z = 62.22233 km p = 54.98750 Pa
// z = 70.00000 km p = 21.51808 Pa
§Feature flags
Interoperability with other crates can be achieved by activating the following features:
ndarray
— Use N-dimensional arrays from the ndarray crate as value of a quantity.num-dual
— Use generalized (hyper-)dual numbers from the [num-dual] crate as value of a quantity.python
— Directly use (scalar) quantities in Python interfaces through pyo3 and the si-units package.python_numpy
— Use scalar and array quantities in Python interfaces through pyo3, numpy, and the si-units package.approx
— Enable approximate comparisons through the approx crate.
Structs§
Constants§
- AMPERE
- SI base unit Ampere $\left(\text{A}\right)$
- AMU
- Additional unit unified atomic mass $\left(1\,\text{u}\approx 1.660539\times 10^{-27}\,\text{kg}\right)$
- ANGSTROM
- Additional unit Ångstrom $\left(1\,\text{\AA}=10^{-10}\,\text{m}\right)$
- ATTO
- Prefix atto $\left(\text{a}=10^{-18}\right)$
- AU
- Additional unit astronomical unit $\left(1\,\text{au}=149597870700\,\text{m}\right)$
- BAR
- Additional unit bar $\left(1\,\text{bar}=10^5\,\text{Pa}\right)$
- CALORIE
- Additional unit calorie $\left(1\,\text{cal}=4.184\,\text{J}\right)$
- CANDELA
- SI base unit candela $\left(\text{cd}\right)$
- CENTI
- Prefix centi $\left(\text{c}=10^{-2}\right)$
- CLIGHT
- Speed of light $\left(c=299792458\,\frac{\text{m}}{\text{s}}\right)$
- COULOMB
- Derived unit Coulomb $\left(1\,\text{C}=1\,\text{A}\cdot\text{s}\right)$
- DAY
- Additional unit day $\left(1\,\text{d}=86400,\text{s}\right)$
- DECA
- Prefix deca $\left(\text{da}=10^{1}\right)$
- DECI
- Prefix deci $\left(\text{d}=10^{-1}\right)$
- DEGREES
- Angle unit degrees $\left(1°=\frac{\pi}{180}\text{rad}\right)$
- DVCS
- Hyperfine transition frequency of Cs $\left(\Delta\nu_\text{Cs}=9192631770\,\text{Hz}\right)$
- EXA
- Prefix exa $\left(\text{E}=10^{18}\right)$
- FARAD
- Derived unit Farad $\left(1\,\text{F}=1\,\frac{\text{C}}{\text{V}}\right)$
- FEMTO
- Prefix femto $\left(\text{f}=10^{-15}\right)$
- G
- Gravitational constant $\left(G=6.6743\times 10^{-11}\,\frac{\text{m}^3}{\text{kg}\cdot\text{s}^2}\right)$
- GIGA
- Prefix giga $\left(\text{G}=10^{9}\right)$
- GRAM
- Additional unit gram $\left(1\,\text{g}=10^{-3}\,\text{kg}\right)$
- HECTO
- Prefix hecto $\left(\text{h}=10^{2}\right)$
- HENRY
- Derived unit Henry $\left(1\,\text{T}=1\,\frac{\text{Wb}}{\text{A}}\right)$
- HERTZ
- Derived unit Hertz $\left(1\,\text{Hz}=1\,\text{s}^{-1}\right)$
- HOUR
- Additional unit hour $\left(1\,\text{h}=3600,\text{s}\right)$
- JOULE
- Derived unit Joule $\left(1\,\text{J}=1\,\text{kg}\frac{\text{m}^2}{\text{s}^2}\right)$
- KB
- Boltzmann constant $\left(k_\text{B}=1.380649\times 10^{-23}\,\frac{\text{J}}{\text{K}}\right)$
- KCD
- Luminous efficacy of $540\,\text{THz}$ radiation $\left(K_\text{cd}=683\,\frac{\text{lm}}{\text{W}}\right)$
- KELVIN
- SI base unit Kelvin $\left(\text{K}\right)$
- KILO
- Prefix kilo $\left(\text{k}=10^{3}\right)$
- KILOGRAM
- SI base unit kilogram $\left(\text{kg}\right)$
- LITER
- Additional unit liter $\left(1\,\text{l}=10^{-3}\,\text{m}^3\right)$
- MEGA
- Prefix mega $\left(\text{M}=10^{6}\right)$
- METER
- SI base unit meter $\left(\text{m}\right)$
- MICRO
- Prefix micro $\left(\text{µ}=10^{-6}\right)$
- MILLI
- Prefix milli $\left(\text{m}=10^{-3}\right)$
- MINUTE
- Additional unit minute $\left(1\,\text{min}=60,\text{s}\right)$
- MOL
- SI base unit mol $\left(\text{mol}\right)$
- NANO
- Prefix nano $\left(\text{n}=10^{-9}\right)$
- NAV
- Avogadro constant $\left(N_\text{A}=6.02214076\times 10^{23}\,\text{mol}^{-1}\right)$
- NEWTON
- Derived unit Newton $\left(1\,\text{N}=1\,\text{kg}\frac{\text{m}}{\text{s}^2}\right)$
- OHM
- Derived unit Ohm $\left(1\,\text{Ω}=1\,\frac{\text{V}}{\text{A}}\right)$
- PASCAL
- Derived unit Pascal $\left(1\,\text{Pa}=1\,\frac{\text{kg}}{\text{m}\cdot\text{s}^2}\right)$
- PETA
- Prefix peta $\left(\text{P}=10^{15}\right)$
- PICO
- Prefix pico $\left(\text{p}=10^{-12}\right)$
- PLANCK
- Planck constant $\left(h=6.62607015\times 10^{-34}\,\text{J}\cdot\text{s}\right)$
- QE
- Elementary charge $\left(e=1.602176634\times 10^{-19}\,\text{C}\right)$
- QUECTO
- Prefix quecto $\left(\text{q}=10^{-30}\right)$
- QUETTA
- Prefix quetta $\left(\text{Q}=10^{30}\right)$
- RADIANS
- Angle unit radians $\left(\text{rad}\right)$
- RGAS
- Ideal gas constant $\left(R=8.31446261815324\,\frac{\text{J}}{\text{molK}}\right)$
- RONNA
- Prefix ronna $\left(\text{R}=10^{27}\right)$
- RONTO
- Prefix ronto $\left(\text{r}=10^{-27}\right)$
- SECOND
- SI base unit second $\left(\text{s}\right)$
- SIEMENS
- Derived unit Siemens $\left(1\,\text{S}=1\,\text{Ω}^{-1}\right)$
- TERA
- Prefix tera $\left(\text{T}=10^{12}\right)$
- TESLA
- Derived unit Tesla $\left(1\,\text{T}=1\,\frac{\text{Wb}}{\text{m}^2}\right)$
- VOLT
- Derived unit Volt $\left(1\,\text{V}=1\,\frac{\text{W}}{\text{A}}\right)$
- WATT
- Derived unit Watt $\left(1\,\text{J}=1\,\text{kg}\frac{\text{m}^2}{\text{s}^3}\right)$
- WEBER
- Derived unit Weber $\left(1\,\text{Wb}=1\,\text{V}\cdot\text{s}\right)$
- YOCTO
- Prefix yocto $\left(\text{y}=10^{-24}\right)$
- YOTTA
- Prefix yotta $\left(\text{Y}=10^{24}\right)$
- ZEPTO
- Prefix zepto $\left(\text{z}=10^{-21}\right)$
- ZETTA
- Prefix zetta $\left(\text{Z}=10^{21}\right)$
Type Aliases§
- Acceleration
- Action
- Angle
- Area
- Capacitance
- Charge
- Compressibility
- Current
- Density
- Diffusivity
- Dimensionless
- Electric
Potential - Electrical
Conductance - Energy
- Entropy
- Entropy
Density - Entropy
PerTemperature - Force
- Frequency
- Heat
Capacity Rate - Heat
Flux - Inductance
- Length
- Luminous
Intensity - Magnetic
Flux - Magnetic
Flux Density - Mass
- Mass
Density - Mass
Flow Rate - Mass
Flux - Molar
Energy - Molar
Entropy - Molar
Volume - Molar
Weight - Mole
Flow Rate - Moles
- Power
- Pressure
- Pressure
PerTemperature - Pressure
PerVolume - Resistance
- SIUnit
- Specific
Energy - Specific
Entropy - Surface
Tension - Temperature
- Thermal
Conductivity - Thermal
Resistance - Thermal
Transmittance - Time
- Velocity
- Viscosity
- Volume
- _Acceleration
- _Action
- _Area
- _Capacitance
- _Charge
- _Compressibility
- _Current
- _Density
- _Diffusivity
- _Dimensionless
- _Electric
Potential - _Electrical
Conductance - _Energy
- _Entropy
- _Entropy
Density - _Entropy
PerTemperature - _Force
- _Frequency
- _Heat
Capacity Rate - _Heat
Flux - _Inductance
- _Length
- _Luminous
Intensity - _Magnetic
Flux - _Magnetic
Flux Density - _Mass
- _Mass
Density - _Mass
Flow Rate - _Mass
Flux - _Molar
Energy - _Molar
Entropy - _Molar
Volume - _Molar
Weight - _Mole
Flow Rate - _Moles
- _Power
- _Pressure
- _Pressure
PerTemperature - _Pressure
PerVolume - _Resistance
- _Specific
Energy - _Specific
Entropy - _Surface
Tension - _Temperature
- _Thermal
Conductivity - _Thermal
Resistance - _Thermal
Transmittance - _Time
- _Velocity
- _Viscosity
- _Volume