Examples with an alternate way to create quantities refactored
- examples modified to provide a unified library look-and-feel - originals moved to a dedicated subdirectory for further reference and comparison
This commit is contained in:
1 parent
0c5864cc87
commit
4b33c0f7c5
10 files changed
+644
-259
No files matched your search
@@ -27,32 +27,12 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
namespace voltage {
|
||||
|
||||
template<typename Rep = double>
|
||||
using V = units::si::voltage<units::si::volt, Rep>;
|
||||
|
||||
template<typename Rep = double>
|
||||
using mV = units::si::voltage<units::si::millivolt, Rep>;
|
||||
|
||||
template<typename Rep = double>
|
||||
using uV = units::si::voltage<units::si::microvolt, Rep>;
|
||||
|
||||
template<typename Rep = double>
|
||||
using nV = units::si::voltage<units::si::nanovolt, Rep>;
|
||||
|
||||
template<typename Rep = double>
|
||||
using pV = units::si::voltage<units::si::picovolt, Rep>;
|
||||
|
||||
} // namespace voltage
|
||||
} // namespace
|
||||
|
||||
using namespace units::si::literals;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "mpusz/units capacitor time curve example...\n";
|
||||
using namespace units;
|
||||
using namespace units::si;
|
||||
|
||||
std::cout << "mp-units capacitor time curve example...\n";
|
||||
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
|
||||
std::cout.precision(3);
|
||||
|
||||
@@ -61,20 +41,20 @@ int main()
|
||||
constexpr auto R = 4.7q_kR;
|
||||
|
||||
for (auto t = 0q_ms; t <= 50q_ms; ++t) {
|
||||
const auto Vt = V0 * std::exp(-t / (R * C));
|
||||
const Voltage auto Vt = V0 * std::exp(-t / (R * C));
|
||||
|
||||
std::cout << "at " << t << " voltage is ";
|
||||
|
||||
if (Vt >= 1q_V)
|
||||
std::cout << Vt;
|
||||
else if (Vt >= 1q_mV)
|
||||
std::cout << voltage::mV<>{Vt};
|
||||
std::cout << quantity_cast<millivolt>(Vt);
|
||||
else if (Vt >= 1q_uV)
|
||||
std::cout << voltage::uV<>{Vt};
|
||||
std::cout << quantity_cast<microvolt>(Vt);
|
||||
else if (Vt >= 1q_nV)
|
||||
std::cout << voltage::nV<>{Vt};
|
||||
std::cout << quantity_cast<nanovolt>(Vt);
|
||||
else
|
||||
std::cout << voltage::pV<>{Vt};
|
||||
std::cout << quantity_cast<picovolt>(Vt);
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user