feat: quantity aliases support addded
This commit is contained in:
1 parent
813197021f
commit
70bff31d06
116 files changed
+2956
-742
No files matched your search
@@ -111,28 +111,28 @@ void calcs_comparison()
|
||||
"when adding two values of the same very big\n"
|
||||
"or very small type:\n\n";
|
||||
|
||||
length<femtometre, float> L1A = 2._q_fm;
|
||||
length<femtometre, float> L2A = 3._q_fm;
|
||||
length<femtometre, float> LrA = L1A + L2A;
|
||||
const length<femtometre, float> L1A = 2._q_fm;
|
||||
const length<femtometre, float> L2A = 3._q_fm;
|
||||
const length<femtometre, float> LrA = L1A + L2A;
|
||||
fmt::print("{:%.30Q %q}\n + {:%.30Q %q}\n = {:%.30Q %q}\n\n", L1A, L2A, LrA);
|
||||
|
||||
std::cout << "The single unit method must convert large\n"
|
||||
"or small values in other units to the base unit.\n"
|
||||
"This is both inefficient and inaccurate\n\n";
|
||||
|
||||
length<metre, float> L1B = L1A;
|
||||
length<metre, float> L2B = L2A;
|
||||
length<metre, float> LrB = L1B + L2B;
|
||||
const length<metre, float> L1B = L1A;
|
||||
const length<metre, float> L2B = L2A;
|
||||
const length<metre, float> LrB = L1B + L2B;
|
||||
fmt::print("{:%.30Q %q}\n + {:%.30Q %q}\n = {:%.30Q %q}\n\n", L1B, L2B, LrB);
|
||||
|
||||
std::cout << "In multiplication and division:\n\n";
|
||||
|
||||
area<square_femtometre, float> ArA = L1A * L2A;
|
||||
const area<square_femtometre, float> ArA = L1A * L2A;
|
||||
fmt::print("{:%.30Q %q}\n * {:%.30Q %q}\n = {:%.30Q %q}\n\n", L1A, L2A, ArA);
|
||||
|
||||
std::cout << "similar problems arise\n\n";
|
||||
|
||||
area<square_metre, float> ArB = L1B * L2B;
|
||||
const area<square_metre, float> ArB = L1B * L2B;
|
||||
fmt::print("{:%.30Q %q}\n * {:%.30Q %q}\n = {:%.30Q %q}\n\n", L1B, L2B, ArB);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ Energy auto total_energy(Momentum auto p, Mass auto m, Speed auto c)
|
||||
void si_example()
|
||||
{
|
||||
using namespace units::isq::si;
|
||||
using GeV = gigaelectronvolt;
|
||||
|
||||
constexpr Speed auto c = si2019::speed_of_light<>;
|
||||
|
||||
@@ -68,17 +67,19 @@ void si_example()
|
||||
<< "E = " << E_si << "\n";
|
||||
|
||||
std::cout << "\n[converted from SI units back to GeV]\n"
|
||||
<< "E = " << quantity_cast<GeV>(E_si) << "\n";
|
||||
<< "E = " << quantity_cast<gigaelectronvolt>(E_si) << "\n";
|
||||
}
|
||||
|
||||
void natural_example()
|
||||
{
|
||||
using namespace units::isq::natural;
|
||||
using GeV = gigaelectronvolt;
|
||||
|
||||
// TODO Typical UDLs will not work here as the same units are reused by many quantities.
|
||||
// Should we define some strange ones (i.e. _q_mass_GeV)?
|
||||
|
||||
constexpr Speed auto c = speed_of_light<>;
|
||||
const momentum<GeV> p(4);
|
||||
const mass<GeV> m(3);
|
||||
const momentum<gigaelectronvolt> p(4);
|
||||
const mass<gigaelectronvolt> m(3);
|
||||
const Energy auto E = total_energy(p, m, c);
|
||||
|
||||
std::cout << "\n*** Natural units (c = " << c << ") ***\n"
|
||||
|
||||
Reference in new issue
Block a user