mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-06 05:34:27 +02:00
Use mag_power
to make callsites more concise
This commit is contained in:
@@ -652,6 +652,16 @@ constexpr Magnitude auto as_magnitude()
|
|||||||
return detail::prime_factorization_v<R.num> / detail::prime_factorization_v<R.den>;
|
return detail::prime_factorization_v<R.num> / detail::prime_factorization_v<R.den>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a Magnitude which is some rational number raised to a rational power.
|
||||||
|
*/
|
||||||
|
template<ratio Base, ratio Pow>
|
||||||
|
requires(Base.num > 0)
|
||||||
|
constexpr Magnitude auto mag_power()
|
||||||
|
{
|
||||||
|
return pow<Pow>(as_magnitude<Base>());
|
||||||
|
}
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<typename T, BasePower auto... BPs>
|
template<typename T, BasePower auto... BPs>
|
||||||
constexpr ratio get_power(T base, magnitude<BPs...>)
|
constexpr ratio get_power(T base, magnitude<BPs...>)
|
||||||
|
@@ -37,7 +37,7 @@ namespace units::isq::si::hep {
|
|||||||
// effective cross-sectional area according to EU council directive 80/181/EEC
|
// effective cross-sectional area according to EU council directive 80/181/EEC
|
||||||
// https://eur-lex.europa.eu/legal-content/EN/TXT/PDF/?uri=CELEX:01980L0181-20090527#page=10
|
// https://eur-lex.europa.eu/legal-content/EN/TXT/PDF/?uri=CELEX:01980L0181-20090527#page=10
|
||||||
// https://www.fedlex.admin.ch/eli/cc/1994/3109_3109_3109/de
|
// https://www.fedlex.admin.ch/eli/cc/1994/3109_3109_3109/de
|
||||||
struct barn : named_scaled_unit<barn, "b", pow<-28>(as_magnitude<10>()), square_metre> {};
|
struct barn : named_scaled_unit<barn, "b", mag_power<10, -28>(), square_metre> {};
|
||||||
struct yocto_barn : prefixed_unit<yocto_barn, yocto, barn> {};
|
struct yocto_barn : prefixed_unit<yocto_barn, yocto, barn> {};
|
||||||
struct zepto_barn : prefixed_unit<zepto_barn, zepto, barn> {};
|
struct zepto_barn : prefixed_unit<zepto_barn, zepto, barn> {};
|
||||||
struct atto_barn : prefixed_unit<atto_barn, atto, barn> {};
|
struct atto_barn : prefixed_unit<atto_barn, atto, barn> {};
|
||||||
|
@@ -44,8 +44,7 @@ namespace units::isq::si::hep {
|
|||||||
|
|
||||||
struct eV_per_c2 :
|
struct eV_per_c2 :
|
||||||
named_scaled_unit<eV_per_c2, basic_symbol_text{"eV/c²", "eV/c^2"},
|
named_scaled_unit<eV_per_c2, basic_symbol_text{"eV/c²", "eV/c^2"},
|
||||||
as_magnitude<ratio(17'826'619'216'279, 1'000'000'000'000)>() * pow<-35>(as_magnitude<10>()),
|
as_magnitude<ratio(17'826'619'216'279, 1'000'000'000'000)>() * mag_power<10, -35>(), kilogram> {};
|
||||||
kilogram> {};
|
|
||||||
struct feV_per_c2 : prefixed_unit<feV_per_c2, femto, eV_per_c2> {};
|
struct feV_per_c2 : prefixed_unit<feV_per_c2, femto, eV_per_c2> {};
|
||||||
struct peV_per_c2 : prefixed_unit<peV_per_c2, pico, eV_per_c2> {};
|
struct peV_per_c2 : prefixed_unit<peV_per_c2, pico, eV_per_c2> {};
|
||||||
struct neV_per_c2 : prefixed_unit<neV_per_c2, nano, eV_per_c2> {};
|
struct neV_per_c2 : prefixed_unit<neV_per_c2, nano, eV_per_c2> {};
|
||||||
@@ -62,16 +61,13 @@ struct EeV_per_c2 : prefixed_unit<EeV_per_c2, exa, eV_per_c2> {};
|
|||||||
struct YeV_per_c2 : prefixed_unit<YeV_per_c2, yotta, eV_per_c2> {};
|
struct YeV_per_c2 : prefixed_unit<YeV_per_c2, yotta, eV_per_c2> {};
|
||||||
struct electron_mass :
|
struct electron_mass :
|
||||||
named_scaled_unit<eV_per_c2, "m_e",
|
named_scaled_unit<eV_per_c2, "m_e",
|
||||||
as_magnitude<ratio(9'109'383'701'528, 1'000'000'000'000)>() * pow<-31>(as_magnitude<10>()),
|
as_magnitude<ratio(9'109'383'701'528, 1'000'000'000'000)>() * mag_power<10, -31>(), kilogram> {};
|
||||||
kilogram> {};
|
|
||||||
struct proton_mass :
|
struct proton_mass :
|
||||||
named_scaled_unit<eV_per_c2, "m_p",
|
named_scaled_unit<eV_per_c2, "m_p",
|
||||||
as_magnitude<ratio(1'672'621'923'695, 1'000'000'000'000)>() * pow<-27>(as_magnitude<10>()),
|
as_magnitude<ratio(1'672'621'923'695, 1'000'000'000'000)>() * mag_power<10, -27>(), kilogram> {};
|
||||||
kilogram> {};
|
|
||||||
struct neutron_mass :
|
struct neutron_mass :
|
||||||
named_scaled_unit<eV_per_c2, "m_n",
|
named_scaled_unit<eV_per_c2, "m_n",
|
||||||
as_magnitude<ratio(1'674'927'498'049, 1'000'000'000'000)>() * pow<-27>(as_magnitude<10>()),
|
as_magnitude<ratio(1'674'927'498'049, 1'000'000'000'000)>() * mag_power<10, -27>(), kilogram> {};
|
||||||
kilogram> {};
|
|
||||||
|
|
||||||
struct dim_mass : isq::dim_mass<eV_per_c2> {};
|
struct dim_mass : isq::dim_mass<eV_per_c2> {};
|
||||||
|
|
||||||
|
@@ -42,7 +42,7 @@ struct kilogram_metre_per_second : derived_unit<kilogram_metre_per_second> {};
|
|||||||
|
|
||||||
struct eV_per_c :
|
struct eV_per_c :
|
||||||
named_scaled_unit<eV_per_c, "eV/c",
|
named_scaled_unit<eV_per_c, "eV/c",
|
||||||
as_magnitude<ratio(5'344'285'992'678, 1'000'000'000'000)>() * pow<-35>(as_magnitude<10>()),
|
as_magnitude<ratio(5'344'285'992'678, 1'000'000'000'000)>() * mag_power<10, -35>(),
|
||||||
kilogram_metre_per_second> {};
|
kilogram_metre_per_second> {};
|
||||||
struct feV_per_c : prefixed_unit<feV_per_c, femto, eV_per_c> {};
|
struct feV_per_c : prefixed_unit<feV_per_c, femto, eV_per_c> {};
|
||||||
struct peV_per_c : prefixed_unit<peV_per_c, pico, eV_per_c> {};
|
struct peV_per_c : prefixed_unit<peV_per_c, pico, eV_per_c> {};
|
||||||
|
@@ -42,7 +42,7 @@ struct light_year : named_scaled_unit<light_year, "ly", as_magnitude<94607304725
|
|||||||
struct parsec : named_scaled_unit<parsec, "pc", as_magnitude<30'856'775'814'913'673>(), si::metre> {};
|
struct parsec : named_scaled_unit<parsec, "pc", as_magnitude<30'856'775'814'913'673>(), si::metre> {};
|
||||||
|
|
||||||
// https://en.wikipedia.org/wiki/Angstrom
|
// https://en.wikipedia.org/wiki/Angstrom
|
||||||
struct angstrom : named_scaled_unit<angstrom, "angstrom", pow<-10>(as_magnitude<10>()), si::metre> {};
|
struct angstrom : named_scaled_unit<angstrom, "angstrom", mag_power<10, -10>(), si::metre> {};
|
||||||
|
|
||||||
#ifndef UNITS_NO_LITERALS
|
#ifndef UNITS_NO_LITERALS
|
||||||
|
|
||||||
|
@@ -38,15 +38,15 @@ namespace units::isq::si::typographic {
|
|||||||
// TODO Conflicts with (https://en.wikipedia.org/wiki/Pica_(typography)), verify correctness of below conversion factors
|
// TODO Conflicts with (https://en.wikipedia.org/wiki/Pica_(typography)), verify correctness of below conversion factors
|
||||||
// and provide hyperlinks to definitions
|
// and provide hyperlinks to definitions
|
||||||
struct pica_comp :
|
struct pica_comp :
|
||||||
named_scaled_unit<pica_comp, "pica(comp)", as_magnitude<4'233'333>() * pow<-9>(as_magnitude<10>()), si::metre> {};
|
named_scaled_unit<pica_comp, "pica(comp)", as_magnitude<4'233'333>() * mag_power<10, -9>(), si::metre> {};
|
||||||
struct pica_prn :
|
struct pica_prn :
|
||||||
named_scaled_unit<pica_prn, "pica(prn)", as_magnitude<ratio(2108759, 500000)>() * pow<-3>(as_magnitude<10>()),
|
named_scaled_unit<pica_prn, "pica(prn)", as_magnitude<ratio(2108759, 500000)>() * mag_power<10, -3>(), si::metre> {
|
||||||
si::metre> {};
|
};
|
||||||
struct point_comp :
|
struct point_comp :
|
||||||
named_scaled_unit<point_comp, "point(comp)", as_magnitude<ratio(1763889, 500000)>() * pow<-4>(as_magnitude<10>()),
|
named_scaled_unit<point_comp, "point(comp)", as_magnitude<ratio(1763889, 500000)>() * mag_power<10, -4>(),
|
||||||
si::metre> {};
|
si::metre> {};
|
||||||
struct point_prn :
|
struct point_prn :
|
||||||
named_scaled_unit<point_prn, "point(prn)", as_magnitude<ratio(1757299, 500000)>() * pow<-4>(as_magnitude<10>()),
|
named_scaled_unit<point_prn, "point(prn)", as_magnitude<ratio(1757299, 500000)>() * mag_power<10, -4>(),
|
||||||
si::metre> {};
|
si::metre> {};
|
||||||
|
|
||||||
#ifndef UNITS_NO_LITERALS
|
#ifndef UNITS_NO_LITERALS
|
||||||
|
@@ -58,8 +58,7 @@ struct exakatal : prefixed_unit<exakatal, exa, katal> {};
|
|||||||
struct zettakatal : prefixed_unit<zettakatal, zetta, katal> {};
|
struct zettakatal : prefixed_unit<zettakatal, zetta, katal> {};
|
||||||
struct yottakatal : prefixed_unit<yottakatal, yotta, katal> {};
|
struct yottakatal : prefixed_unit<yottakatal, yotta, katal> {};
|
||||||
|
|
||||||
struct enzyme_unit :
|
struct enzyme_unit : named_scaled_unit<enzyme_unit, "U", as_magnitude<ratio(1, 60)>() * mag_power<10, -6>(), katal> {};
|
||||||
named_scaled_unit<enzyme_unit, "U", as_magnitude<ratio(1, 60)>() * pow<-6>(as_magnitude<10>()), katal> {};
|
|
||||||
|
|
||||||
struct dim_catalytic_activity :
|
struct dim_catalytic_activity :
|
||||||
isq::dim_catalytic_activity<dim_catalytic_activity, katal, dim_time, dim_amount_of_substance> {};
|
isq::dim_catalytic_activity<dim_catalytic_activity, katal, dim_time, dim_amount_of_substance> {};
|
||||||
|
@@ -56,8 +56,8 @@ struct yottajoule : prefixed_unit<yottajoule, yotta, joule> {};
|
|||||||
// N.B. electron charge (and eV) is an exact constant:
|
// N.B. electron charge (and eV) is an exact constant:
|
||||||
// https://www.bipm.org/documents/20126/41483022/SI-Brochure-9.pdf#page=147
|
// https://www.bipm.org/documents/20126/41483022/SI-Brochure-9.pdf#page=147
|
||||||
struct electronvolt :
|
struct electronvolt :
|
||||||
named_scaled_unit<electronvolt, "eV",
|
named_scaled_unit<electronvolt, "eV", as_magnitude<ratio(1'602'176'634, 1'000'000'000)>() * mag_power<10, -19>(),
|
||||||
as_magnitude<ratio(1'602'176'634, 1'000'000'000)>() * pow<-19>(as_magnitude<10>()), joule> {};
|
joule> {};
|
||||||
struct gigaelectronvolt : prefixed_unit<gigaelectronvolt, giga, electronvolt> {};
|
struct gigaelectronvolt : prefixed_unit<gigaelectronvolt, giga, electronvolt> {};
|
||||||
|
|
||||||
struct dim_energy : isq::dim_energy<dim_energy, joule, dim_force, dim_length> {};
|
struct dim_energy : isq::dim_energy<dim_energy, joule, dim_force, dim_length> {};
|
||||||
|
@@ -80,8 +80,8 @@ struct yottatonne : prefixed_unit<yottatonne, yotta, tonne> {};
|
|||||||
|
|
||||||
struct dalton :
|
struct dalton :
|
||||||
named_scaled_unit<dalton, "Da",
|
named_scaled_unit<dalton, "Da",
|
||||||
as_magnitude<ratio(16'605'390'666'050, 10'000'000'000'000)>() * pow<-27>(as_magnitude<10>()),
|
as_magnitude<ratio(16'605'390'666'050, 10'000'000'000'000)>() * mag_power<10, -27>(), kilogram> {
|
||||||
kilogram> {};
|
};
|
||||||
|
|
||||||
struct dim_mass : isq::dim_mass<kilogram> {};
|
struct dim_mass : isq::dim_mass<kilogram> {};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user