feat: Magnitude / Unit operator added

This commit is contained in:
Mateusz Pusz
2023-09-30 21:36:23 -06:00
parent f15baf4c2a
commit 04588d9c8b
2 changed files with 10 additions and 1 deletions

View File

@@ -430,6 +430,15 @@ template<Unit Lhs, Unit Rhs>
return detail::expr_multiply<derived_unit, struct one, detail::type_list_of_unit_less>(lhs, rhs);
}
/**
* Returns the result of multiplication with an inverse unit.
*/
template<Magnitude M, Unit U>
[[nodiscard]] MP_UNITS_CONSTEVAL Unit auto operator/(M mag, const U u)
{
return mag * (1 / u);
}
/**
* `scaled_unit` specializations have priority in this operation. This means that the library framework
* prevents passing it as an element to the `derived_unit`. In such case only the reference unit is passed

View File

@@ -41,7 +41,7 @@ inline constexpr struct elementary_charge :
inline constexpr struct boltzmann_constant :
named_unit<"k", mag<ratio{1'380'649, 1'000'000}> * mag_power<10, -23> * joule / kelvin> {} boltzmann_constant;
inline constexpr struct avogadro_constant :
named_unit<"N_A", mag<ratio{602'214'076, 100'000'000}> * mag_power<10, 23> * (1 / mole)> {} avogadro_constant;
named_unit<"N_A", mag<ratio{602'214'076, 100'000'000}> * mag_power<10, 23> / mole> {} avogadro_constant;
inline constexpr struct luminous_efficacy :
named_unit<"K_cd", mag<683> * lumen / watt> {} luminous_efficacy;
// clang-format on