Boost logo

Boost Users :

Subject: [Boost-users] [Units] Un-scaling dimensionless value
From: Lindley French (lindleyf_at_[hidden])
Date: 2014-02-14 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

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;

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
scaled----it'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 un-scale 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?

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at