![]() |
Shamrock 2025.10.0
Astrophysical Code
|
A unit system, defined by the SI value of its base units. More...
#include <shamunits/include/shamunits/UnitSystem.hpp>
Public Types | |
| template<class Tret> | |
| using | acc_t = decltype(T{} * Tret{} * double{}) |
| Accumulation type of the Unit-value getters: the widest of T, Tret and double. | |
Public Member Functions | |
| constexpr | UnitSystem (T unit_time=1, T unit_length=1, T unit_mass=1, T unit_current=1, T unit_temperature=1, T unit_qte=1, T unit_lumint=1) |
| Construct a new UnitSystem from either supplied base units or SI by default. | |
| template<Unit u, class Tret = T> | |
| constexpr Tret | get () const noexcept |
| Value of the compile-time unit u in this system. | |
| template<Unit u, class Tret = T> | |
| constexpr Tret | to () const noexcept |
| template<class Tret = T, class Tu> | |
| constexpr Tret | get (Unit< Tu > u) const noexcept |
| template<class Tret = T, class Tu> | |
| constexpr Tret | get (Unit< Tu > u, int power) const noexcept |
| template<class Tret = T, class Tu> | |
| constexpr Tret | to (Unit< Tu > u) const noexcept |
| Inverse of get(u). | |
| template<class Tret = T, class Tu> | |
| constexpr Tret | to (Unit< Tu > u, int power) const noexcept |
| Inverse of get(u, power). | |
Public Attributes | |
| T | s |
| value of a second in this system | |
| T | m |
| value of a metre in this system | |
| T | kg |
| value of a kilogram in this system | |
| T | A |
| value of an ampere in this system | |
| T | K |
| value of a kelvin in this system | |
| T | mol |
| value of a mole in this system | |
| T | cd |
| value of a candela in this system | |
| T | s_inv |
| inverse value of a second in this system (the time unit in s) | |
| T | m_inv |
| inverse value of a metre in this system (the length unit in m) | |
| T | kg_inv |
| inverse value of a kilogram in this system (the mass unit in kg) | |
| T | A_inv |
| inverse value of an ampere in this system | |
| T | K_inv |
| inverse value of a kelvin in this system | |
| T | mol_inv |
| inverse value of a mole in this system | |
| T | cd_inv |
| inverse value of a candela in this system | |
A unit system, defined by the SI value of its base units.
Units, prefixes and constants come from shamunits/unit_table.hpp, shamunits/prefix_table.hpp and shamunits/constant_table.hpp, and compose freely:
Definition at line 49 of file UnitSystem.hpp.
| using shamunits::UnitSystem< T >::acc_t = decltype(T{} * Tret{} * double{}) |
Accumulation type of the Unit-value getters: the widest of T, Tret and double.
Definition at line 102 of file UnitSystem.hpp.
|
inlineexplicitconstexpr |
Construct a new UnitSystem from either supplied base units or SI by default.
| unit_time | |
| unit_length | |
| unit_mass | |
| unit_current | |
| unit_temperature | |
| unit_qte | |
| unit_lumint |
Definition at line 77 of file UnitSystem.hpp.
|
inlineconstexprnoexcept |
Value of the compile-time unit u in this system.
u is a by-value template parameter, so every exponent is a constant expression: dimensions with exponent 0 expand to nothing. The parameter is Unit u (deduced) on purpose; it compiles on clang 15. Never replace it with a raw double template parameter, which clang < 18 rejects.
Definition at line 121 of file UnitSystem.hpp.
|
inlineconstexprnoexcept |
Value of a unit only known at run time (e.g. looked up by name). Exponents are runtime values; the stored *_inv members serve negative exponents, so there is no division.
Definition at line 146 of file UnitSystem.hpp.
|
inlineconstexprnoexcept |
get(u) for u raised to a runtime power: exactly get(upow(u, power)). The only entry point that can divide (in upow, for power < 0); this is the Python path.
Definition at line 161 of file UnitSystem.hpp.
|
inlineconstexprnoexcept |
Inverse of get<u>(): one unit of this system expressed in u, e.g. to<units::kilogram>() is the code mass unit in kg. The reciprocal of the factor is a constant expression, so this does not divide either.
Definition at line 139 of file UnitSystem.hpp.
|
inlineconstexprnoexcept |
Inverse of get(u).
Definition at line 167 of file UnitSystem.hpp.
|
inlineconstexprnoexcept |
Inverse of get(u, power).
Definition at line 173 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::A |
value of an ampere in this system
Definition at line 54 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::A_inv |
inverse value of an ampere in this system
Definition at line 61 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::cd |
value of a candela in this system
Definition at line 57 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::cd_inv |
inverse value of a candela in this system
Definition at line 64 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::K |
value of a kelvin in this system
Definition at line 55 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::K_inv |
inverse value of a kelvin in this system
Definition at line 62 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::kg |
value of a kilogram in this system
Definition at line 53 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::kg_inv |
inverse value of a kilogram in this system (the mass unit in kg)
Definition at line 60 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::m |
value of a metre in this system
Definition at line 52 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::m_inv |
inverse value of a metre in this system (the length unit in m)
Definition at line 59 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::mol |
value of a mole in this system
Definition at line 56 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::mol_inv |
inverse value of a mole in this system
Definition at line 63 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::s |
value of a second in this system
Definition at line 51 of file UnitSystem.hpp.
| T shamunits::UnitSystem< T >::s_inv |
inverse value of a second in this system (the time unit in s)
Definition at line 58 of file UnitSystem.hpp.