examples, alternative namespaces : Part2 of put alternative namespace definitions in local headers.

examples, clcpp_response,alternative_namespaces::clcpp_response : use fmt functions for showing precision of quantities
examples, alternative namespaces : combined the alternative namespace quantity typedefs in header files.
examples, alternative namespaces : add simple timer example
This commit is contained in:
Andy Little
2020-03-19 11:43:12 +00:00
committed by Mateusz Pusz
parent c886590b03
commit 6b7e5893d2
13 changed files with 283 additions and 182 deletions

View File

@ -24,6 +24,7 @@
#include <units/physical/si/volume.h>
#include <units/physical/typographic/length.h>
#include <units/physical/us/length.h>
#include <units/format.h>
#include <iostream>
namespace {
@ -105,36 +106,33 @@ void calcs_comparison()
{
using namespace units::si;
std::cout.precision(20);
std::cout << "\nA distinct unit for each type is efficient and accurate\n"
"when adding two values of the same very big\n"
"or very small type:\n\n";
Length AUTO L1A = 2.q_fm;
Length AUTO L2A = 3.q_fm;
Length AUTO LrA = L1A + L2A;
std::cout << L1A << " + " << L2A << " = " << LrA << "\n\n";
length<femtometre,float> L1A = 2.q_fm;
length<femtometre,float> L2A = 3.q_fm;
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> L1B = L1A;
length<metre> L2B = L2A;
length<metre> LrB = L1B + L2B;
std::cout << L1B << " + " << L2B << " = " << LrB << "\n\n";
length<metre,float> L1B = L1A;
length<metre,float> L2B = L2A;
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 AUTO ArA = L1A * L2A;
std::cout << L1A << " * " << L2A << " = " << ArA << "\n\n";
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 AUTO ArB = L1B * L2B;
std::cout << L1B << " * " << L2B << "\n = " << ArB << '\n';
area<square_metre,float> ArB = L1B * L2B;
fmt::print("{:%.30Q %q}\n * {:%.30Q %q}\n = {:%.30Q %q}\n\n",L1B,L2B,ArB);
}
} // namespace