51 .second = a.second + b.second,
52 .metre = a.metre + b.metre,
53 .kilogram = a.kilogram + b.kilogram,
54 .ampere = a.ampere + b.ampere,
55 .kelvin = a.kelvin + b.kelvin,
56 .mole = a.mole + b.mole,
57 .candela = a.candela + b.candela,
64 .second = a.second - b.second,
65 .metre = a.metre - b.metre,
66 .kilogram = a.kilogram - b.kilogram,
67 .ampere = a.ampere - b.ampere,
68 .kelvin = a.kelvin - b.kelvin,
69 .mole = a.mole - b.mole,
70 .candela = a.candela - b.candela,
77 .second = d.second * n,
79 .kilogram = d.kilogram * n,
80 .ampere = d.ampere * n,
81 .kelvin = d.kelvin * n,
83 .candela = d.candela * n,
88 template<
class Tscal =
double>
98 template<
class Tdst,
class Tsrc>
100 return {.dim = u.dim, .si_factor =
static_cast<Tdst
>(u.si_factor)};
106 return {.dim = a.dim * b.dim, .si_factor = a.si_factor * b.si_factor};
112 return {.dim = a.dim / b.dim, .si_factor = a.si_factor / b.si_factor};
118 return {.dim = u.dim, .si_factor = s * u.si_factor};
124 return {.dim = u.dim, .si_factor = u.si_factor * s};
130 return {.dim = u.dim, .si_factor = u.si_factor / s};
136 return {.dim =
Dimension{} / u.dim, .si_factor = s / u.si_factor};
150 int k = (n < 0) ? -n : n;
160 return {.dim =
dim_pow(u.dim, n), .si_factor = (n < 0) ? T(1) / f : f};
164 template<
class T =
double>
166 return {.dim = d, .si_factor = T(1)};
172 return {.dim =
Dimension{}, .si_factor = s};
namespace containing the units library
constexpr Unit< T > scale(T s) noexcept
A dimensionless scale factor, e.g. a prefix: scale(1e6) (precision of the argument).
constexpr Dimension dim_pow(Dimension d, int n) noexcept
Dimension raised to an integer power: exponents scale.
constexpr Dimension operator/(Dimension a, Dimension b) noexcept
Dimension of a quotient: exponents subtract.
constexpr Dimension operator*(Dimension a, Dimension b) noexcept
Dimension of a product: exponents add.
constexpr Unit< Tdst > unit_cast(Unit< Tsrc > u) noexcept
Explicit precision conversion, e.g. unit_cast<float>(units::metre).
constexpr Unit< T > base_unit(Dimension d) noexcept
A base unit of the given dimension with factor 1, e.g. base_unit({.metre = 1}).
constexpr Unit< T > upow(Unit< T > u, int n) noexcept
Integer power of a unit.
Exponents of the seven SI base dimensions.
int mole
amount of substance exponent
int kilogram
mass exponent
int kelvin
temperature exponent
int ampere
electric current exponent
constexpr bool operator==(const Dimension &) const =default
Exponent-wise equality.
int candela
luminous intensity exponent
A unit: its dimension and its magnitude expressed in SI base units, in precision Tscal.
constexpr bool operator==(const Unit &) const =default
Exact equality of dimension and factor.
Dimension dim
SI dimension.
Tscal si_factor
value of one of this unit in SI base units