diff --git a/example/capacitor_time_curve.cpp b/example/capacitor_time_curve.cpp index d1c75757f..f2c06f73e 100644 --- a/example/capacitor_time_curve.cpp +++ b/example/capacitor_time_curve.cpp @@ -15,10 +15,10 @@ along with this program. If not, see http://www.gnu.org/licenses./ */ -/* - capacitor discharge curve using compile_time - physical_quantities -*/ +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +// !!! Before you commit any changes to this file please make sure to check if it !!! +// !!! renders correctly in the documentation "Examples" section. !!! +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #ifdef MP_UNITS_IMPORT_STD import std; @@ -33,36 +33,28 @@ import mp_units; #include #endif + int main() { using namespace mp_units; using namespace mp_units::si::unit_symbols; - std::cout << "mp-units capacitor time curve example...\n"; - std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield); - std::cout.precision(3); - constexpr auto CC = isq::capacitance(0.47 * uF); constexpr auto V0 = isq::voltage(5.0 * V); constexpr auto RR = isq::resistance(4.7 * si::kilo); + std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield); + std::cout.precision(3); + std::cout << "Capacitor time curve example for the following parameters:\n"; + std::cout << "Capacitance: " << CC << "\n"; + std::cout << "Initial Voltage: " << V0 << "\n"; + std::cout << "Resistance: " << RR << "\n"; + + std::cout << "Time curve:\n"; for (auto tt = 0 * ms; tt <= 50 * ms; ++tt) { - const QuantityOf auto Vt = V0 * exp(dimensionless(-tt / (RR * CC))); - // TODO try to make the below work instead - // const QuantityOf auto Vt = V0 * exp(-tt / (RR * CC)); - - std::cout << "at " << tt << " voltage is "; - - if (Vt >= 1 * V) - std::cout << Vt.in(V); - else if (Vt >= 1 * mV) - std::cout << Vt.in(mV); - else if (Vt >= 1 * uV) - std::cout << Vt.in(uV); - else if (Vt >= 1 * nV) - std::cout << Vt.in(nV); - else - std::cout << Vt.in(pV); + const QuantityOf auto Vt = V0 * exp(-tt / (RR * CC)); + std::cout << "- at " << tt << " voltage is "; + si::invoke_with_prefixed([](auto q) { std::cout << q; }, Vt, V); std::cout << "\n"; } } diff --git a/example/currency.cpp b/example/currency.cpp index f941ead3e..3ddf67ace 100644 --- a/example/currency.cpp +++ b/example/currency.cpp @@ -20,6 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +// !!! Before you commit any changes to this file please make sure to check if it !!! +// !!! renders correctly in the documentation "Examples" section. !!! +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #include #ifdef MP_UNITS_IMPORT_STD import std; @@ -98,6 +103,5 @@ int main() const quantity_point price_euro = exchange_to(price_usd, timestamp); std::cout << price_usd.quantity_from_zero() << " -> " << price_euro.quantity_from_zero() << "\n"; - // std::cout << price_usd.quantity_from_zero() + price_euro.quantity_from_zero() << "\n"; // does - // not compile + // std::cout << price_usd.quantity_from_zero() + price_euro.quantity_from_zero() << "\n"; // does not compile } diff --git a/example/foot_pound_second.cpp b/example/foot_pound_second.cpp index 704cbd88e..e8ab4aeab 100644 --- a/example/foot_pound_second.cpp +++ b/example/foot_pound_second.cpp @@ -20,6 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +// !!! Before you commit any changes to this file please make sure to check if it !!! +// !!! renders correctly in the documentation "Examples" section. !!! +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #include #include #ifdef MP_UNITS_IMPORT_STD diff --git a/example/hw_voltage.cpp b/example/hw_voltage.cpp index 463f0312e..ad979cf2b 100644 --- a/example/hw_voltage.cpp +++ b/example/hw_voltage.cpp @@ -79,7 +79,8 @@ std::optional read_hw_voltage() void print(QuantityPoint auto qp) { std::cout << MP_UNITS_STD_FMT::format("{:10} ({:5})", qp.quantity_from_zero(), - value_cast(qp).quantity_from_zero()); + value_cast(qp).quantity_from_zero()) + << "\n"; } int main() diff --git a/example/spectroscopy_units.cpp b/example/spectroscopy_units.cpp index e4eb91578..f56b47520 100644 --- a/example/spectroscopy_units.cpp +++ b/example/spectroscopy_units.cpp @@ -20,6 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +// !!! Before you commit any changes to this file please make sure to check if it !!! +// !!! renders correctly in the documentation "Examples" section. !!! +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #include #include #ifdef MP_UNITS_IMPORT_STD diff --git a/example/storage_tank.cpp b/example/storage_tank.cpp index 8d8715d91..9aa0cb502 100644 --- a/example/storage_tank.cpp +++ b/example/storage_tank.cpp @@ -20,6 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +// !!! Before you commit any changes to this file please make sure to check if it !!! +// !!! renders correctly in the documentation "Examples" section. !!! +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #include #include #include diff --git a/example/strong_angular_quantities.cpp b/example/strong_angular_quantities.cpp index ca85fde1b..6556c8cfc 100644 --- a/example/strong_angular_quantities.cpp +++ b/example/strong_angular_quantities.cpp @@ -20,6 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +// !!! Before you commit any changes to this file please make sure to check if it !!! +// !!! renders correctly in the documentation "Examples" section. !!! +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #ifdef MP_UNITS_IMPORT_STD import std; #else