diff --git a/src/core/include/units/magnitude.h b/src/core/include/units/magnitude.h index 3e1e7a19..d3ab7181 100644 --- a/src/core/include/units/magnitude.h +++ b/src/core/include/units/magnitude.h @@ -652,6 +652,16 @@ constexpr Magnitude auto as_magnitude() return detail::prime_factorization_v / detail::prime_factorization_v; } +/** + * @brief Create a Magnitude which is some rational number raised to a rational power. + */ +template + requires(Base.num > 0) +constexpr Magnitude auto mag_power() +{ + return pow(as_magnitude()); +} + namespace detail { template constexpr ratio get_power(T base, magnitude) diff --git a/src/systems/si-hep/include/units/isq/si/hep/area.h b/src/systems/si-hep/include/units/isq/si/hep/area.h index 658a12a8..65130f8a 100644 --- a/src/systems/si-hep/include/units/isq/si/hep/area.h +++ b/src/systems/si-hep/include/units/isq/si/hep/area.h @@ -37,7 +37,7 @@ namespace units::isq::si::hep { // 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://www.fedlex.admin.ch/eli/cc/1994/3109_3109_3109/de -struct barn : named_scaled_unit(as_magnitude<10>()), square_metre> {}; +struct barn : named_scaled_unit(), square_metre> {}; struct yocto_barn : prefixed_unit {}; struct zepto_barn : prefixed_unit {}; struct atto_barn : prefixed_unit {}; diff --git a/src/systems/si-hep/include/units/isq/si/hep/mass.h b/src/systems/si-hep/include/units/isq/si/hep/mass.h index 754c2a61..c3b3bd99 100644 --- a/src/systems/si-hep/include/units/isq/si/hep/mass.h +++ b/src/systems/si-hep/include/units/isq/si/hep/mass.h @@ -44,8 +44,7 @@ namespace units::isq::si::hep { struct eV_per_c2 : named_scaled_unit() * pow<-35>(as_magnitude<10>()), - kilogram> {}; + as_magnitude() * mag_power<10, -35>(), kilogram> {}; struct feV_per_c2 : prefixed_unit {}; struct peV_per_c2 : prefixed_unit {}; struct neV_per_c2 : prefixed_unit {}; @@ -62,16 +61,13 @@ struct EeV_per_c2 : prefixed_unit {}; struct YeV_per_c2 : prefixed_unit {}; struct electron_mass : named_scaled_unit() * pow<-31>(as_magnitude<10>()), - kilogram> {}; + as_magnitude() * mag_power<10, -31>(), kilogram> {}; struct proton_mass : named_scaled_unit() * pow<-27>(as_magnitude<10>()), - kilogram> {}; + as_magnitude() * mag_power<10, -27>(), kilogram> {}; struct neutron_mass : named_scaled_unit() * pow<-27>(as_magnitude<10>()), - kilogram> {}; + as_magnitude() * mag_power<10, -27>(), kilogram> {}; struct dim_mass : isq::dim_mass {}; diff --git a/src/systems/si-hep/include/units/isq/si/hep/momentum.h b/src/systems/si-hep/include/units/isq/si/hep/momentum.h index ab87fb4a..dbc66c57 100644 --- a/src/systems/si-hep/include/units/isq/si/hep/momentum.h +++ b/src/systems/si-hep/include/units/isq/si/hep/momentum.h @@ -42,7 +42,7 @@ struct kilogram_metre_per_second : derived_unit {}; struct eV_per_c : named_scaled_unit() * pow<-35>(as_magnitude<10>()), + as_magnitude() * mag_power<10, -35>(), kilogram_metre_per_second> {}; struct feV_per_c : prefixed_unit {}; struct peV_per_c : prefixed_unit {}; diff --git a/src/systems/si-iau/include/units/isq/si/iau/length.h b/src/systems/si-iau/include/units/isq/si/iau/length.h index e4066edb..bf0226c3 100644 --- a/src/systems/si-iau/include/units/isq/si/iau/length.h +++ b/src/systems/si-iau/include/units/isq/si/iau/length.h @@ -42,7 +42,7 @@ struct light_year : named_scaled_unit(), si::metre> {}; // https://en.wikipedia.org/wiki/Angstrom -struct angstrom : named_scaled_unit(as_magnitude<10>()), si::metre> {}; +struct angstrom : named_scaled_unit(), si::metre> {}; #ifndef UNITS_NO_LITERALS diff --git a/src/systems/si-typographic/include/units/isq/si/typographic/length.h b/src/systems/si-typographic/include/units/isq/si/typographic/length.h index ecd56afd..899bd4e6 100644 --- a/src/systems/si-typographic/include/units/isq/si/typographic/length.h +++ b/src/systems/si-typographic/include/units/isq/si/typographic/length.h @@ -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 // and provide hyperlinks to definitions struct pica_comp : - named_scaled_unit() * pow<-9>(as_magnitude<10>()), si::metre> {}; + named_scaled_unit() * mag_power<10, -9>(), si::metre> {}; struct pica_prn : - named_scaled_unit() * pow<-3>(as_magnitude<10>()), - si::metre> {}; + named_scaled_unit() * mag_power<10, -3>(), si::metre> { +}; struct point_comp : - named_scaled_unit() * pow<-4>(as_magnitude<10>()), + named_scaled_unit() * mag_power<10, -4>(), si::metre> {}; struct point_prn : - named_scaled_unit() * pow<-4>(as_magnitude<10>()), + named_scaled_unit() * mag_power<10, -4>(), si::metre> {}; #ifndef UNITS_NO_LITERALS diff --git a/src/systems/si/include/units/isq/si/catalytic_activity.h b/src/systems/si/include/units/isq/si/catalytic_activity.h index 562eb0fa..397de5c4 100644 --- a/src/systems/si/include/units/isq/si/catalytic_activity.h +++ b/src/systems/si/include/units/isq/si/catalytic_activity.h @@ -58,8 +58,7 @@ struct exakatal : prefixed_unit {}; struct zettakatal : prefixed_unit {}; struct yottakatal : prefixed_unit {}; -struct enzyme_unit : - named_scaled_unit() * pow<-6>(as_magnitude<10>()), katal> {}; +struct enzyme_unit : named_scaled_unit() * mag_power<10, -6>(), katal> {}; struct dim_catalytic_activity : isq::dim_catalytic_activity {}; diff --git a/src/systems/si/include/units/isq/si/energy.h b/src/systems/si/include/units/isq/si/energy.h index c9eca1cb..d5edf645 100644 --- a/src/systems/si/include/units/isq/si/energy.h +++ b/src/systems/si/include/units/isq/si/energy.h @@ -56,8 +56,8 @@ struct yottajoule : prefixed_unit {}; // N.B. electron charge (and eV) is an exact constant: // https://www.bipm.org/documents/20126/41483022/SI-Brochure-9.pdf#page=147 struct electronvolt : - named_scaled_unit() * pow<-19>(as_magnitude<10>()), joule> {}; + named_scaled_unit() * mag_power<10, -19>(), + joule> {}; struct gigaelectronvolt : prefixed_unit {}; struct dim_energy : isq::dim_energy {}; diff --git a/src/systems/si/include/units/isq/si/mass.h b/src/systems/si/include/units/isq/si/mass.h index e4d935d1..e57d2c0b 100644 --- a/src/systems/si/include/units/isq/si/mass.h +++ b/src/systems/si/include/units/isq/si/mass.h @@ -80,8 +80,8 @@ struct yottatonne : prefixed_unit {}; struct dalton : named_scaled_unit() * pow<-27>(as_magnitude<10>()), - kilogram> {}; + as_magnitude() * mag_power<10, -27>(), kilogram> { +}; struct dim_mass : isq::dim_mass {};