Migrate units from ratio to Magnitude

This commit is huge, but hopefully the cognitive load is not too bad.
The bulk of this commit is just some fairly mechanical updates from
`ratio` to `Magnitude`.  Other things to call out:

- `UnitRatio` goes away.  We don't need this concept, because Magnitude
  can't even _represent_ anything that doesn't satisfy it.

- I commented out some formatting test cases where the precise
  expression changes, but the number is completely equivalent.  We will
  need to decide how we want to handle Magnitude formatting as a
  separate, follow-on task.  But at least Magnitude gives us all the
  tools we'll need to do so!
This commit is contained in:
Chip Hogg committed 2022-04-11 15:16:16 +00:00
1 parent 5afe7766e9
commit d19b2803ce
42 files changed
+197 -199

No files matched your search

@@ -53,7 +53,7 @@ struct tebibit : prefixed_unit<tebibit, tebi, binary_prefix_bit> {};
struct pebibit : prefixed_unit<pebibit, pebi, binary_prefix_bit> {};
struct exbibit : prefixed_unit<exbibit, exbi, binary_prefix_bit> {};
struct byte : named_scaled_unit<byte, "B", si::prefix, ratio(8), bit> {};
struct byte : named_scaled_unit<byte, "B", si::prefix, as_magnitude<8>(), bit> {};
struct kilobyte : prefixed_unit<kilobyte, si::kilo, byte> {};
struct megabyte : prefixed_unit<megabyte, si::mega, byte> {};
struct gigabyte : prefixed_unit<gigabyte, si::giga, byte> {};
@@ -40,7 +40,8 @@ namespace units::isq::si::fps {
struct poundal : named_unit<poundal, "pdl", no_prefix> {};
// https://en.wikipedia.org/wiki/Pound_(force)
struct pound_force : named_scaled_unit<pound_force, "lbf", si::prefix, ratio(32'174'049, 1'000'000), poundal> {};
struct pound_force :
named_scaled_unit<pound_force, "lbf", si::prefix, as_magnitude<ratio(32'174'049, 1'000'000)>(), poundal> {};
struct kilopound_force : prefixed_unit<kilopound_force, si::kilo, pound_force> {};
@@ -35,24 +35,24 @@
namespace units::isq::si::fps {
// https://en.wikipedia.org/wiki/Foot_(unit)
struct foot : named_scaled_unit<foot, "ft", no_prefix, ratio(3'048, 1'000, -1), si::metre> {};
struct foot : named_scaled_unit<foot, "ft", no_prefix, as_magnitude<ratio(3'048, 1'000, -1)>(), si::metre> {};
struct inch : named_scaled_unit<inch, "in", no_prefix, ratio(1, 12), foot> {};
struct inch : named_scaled_unit<inch, "in", no_prefix, as_magnitude<ratio(1, 12)>(), foot> {};
// thousandth of an inch
struct thousandth : named_scaled_unit<thousandth, "thou", no_prefix, ratio(1, 1'000), inch> {};
struct thousandth : named_scaled_unit<thousandth, "thou", no_prefix, as_magnitude<ratio(1, 1'000)>(), inch> {};
struct thou : alias_unit<thousandth, "thou", no_prefix> {};
struct mil : alias_unit<thousandth, "mil", no_prefix> {};
struct yard : named_scaled_unit<yard, "yd", si::prefix, ratio(3, 1), foot> {};
struct yard : named_scaled_unit<yard, "yd", si::prefix, as_magnitude<3>(), foot> {};
struct fathom : named_scaled_unit<fathom, "ftm", no_prefix, ratio(6, 1), foot> {};
struct fathom : named_scaled_unit<fathom, "ftm", no_prefix, as_magnitude<6>(), foot> {};
struct kiloyard : prefixed_unit<kiloyard, si::kilo, yard> {};
struct mile : named_scaled_unit<mile, "mile", no_prefix, ratio(5'280), foot> {};
struct mile : named_scaled_unit<mile, "mile", no_prefix, as_magnitude<5'280>(), foot> {};
struct nautical_mile : named_scaled_unit<nautical_mile, "mi(naut)", no_prefix, ratio(2'000), yard> {};
struct nautical_mile : named_scaled_unit<nautical_mile, "mi(naut)", no_prefix, as_magnitude<2'000>(), yard> {};
struct dim_length : isq::dim_length<foot> {};
@@ -35,28 +35,29 @@
namespace units::isq::si::fps {
// https://en.wikipedia.org/wiki/Pound_(mass)
struct pound : named_scaled_unit<pound, "lb", no_prefix, ratio(45'359'237, 100'000'000), si::kilogram> {};
struct pound :
named_scaled_unit<pound, "lb", no_prefix, as_magnitude<ratio(45'359'237, 100'000'000)>(), si::kilogram> {};
struct dim_mass : isq::dim_mass<pound> {};
template<UnitOf<dim_mass> U, Representation Rep = double>
using mass = quantity<dim_mass, U, Rep>;
struct grain : named_scaled_unit<grain, "gr", no_prefix, ratio(1, 7000), pound> {};
struct grain : named_scaled_unit<grain, "gr", no_prefix, as_magnitude<ratio(1, 7000)>(), pound> {};
struct dram : named_scaled_unit<dram, "dr", no_prefix, ratio(1, 256), pound> {};
struct dram : named_scaled_unit<dram, "dr", no_prefix, as_magnitude<ratio(1, 256)>(), pound> {};
struct ounce : named_scaled_unit<ounce, "oz", no_prefix, ratio(1, 16), pound> {};
struct ounce : named_scaled_unit<ounce, "oz", no_prefix, as_magnitude<ratio(1, 16)>(), pound> {};
struct stone : named_scaled_unit<stone, "st", no_prefix, ratio(14, 1), pound> {};
struct stone : named_scaled_unit<stone, "st", no_prefix, as_magnitude<14>(), pound> {};
struct quarter : named_scaled_unit<quarter, "qr", no_prefix, ratio(28, 1), pound> {};
struct quarter : named_scaled_unit<quarter, "qr", no_prefix, as_magnitude<28>(), pound> {};
struct hundredweight : named_scaled_unit<hundredweight, "cwt", no_prefix, ratio(112, 1), pound> {};
struct hundredweight : named_scaled_unit<hundredweight, "cwt", no_prefix, as_magnitude<112>(), pound> {};
struct short_ton : named_scaled_unit<short_ton, "ton (short)", no_prefix, ratio(2'000, 1), pound> {};
struct short_ton : named_scaled_unit<short_ton, "ton (short)", no_prefix, as_magnitude<2'000>(), pound> {};
struct long_ton : named_scaled_unit<long_ton, "ton (long)", no_prefix, ratio(2'240, 1), pound> {};
struct long_ton : named_scaled_unit<long_ton, "ton (long)", no_prefix, as_magnitude<2'240>(), pound> {};
#ifndef UNITS_NO_LITERALS
@@ -41,7 +41,8 @@ struct dim_power : isq::dim_power<dim_power, foot_poundal_per_second, dim_length
struct foot_pound_force_per_second : derived_unit<foot_pound_force_per_second, dim_power, foot, pound_force, second> {};
struct horse_power : named_scaled_unit<horse_power, "hp", no_prefix, ratio(550), foot_pound_force_per_second> {};
struct horse_power :
named_scaled_unit<horse_power, "hp", no_prefix, as_magnitude<550>(), foot_pound_force_per_second> {};
template<UnitOf<dim_power> U, Representation Rep = double>
using power = quantity<dim_power, U, Rep>;
@@ -44,11 +44,12 @@ template<UnitOf<dim_pressure> U, Representation Rep = double>
using pressure = quantity<dim_pressure, U, Rep>;
struct pound_force_per_foot_sq :
named_scaled_unit<pound_force_per_foot_sq, "lbf ft2", si::prefix, ratio(32'174'049, 1'000'000),
named_scaled_unit<pound_force_per_foot_sq, "lbf ft2", si::prefix, as_magnitude<ratio(32'174'049, 1'000'000)>(),
poundal_per_foot_sq> {};
struct pound_force_per_inch_sq :
named_scaled_unit<pound_force_per_inch_sq, "psi", si::prefix, ratio(1, 144), pound_force_per_foot_sq> {};
named_scaled_unit<pound_force_per_inch_sq, "psi", si::prefix, as_magnitude<ratio(1, 144)>(),
pound_force_per_foot_sq> {};
struct kilopound_force_per_inch_sq : prefixed_unit<kilopound_force_per_inch_sq, si::kilo, pound_force_per_inch_sq> {};
@@ -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<barn, "b", prefix, ratio(1, 1, -28), square_metre> {};
struct barn : named_scaled_unit<barn, "b", prefix, as_magnitude<ratio(1, 1, -28)>(), square_metre> {};
struct yocto_barn : prefixed_unit<yocto_barn, yocto, barn> {};
struct zepto_barn : prefixed_unit<zepto_barn, zepto, barn> {};
struct atto_barn : prefixed_unit<atto_barn, atto, barn> {};
@@ -32,11 +32,15 @@
#include <units/isq/si/mass.h>
#include <units/unit.h>
// Necessary to factor `1'672'621'923'695`, which appears in the proton mass.
template<>
inline constexpr std::optional<std::intmax_t> units::known_first_factor<334'524'384'739> = 334'524'384'739;
namespace units::isq::si::hep {
struct eV_per_c2 :
named_scaled_unit<eV_per_c2, basic_symbol_text{"eV/c²", "eV/c^2"}, prefix,
ratio(1'7826'619'216'279, 1'000'000'000'000, -35), kilogram> {};
as_magnitude<ratio(1'7826'619'216'279, 1'000'000'000'000, -35)>(), kilogram> {};
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 neV_per_c2 : prefixed_unit<neV_per_c2, nano, eV_per_c2> {};
@@ -52,11 +56,14 @@ struct PeV_per_c2 : prefixed_unit<PeV_per_c2, peta, eV_per_c2> {};
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 electron_mass :
named_scaled_unit<eV_per_c2, "m_e", prefix, ratio(9'109'383'701'528, 1'000'000'000'000, -31), kilogram> {};
named_scaled_unit<eV_per_c2, "m_e", prefix, as_magnitude<ratio(9'109'383'701'528, 1'000'000'000'000, -31)>(),
kilogram> {};
struct proton_mass :
named_scaled_unit<eV_per_c2, "m_p", prefix, ratio(1'672'621'923'695, 1'000'000'000'000, -27), kilogram> {};
named_scaled_unit<eV_per_c2, "m_p", prefix, as_magnitude<ratio(1'672'621'923'695, 1'000'000'000'000, -27)>(),
kilogram> {};
struct neutron_mass :
named_scaled_unit<eV_per_c2, "m_n", prefix, ratio(1'674'927'498'049, 1'000'000'000'000, -27), kilogram> {};
named_scaled_unit<eV_per_c2, "m_n", prefix, as_magnitude<ratio(1'674'927'498'049, 1'000'000'000'000, -27)>(),
kilogram> {};
struct dim_mass : isq::dim_mass<eV_per_c2> {};
@@ -36,7 +36,7 @@
namespace units::isq::si::hep {
struct eV_per_c :
named_scaled_unit<eV_per_c, "eV/c", prefix, ratio(5'344'285'992'678, 1'000'000'000'000, -35),
named_scaled_unit<eV_per_c, "eV/c", prefix, as_magnitude<ratio(5'344'285'992'678, 1'000'000'000'000, -35)>(),
::units::isq::si::kilogram_metre_per_second> {};
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> {};
@@ -36,13 +36,13 @@
namespace units::isq::si::iau {
// https://en.wikipedia.org/wiki/Light-year
struct light_year : named_scaled_unit<light_year, "ly", no_prefix, ratio(9460730472580800), si::metre> {};
struct light_year : named_scaled_unit<light_year, "ly", no_prefix, as_magnitude<9460730472580800>(), si::metre> {};
// https://en.wikipedia.org/wiki/Parsec
struct parsec : named_scaled_unit<parsec, "pc", si::prefix, ratio(30'856'775'814'913'673), si::metre> {};
struct parsec : named_scaled_unit<parsec, "pc", si::prefix, as_magnitude<30'856'775'814'913'673>(), si::metre> {};
// https://en.wikipedia.org/wiki/Angstrom
struct angstrom : named_scaled_unit<angstrom, "angstrom", no_prefix, ratio(1, 1, -10), si::metre> {};
struct angstrom : named_scaled_unit<angstrom, "angstrom", no_prefix, as_magnitude<ratio(1, 1, -10)>(), si::metre> {};
#ifndef UNITS_NO_LITERALS
@@ -35,10 +35,10 @@
namespace units::isq::si::imperial {
// https://en.wikipedia.org/wiki/Chain_(unit)
struct chain : named_scaled_unit<chain, "ch", no_prefix, ratio(22, 1), si::international::yard> {};
struct chain : named_scaled_unit<chain, "ch", no_prefix, as_magnitude<22>(), si::international::yard> {};
// https://en.wikipedia.org/wiki/Rod_(unit)
struct rod : named_scaled_unit<rod, "rd", no_prefix, ratio(1, 4), chain> {};
struct rod : named_scaled_unit<rod, "rd", no_prefix, as_magnitude<ratio(1, 4)>(), chain> {};
#ifndef UNITS_NO_LITERALS
@@ -37,30 +37,30 @@ namespace units::isq::si::international {
// si::international yard
// https://en.wikipedia.org/wiki/International_yard_and_pound
struct yard : named_scaled_unit<yard, "yd", no_prefix, ratio(9'144, 1'000, -1), si::metre> {};
struct yard : named_scaled_unit<yard, "yd", no_prefix, as_magnitude<ratio(9'144, 1'000, -1)>(), si::metre> {};
// si::international foot
// https://en.wikipedia.org/wiki/Foot_(unit)#International_foot
struct foot : named_scaled_unit<foot, "ft", no_prefix, ratio(1, 3), yard> {};
struct foot : named_scaled_unit<foot, "ft", no_prefix, as_magnitude<ratio(1, 3)>(), yard> {};
// https://en.wikipedia.org/wiki/Fathom#International_fathom
struct fathom : named_scaled_unit<fathom, "fathom", no_prefix, ratio(2), yard> {};
struct fathom : named_scaled_unit<fathom, "fathom", no_prefix, as_magnitude<2>(), yard> {};
// si::international inch
// https://en.wikipedia.org/wiki/Inch#Equivalences
struct inch : named_scaled_unit<inch, "in", no_prefix, ratio(1, 36), yard> {};
struct inch : named_scaled_unit<inch, "in", no_prefix, as_magnitude<ratio(1, 36)>(), yard> {};
// intrnational mile
// https://en.wikipedia.org/wiki/Mile#International_mile
struct mile : named_scaled_unit<mile, "mi", no_prefix, ratio(25'146, 15'625), si::kilometre> {};
struct mile : named_scaled_unit<mile, "mi", no_prefix, as_magnitude<ratio(25'146, 15'625)>(), si::kilometre> {};
// si::international nautical mile
// https://en.wikipedia.org/wiki/Nautical_mile
struct nautical_mile : named_scaled_unit<nautical_mile, "mi(naut)", no_prefix, ratio(1852), si::metre> {};
struct nautical_mile : named_scaled_unit<nautical_mile, "mi(naut)", no_prefix, as_magnitude<1852>(), si::metre> {};
// thou
// https://en.wikipedia.org/wiki/Thousandth_of_an_inch
struct thou : named_scaled_unit<thou, "thou", no_prefix, ratio(1, 1000), inch> {};
struct thou : named_scaled_unit<thou, "thou", no_prefix, as_magnitude<ratio(1, 1000)>(), inch> {};
// mil - different name for thou
// https://en.wikipedia.org/wiki/Thousandth_of_an_inch
@@ -37,10 +37,14 @@ 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<pica_comp, "pica(comp)", no_prefix, ratio(4233333, 1000000, -3), si::metre> {};
struct pica_prn : named_scaled_unit<pica_prn, "pica(prn)", no_prefix, ratio(2108759, 500000, -3), si::metre> {};
struct point_comp : named_scaled_unit<point_comp, "point(comp)", no_prefix, ratio(1763889, 500000, -4), si::metre> {};
struct point_prn : named_scaled_unit<point_prn, "point(prn)", no_prefix, ratio(1757299, 500000, -4), si::metre> {};
struct pica_comp :
named_scaled_unit<pica_comp, "pica(comp)", no_prefix, as_magnitude<ratio(4233333, 1000000, -3)>(), si::metre> {};
struct pica_prn :
named_scaled_unit<pica_prn, "pica(prn)", no_prefix, as_magnitude<ratio(2108759, 500000, -3)>(), si::metre> {};
struct point_comp :
named_scaled_unit<point_comp, "point(comp)", no_prefix, as_magnitude<ratio(1763889, 500000, -4)>(), si::metre> {};
struct point_prn :
named_scaled_unit<point_prn, "point(prn)", no_prefix, as_magnitude<ratio(1757299, 500000, -4)>(), si::metre> {};
#ifndef UNITS_NO_LITERALS
@@ -36,14 +36,14 @@ namespace units::isq::si::uscs {
// https://en.wikipedia.org/wiki/Foot_(unit)#US_survey_foot
// https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors#B6
struct foot : named_scaled_unit<foot, "ft(us)", no_prefix, ratio(1'200, 3'937), si::metre> {};
struct foot : named_scaled_unit<foot, "ft(us)", no_prefix, as_magnitude<ratio(1'200, 3'937)>(), si::metre> {};
// https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors#B6
struct fathom : named_scaled_unit<fathom, "fathom(us)", no_prefix, ratio(6), foot> {};
struct fathom : named_scaled_unit<fathom, "fathom(us)", no_prefix, as_magnitude<6>(), foot> {};
// https://en.wikipedia.org/wiki/Mile#U.S._survey_mile
// https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors#B6
struct mile : named_scaled_unit<mile, "mi(us)", no_prefix, ratio(5280), foot> {};
struct mile : named_scaled_unit<mile, "mi(us)", no_prefix, as_magnitude<5280>(), foot> {};
#ifndef UNITS_NO_LITERALS
@@ -58,7 +58,7 @@ struct exakatal : prefixed_unit<exakatal, exa, katal> {};
struct zettakatal : prefixed_unit<zettakatal, zetta, katal> {};
struct yottakatal : prefixed_unit<yottakatal, yotta, katal> {};
struct enzyme_unit : named_scaled_unit<enzyme_unit, "U", prefix, ratio(1, 60, -6), katal> {};
struct enzyme_unit : named_scaled_unit<enzyme_unit, "U", prefix, as_magnitude<ratio(1, 60, -6)>(), katal> {};
struct dim_catalytic_activity :
isq::dim_catalytic_activity<dim_catalytic_activity, katal, dim_time, dim_amount_of_substance> {};
+2 -1
View File
@@ -55,7 +55,8 @@ struct yottajoule : prefixed_unit<yottajoule, yotta, joule> {};
// 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<electronvolt, "eV", prefix, ratio(1'602'176'634, 1'000'000'000, -19), joule> {};
struct electronvolt :
named_scaled_unit<electronvolt, "eV", prefix, as_magnitude<ratio(1'602'176'634, 1'000'000'000, -19)>(), joule> {};
struct gigaelectronvolt : prefixed_unit<gigaelectronvolt, giga, electronvolt> {};
struct dim_energy : isq::dim_energy<dim_energy, joule, dim_force, dim_length> {};
+2 -1
View File
@@ -56,7 +56,8 @@ struct exametre : prefixed_unit<exametre, exa, metre> {};
struct zettametre : prefixed_unit<zettametre, zetta, metre> {};
struct yottametre : prefixed_unit<yottametre, yotta, metre> {};
struct astronomical_unit : named_scaled_unit<astronomical_unit, "au", no_prefix, ratio(149'597'870'700), metre> {};
struct astronomical_unit :
named_scaled_unit<astronomical_unit, "au", no_prefix, as_magnitude<149'597'870'700>(), metre> {};
struct dim_length : isq::dim_length<metre> {};
@@ -56,7 +56,7 @@ struct exatesla : prefixed_unit<exatesla, exa, tesla> {};
struct zettatesla : prefixed_unit<zettatesla, zetta, tesla> {};
struct yottatesla : prefixed_unit<yottatesla, yotta, tesla> {};
struct gauss : named_scaled_unit<gauss, "G", prefix, ratio(1, 10'000), tesla> {};
struct gauss : named_scaled_unit<gauss, "G", prefix, as_magnitude<ratio(1, 10'000)>(), tesla> {};
struct dim_magnetic_induction :
isq::dim_magnetic_induction<dim_magnetic_induction, tesla, dim_voltage, dim_time, dim_length> {};
+2 -1
View File
@@ -79,7 +79,8 @@ struct zettatonne : prefixed_unit<zettatonne, zetta, tonne> {};
struct yottatonne : prefixed_unit<yottatonne, yotta, tonne> {};
struct dalton :
named_scaled_unit<dalton, "Da", no_prefix, ratio(16'605'390'666'050, 10'000'000'000'000, -27), kilogram> {};
named_scaled_unit<dalton, "Da", no_prefix, as_magnitude<ratio(16'605'390'666'050, 10'000'000'000'000, -27)>(),
kilogram> {};
struct dim_mass : isq::dim_mass<kilogram> {};
+3 -3
View File
@@ -43,9 +43,9 @@ struct picosecond : prefixed_unit<picosecond, pico, second> {};
struct nanosecond : prefixed_unit<nanosecond, nano, second> {};
struct microsecond : prefixed_unit<microsecond, micro, second> {};
struct millisecond : prefixed_unit<millisecond, milli, second> {};
struct minute : named_scaled_unit<minute, "min", no_prefix, ratio(60), second> {};
struct hour : named_scaled_unit<hour, "h", no_prefix, ratio(60), minute> {};
struct day : named_scaled_unit<day, "d", no_prefix, ratio(24), hour> {};
struct minute : named_scaled_unit<minute, "min", no_prefix, as_magnitude<60>(), second> {};
struct hour : named_scaled_unit<hour, "h", no_prefix, as_magnitude<60>(), minute> {};
struct day : named_scaled_unit<day, "d", no_prefix, as_magnitude<24>(), hour> {};
struct dim_time : isq::dim_time<second> {};