24#define addget(uname) \
26 UnitPrefix pref = None, \
29 std::enable_if_t<u == units::uname, int> = 0> \
30 inline constexpr T get() const noexcept
33#define Uget(unitname, mult_pow) get<pref, units::unitname, (mult_pow) * power>()
35#define Cget(constant_name, mult_pow) \
36 details::pow_constexpr_fast_inv<(mult_pow) * power>(constant_name, T(1) / constant_name)
38#define PREF Cget((get_prefix_val<T, pref>()), 1)
80 inline static constexpr T pow_constexpr(T a, T a_inv)
noexcept {
84 inline T pown(T a,
int n) {
return std::pow(a, n); }
153 T unit_temperature = 1,
156 :
s(1 / unit_time),
m(1 / unit_length),
kg(1 / unit_mass),
A(1 / unit_current),
157 K(1 / unit_temperature),
mol(1 / unit_qte),
cd(1 / unit_lumint),
s_inv(unit_time),
170 template<UnitPrefix pref = None, units::UnitName u,
int power = 1>
171 inline constexpr T
get() const noexcept;
233 template<UnitPrefix pref = None, units::UnitName u,
int power = 1>
234 inline constexpr T
to() {
235 return get<u, -power>();
239 template<units::UnitName u,
int power = 1>
240 inline constexpr T
get() {
245 template<units::UnitName u,
int power = 1>
246 inline constexpr T
to() {
251 template<UnitPrefix pref = None>
297 inline T getter_2(
UnitPrefix pref, units::UnitName name) {
300 case tera :
return getter_1<tera>(name);
break;
301 case giga :
return getter_1<giga>(name);
break;
302 case mega :
return getter_1<mega>(name);
break;
303 case kilo :
return getter_1<kilo>(name);
break;
304 case hecto:
return getter_1<hecto>(name);
break;
305 case deca :
return getter_1<deca>(name);
break;
306 case None :
return getter_1<None>(name);
break;
308 case centi:
return getter_1<centi>(name);
break;
309 case milli:
return getter_1<milli>(name);
break;
310 case micro:
return getter_1<micro>(name);
break;
311 case nano :
return getter_1<nano>(name);
break;
312 case pico :
return getter_1<pico>(name);
break;
313 case femto:
return getter_1<femto>(name);
break;
320 return pown(getter_2(pref, name), power);
325 return pown(getter_2(pref, name), -power);
#define Uget(unitname, mult_pow)
Utility macro to get the value of a unit in the current unit system with its power.
#define Cget(constant_name, mult_pow)
Utility macro to get the value of a constant in the current unit system with its power.
UnitName
List of all units name.
#define addget(uname)
Macro to add a unit getter.
#define PREF
Shorthand for prefix handling.
constexpr T to()
Simplified signature for to without prefix.
constexpr T get() const noexcept
get the value of a units in the current system
constexpr T to()
To the si units (convert a system unit to si ones). This function is the inverse of get.
constexpr T get()
Simplified signature for get without prefix.
T runtime_to(UnitPrefix pref, units::UnitName name, int power)
Non templated version of to.
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.
T runtime_get(UnitPrefix pref, units::UnitName name, int power)
Non templated version of get.
namespace containing the units library
UnitPrefix
Enum of all prefixes.
static constexpr T dy_to_s
conversion factor from days to seconds
static constexpr T pc_to_m
conversion factor from parsecs to meters
static constexpr T rsol_to_m
conversion factor from solar radii to meters
static constexpr T mn_to_s
conversion factor from minutes to seconds
static constexpr T ly_to_m
conversion factor from light years to meters
static constexpr T hr_to_s
conversion factor from hours to seconds
static constexpr T erg_to_J
conversion factor from ergs to joules
static constexpr T au_to_m
conversion factor from au to meters
static constexpr T yr_to_s
conversion factor from years to seconds
static constexpr T rearth_to_m
conversion factor from earth equatorial radii to meters
static constexpr T eV_to_J
conversion factor from electron volts to joules
static constexpr T litre_to_pint
conversion offset from litre to british pint
constexpr T pow_constexpr_fast_inv(T a, T a_inv) noexcept
Constexpr power expansion function with supplied inverse for negative values.