1 parent
cf3408a3c8
commit
b4f47c3fef
19 files changed
+220
-212
No files matched your search
+8
-12
@@ -52,8 +52,7 @@ constexpr QuantityOf<isq::speed> auto avg_speed(QuantityOf<isq::length> auto d,
|
||||
template<QuantityOf<isq::length> D, QuantityOf<isq::time> T, QuantityOf<isq::speed> V>
|
||||
void print_result(D distance, T duration, V speed)
|
||||
{
|
||||
constexpr auto kmph = si::kilo<si::metre> / si::hour;
|
||||
const auto result_in_kmph = quantity_cast<kmph>(speed);
|
||||
const auto result_in_kmph = value_cast<km / h>(speed);
|
||||
std::cout << "Average speed of a car that makes " << distance << " in " << duration << " is " << result_in_kmph
|
||||
<< ".\n";
|
||||
}
|
||||
@@ -80,8 +79,7 @@ void example()
|
||||
std::cout << "\nSI units with 'double' as representation\n";
|
||||
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
print_result(distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<int>(distance), quantity_cast<int>(duration)));
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(value_cast<int>(distance), value_cast<int>(duration)));
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, avg_speed(distance, duration));
|
||||
}
|
||||
@@ -97,7 +95,7 @@ void example()
|
||||
|
||||
// it is not possible to make a lossless conversion of miles to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<si::metre>(distance), duration));
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(value_cast<si::metre>(distance), duration));
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, avg_speed(distance, duration));
|
||||
}
|
||||
@@ -114,9 +112,8 @@ void example()
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
// also it is not possible to make a lossless conversion of miles to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(
|
||||
distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<quantity<isq::length[m], int>>(distance), quantity_cast<int>(duration)));
|
||||
print_result(distance, duration,
|
||||
fixed_int_si_avg_speed(value_cast<int>(value_cast<si::metre>(distance)), value_cast<int>(duration)));
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, avg_speed(distance, duration));
|
||||
}
|
||||
@@ -130,7 +127,7 @@ void example()
|
||||
|
||||
// it is not possible to make a lossless conversion of centimeters to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<si::metre>(distance), duration));
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(value_cast<si::metre>(distance), duration));
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, avg_speed(distance, duration));
|
||||
}
|
||||
@@ -145,9 +142,8 @@ void example()
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
// it is not possible to make a lossless conversion of centimeters to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(
|
||||
distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<quantity<isq::length[m], int>>(distance), quantity_cast<int>(duration)));
|
||||
print_result(distance, duration,
|
||||
fixed_int_si_avg_speed(value_cast<int>(value_cast<m>(distance)), value_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, avg_speed(distance, duration));
|
||||
|
||||
@@ -40,7 +40,7 @@ int main()
|
||||
constexpr auto R = isq::resistance(4.7, si::kilo<si::ohm>);
|
||||
|
||||
for (auto t = isq::time(0, ms); t <= isq::time(50, ms); ++t) {
|
||||
const weak_quantity_of<isq::voltage> auto Vt = V0 * mp_units::exp(-t / (R * C));
|
||||
const WeakQuantityOf<isq::voltage> auto Vt = V0 * mp_units::exp(-t / (R * C));
|
||||
|
||||
std::cout << "at " << t << " voltage is ";
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ template<mp_units::Quantity Target, mp_units::Quantity Source>
|
||||
requires std::constructible_from<Target, Source>
|
||||
inline constexpr double conversion_factor(Target, Source)
|
||||
{
|
||||
return quantity_cast<Target::unit>(1. * Source::reference).number();
|
||||
return value_cast<Target::unit>(1. * Source::reference).number();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -52,7 +52,7 @@ struct Ship {
|
||||
template<Unit auto... Us, Quantity Q>
|
||||
auto fmt_line(const Q& q)
|
||||
{
|
||||
return STD_FMT::format("{:22}", q) + (STD_FMT::format(",{:20}", quantity_cast<Us>(q)) + ...);
|
||||
return STD_FMT::format("{:22}", q) + (STD_FMT::format(",{:20}", value_cast<Us>(q)) + ...);
|
||||
}
|
||||
|
||||
// Print the ship details in the units as defined in the Ship struct, in other si::imperial units, and in SI
|
||||
|
||||
@@ -77,7 +77,7 @@ void print(std::string_view phase_name, timestamp start_ts, const glide_computer
|
||||
std::cout << STD_FMT::format(
|
||||
"| {:<12} | {:>9%.1Q %q} (Total: {:>9%.1Q %q}) | {:>8%.1Q %q} (Total: {:>8%.1Q %q}) | {:>7%.0Q %q} ({:>6%.0Q %q}) "
|
||||
"|\n",
|
||||
phase_name, quantity_cast<si::minute>(new_point.ts - point.ts), quantity_cast<si::minute>(new_point.ts - start_ts),
|
||||
phase_name, value_cast<si::minute>(new_point.ts - point.ts), value_cast<si::minute>(new_point.ts - start_ts),
|
||||
new_point.dist - point.dist, new_point.dist, new_point.alt - point.alt, new_point.alt);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,11 +85,11 @@ void print(const R& gliders)
|
||||
std::cout << "- Name: " << g.name << "\n";
|
||||
std::cout << "- Polar:\n";
|
||||
for (const auto& p : g.polar) {
|
||||
const auto ratio = quantity_cast<one>(glide_ratio(g.polar[0]));
|
||||
const auto ratio = value_cast<one>(glide_ratio(g.polar[0]));
|
||||
std::cout << STD_FMT::format(" * {:%.4Q %q} @ {:%.1Q %q} -> {:%.1Q %q} ({:%.1Q %q})\n", p.climb, p.v, ratio,
|
||||
// TODO is it possible to make ADL work below (we need another set of trig functions
|
||||
// for strong angle in a different namespace)
|
||||
quantity_cast<si::degree>(isq::asin(1 / ratio)));
|
||||
value_cast<si::degree>(isq::asin(1 / ratio)));
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ int main()
|
||||
constexpr auto v2 = isq::speed(70., mph);
|
||||
constexpr auto v3 = avg_speed(isq::distance(220, km), isq::duration(2, h));
|
||||
constexpr auto v4 = avg_speed(quantity<isq::distance[mi]>{140}, quantity<isq::duration[h]>{2});
|
||||
constexpr auto v5 = quantity_cast<quantity<isq::speed[m / s]>>(v3);
|
||||
constexpr auto v6 = quantity_cast<m / s>(v4);
|
||||
constexpr auto v7 = quantity_cast<int>(v6);
|
||||
constexpr auto v5 = value_cast<m / s>(v3);
|
||||
constexpr auto v6 = value_cast<m / s>(v4);
|
||||
constexpr auto v7 = value_cast<int>(v6);
|
||||
|
||||
std::cout << v1 << '\n'; // 110 km/h
|
||||
std::cout << v2 << '\n'; // 70 mi/h
|
||||
|
||||
@@ -95,7 +95,7 @@ void quantity_of_vector_cast()
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
|
||||
std::cout << "v[km] = " << quantity_cast<km>(v) << "\n";
|
||||
std::cout << "v[km] = " << value_cast<km>(v) << "\n";
|
||||
std::cout << "u[m] = " << u[m] << "\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ void si_example()
|
||||
<< "E = " << E3 << "\n";
|
||||
|
||||
std::cout << "\n[converted from SI units back to GeV]\n"
|
||||
<< "E = " << quantity_cast<GeV>(E3) << "\n";
|
||||
<< "E = " << value_cast<GeV>(E3) << "\n";
|
||||
}
|
||||
|
||||
void natural_example()
|
||||
|
||||
Reference in new issue
Block a user