All UDLs are now prefixed with q_

This commit is contained in:
Mateusz Pusz
2020-02-17 15:56:06 +01:00
parent 0566cc631d
commit 18620044c5
65 changed files with 768 additions and 768 deletions
+9 -9
View File
@@ -68,7 +68,7 @@ void example()
// SI (int)
{
using namespace units::si::literals;
constexpr Length AUTO distance = 220km; // constructed from a UDL
constexpr Length AUTO distance = 220q_km; // constructed from a UDL
constexpr si::time<si::hour, int> duration(2); // constructed from a value
std::cout << "SI units with 'int' as representation\n";
@@ -82,8 +82,8 @@ void example()
// SI (double)
{
using namespace units::si::literals;
constexpr Length AUTO distance = 220.km; // constructed from a UDL
constexpr si::time<si::hour> duration(2); // constructed from a value
constexpr Length AUTO distance = 220.q_km; // constructed from a UDL
constexpr si::time<si::hour> duration(2); // constructed from a value
std::cout << "\nSI units with 'double' as representation\n";
@@ -98,7 +98,7 @@ void example()
// Customary Units (int)
{
using namespace units::international::literals;
constexpr Length AUTO distance = 140mi; // constructed from a UDL
constexpr Length AUTO distance = 140q_mi; // constructed from a UDL
constexpr si::time<si::hour, int> duration(2); // constructed from a value
std::cout << "\nUS Customary Units with 'int' as representation\n";
@@ -114,7 +114,7 @@ void example()
// Customary Units (double)
{
using namespace units::international::literals;
constexpr Length AUTO distance = 140.mi; // constructed from a UDL
constexpr Length AUTO distance = 140q_mi; // constructed from a UDL
constexpr si::time<si::hour> duration(2); // constructed from a value
std::cout << "\nUS Customary Units with 'double' as representation\n";
@@ -132,8 +132,8 @@ void example()
// CGS (int)
{
using namespace units::cgs::literals;
constexpr Length AUTO distance = 22'000'000cm; // constructed from a UDL
constexpr cgs::time<si::hour, int> duration(2); // constructed from a value
constexpr Length AUTO distance = 22'000'000q_cm; // constructed from a UDL
constexpr cgs::time<si::hour, int> duration(2); // constructed from a value
std::cout << "\nCGS units with 'int' as representation\n";
@@ -151,8 +151,8 @@ void example()
// CGS (double)
{
using namespace units::cgs::literals;
constexpr Length AUTO distance = 22'000'000.cm; // constructed from a UDL
constexpr cgs::time<si::hour> duration(2); // constructed from a value
constexpr Length AUTO distance = 22'000'000q_cm; // constructed from a UDL
constexpr cgs::time<si::hour> duration(2); // constructed from a value
std::cout << "\nCGS units with 'double' as representation\n";
+4 -4
View File
@@ -101,11 +101,11 @@ struct Box {
using namespace units::si::literals;
int main()
{
auto box = Box{1000.0mm, 500.0mm, 200.0mm};
box.set_contents_density(1000.0kgpm3);
auto box = Box{1000.0q_mm, 500.0q_mm, 200.0q_mm};
box.set_contents_density(1000.0q_kgpm3);
auto fill_time = 200.0s; // time since starting fill
auto measured_mass = 20.0kg; // measured mass at fill_time
auto fill_time = 200.0q_s; // time since starting fill
auto measured_mass = 20.0q_kg; // measured mass at fill_time
std::cout << "mpusz/units box example...\n";
std::cout << "fill height at " << fill_time << " = " << box.fill_level(measured_mass) << " ("
+8 -8
View File
@@ -56,22 +56,22 @@ int main()
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
std::cout.precision(3);
constexpr auto C = 0.47uF;
constexpr auto V0 = 5.0V;
constexpr auto R = 4.7kR;
constexpr auto C = 0.47q_uF;
constexpr auto V0 = 5.0q_V;
constexpr auto R = 4.7q_kR;
for (auto t = 0ms; t <= 50ms; ++t) {
for (auto t = 0q_ms; t <= 50q_ms; ++t) {
const auto Vt = V0 * std::exp(-t / (R * C));
std::cout << "at " << t << " voltage is ";
if (Vt >= 1V)
if (Vt >= 1q_V)
std::cout << Vt;
else if (Vt >= 1mV)
else if (Vt >= 1q_mV)
std::cout << voltage::mV<>{Vt};
else if (Vt >= 1uV)
else if (Vt >= 1q_uV)
std::cout << voltage::uV<>{Vt};
else if (Vt >= 1nV)
else if (Vt >= 1q_nV)
std::cout << voltage::nV<>{Vt};
else
std::cout << voltage::pV<>{Vt};
+13 -13
View File
@@ -130,12 +130,12 @@ void simple_quantities()
using distance = length::m<>;
using time = time::s<>;
constexpr distance km = 1.0km;
constexpr distance miles = 1.0mi;
constexpr distance km = 1.0q_km;
constexpr distance miles = 1.0q_mi;
constexpr time sec = 1s;
constexpr time min = 1min;
constexpr time hr = 1h;
constexpr time sec = 1q_s;
constexpr time min = 1q_min;
constexpr time hr = 1q_h;
std::cout << "A physical quantities library can choose the simple\n";
std::cout << "option to provide output using a single type for each base unit:\n\n";
@@ -148,14 +148,14 @@ void simple_quantities()
void quantities_with_typed_units()
{
constexpr length::km<> km = 1.0km;
constexpr length::mi<> miles = 1.0mi;
constexpr length::km<> km = 1.0q_km;
constexpr length::mi<> miles = 1.0q_mi;
std::cout.precision(6);
constexpr time::s<> sec = 1s;
constexpr time::min<> min = 1min;
constexpr time::h<> hr = 1h;
constexpr time::s<> sec = 1q_s;
constexpr time::min<> min = 1q_min;
constexpr time::h<> hr = 1q_h;
std::cout << "A more flexible option is to provide separate types for each unit,\n\n";
std::cout << km << '\n';
@@ -164,7 +164,7 @@ void quantities_with_typed_units()
std::cout << min << '\n';
std::cout << hr << "\n\n";
constexpr length::m<> meter = 1m;
constexpr length::m<> meter = 1q_m;
std::cout << "then a wide range of pre-defined units can be defined and converted,\n"
" for consistency and repeatability across applications:\n\n";
@@ -197,8 +197,8 @@ void calcs_comparison()
"when adding two values of the same very big\n"
"or very small type:\n\n";
length::fm<float> L1A = 2fm;
length::fm<float> L2A = 3fm;
length::fm<float> L1A = 2q_fm;
length::fm<float> L2A = 3q_fm;
length::fm<float> LrA = L1A + L2A;
std::cout << L1A << " + " << L2A << " = " << LrA << "\n\n";
+1 -1
View File
@@ -64,7 +64,7 @@ int main()
{
std::cout << "conversion factor in mpusz/units...\n\n";
constexpr length::m<> lengthA = 2.0m;
constexpr length::m<> lengthA = 2.0q_m;
constexpr length::mm<> lengthB = lengthA;
std::cout << "lengthA( " << lengthA << " ) and lengthB( " << lengthB << " )\n"
+1 -1
View File
@@ -35,7 +35,7 @@ constexpr Velocity AUTO avg_speed(Length AUTO d, Time AUTO t)
int main()
{
using namespace si::literals;
Velocity AUTO v1 = avg_speed(220km, 2h);
Velocity AUTO v1 = avg_speed(220q_km, 2q_h);
Velocity AUTO v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
Velocity AUTO v3 = quantity_cast<si::metre_per_second>(v2);
Velocity AUTO v4 = quantity_cast<int>(v3);
+5 -5
View File
@@ -35,13 +35,13 @@ void example()
{
using namespace units::si::literals;
units::Length AUTO d1 = 123m;
units::Time AUTO t1 = 10s;
units::Length AUTO d1 = 123q_m;
units::Time AUTO t1 = 10q_s;
units::Velocity AUTO v1 = avg_speed(d1, t1);
auto temp1 = v1 * 50m; // produces intermediate unknown dimension with 'unknown_unit' as its 'coherent_unit'
units::Velocity AUTO v2 = temp1 / 100m; // back to known dimensions again
units::Length AUTO d2 = v2 * 60s;
auto temp1 = v1 * 50q_m; // produces intermediate unknown dimension with 'unknown_unit' as its 'coherent_unit'
units::Velocity AUTO v2 = temp1 / 100q_m; // back to known dimensions again
units::Length AUTO d2 = v2 * 60q_s;
std::cout << "d1 = " << d1 << '\n';
std::cout << "t1 = " << t1 << '\n';