AMDG On 03/22/2013 01:13 AM, Dennis Gertitschke wrote:
Hi community,
while the code below works, i am not sure if it is the best/most elegant approach. Specifically,
a) can i somehow reuse the minute_base_unit from SI (rpm=dimensionless/minute_base_unit)?
Yes.
b) Is the cast to quantity<frequency> in velocity calculation avoidable, e.g. can be done automatically?
No. Conversions between different units are intentionally explicit.
Dennis <snip>
BOOST_UNITS_DEFINE_BASE_UNIT_WITH_CONVERSIONS(si, revolution, revolutions per minute", "rpm", 1.0/60.0, frequency, 1); typedef revolution_base_unit::unit_type revolution; BOOST_UNITS_STATIC_CONSTANT(rpm, revolution);
typedef decltype(si::dimensionless / metric::minute_base_unit::unit_type()) revolution;
BOOST_UNITS_DEFINE_BASE_UNIT_WITH_CONVERSIONS(si, velocity_kmh, "velocity", "km/h", 1.0/3.6, velocity, 2); typedef velocity_kmh_base_unit::unit_type velocity_kmh; BOOST_UNITS_STATIC_CONSTANT(kmh, velocity_kmh);
typedef decltype(si::kilometers / metric::hour_base_unit::unit_type()) velocity_kmh;
int main(int argc, char* argv[]) { quantity<velocity> v(0.0 * meter_per_second); quantity<length> r(0.63 * meter); quantity<dimensionless> i_HA(4.5 * si_dimensionless); quantity<dimensionless> i_G(1.0 * si_dimensionless); quantity<revolution> n(3000.0 * rpm); quantity<dimensionless> pi2(2.0 * M_PI * si_dimensionless);
cout << n << endl; v = ((quantity<frequency>)n / (i_HA * i_G)) * pi2 * r; cout << v << endl; quantity
v2(v); cout << v2 << endl; return 0; }
In Christ, Steven Watanabe