
Boost Users : 
Subject: [Boostusers] [Units] Unscaling dimensionless value
From: Lindley French (lindleyf_at_[hidden])
Date: 20140214 19:06:06
I am using Boost.Units to try and compute the number of samples in a time
interval, given the sample rate. Given this code:
typedef make_scaled_unit<si::frequency, scale<10, static_rational<3> >
>::type kilohertz_unit;
typedef make_scaled_unit<si::time, scale<10, static_rational<6> > >::type
microseconds_unit;
<code>
template <typename T=unsigned>
using Kilohertz = quantity<kilohertz_unit,T>;
template <typename T=unsigned>
using Microseconds = quantity<microseconds_unit,T>;
// Using boost::rational as the value type neatly avoids overflows
Kilohertz<rational<unsigned>> sample_rate(125*si::kilo*si::hertz);
Microseconds<rational<unsigned>> duration(10*si::seconds);
auto total = sample_rate*duration;
</code>
Now, when I cout these values, I see that everything is technically the
correct. The problem is that total is a dimensionless quantity which is
scaledit's 1,250,000,000, when I expect 1,250,000, and it displays as
"1250000000 m", where m is "milli", not "meters".
What is the correct way to unscale dimensionless quantities? I tried this:
quantity<si::dimensionless,rational<unsigned>> unscaled(total);
However, unscaled still has the same value.
I also tried
typedef make_scaled_unit<si::dimensionless, scale<10, static_rational<0> >
>::type dimensionless_unit;
quantity<dimensionless_unit,rational<unsigned>> unscaled(total);
but this time, unscaled came out zero.
Any suggestions?
Boostusers list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net