1

I'm trying to use boost::units in my code to define a type RoundsPerMinute. However I am not really understanding how to do that.

I've defined a minute via

using boost::units::si::seconds;

typedef boost::units::make_scaled_unit < boost::units::si::time, boost::units::scale<60, boost::units::static_rational<1> > >::type minute;
BOOST_UNITS_STATIC_CONSTANT(minutes, minute);

typedef boost::units::quantity<minute, float> Minute;

and can now do e.g.

Minute m = 5*minutes;

What I now would like to do is something along the lines of

RoundsPerMinute rpm1 = 50 * rpm;
RoundsPerMinute rpm2 = 100 / (2*minutes);
Minute m = 1/rpm2; // how many minutes does it take for one round?

but I am not sure how to define these types - frankly the whole boost documentation is way too technical for me to understand :-( If anybody could help me out with the definitions, this would be great.

Frankie
  • 653
  • 1
  • 9
  • 20

1 Answers1

2

One RPM is just 1/60 Hertz - see boost::units::si::hertz.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • Thanks for pointing me to Hz. I've tried to use it and it seems to work for the basic stuff. However shouldn't I be able to do 1/Hertz to get the time it takes for one iteration? This fails with unknown operator/. – Frankie Jul 09 '13 at 07:47
  • @Frankie: That doesn't make sense. You do `1/variable` to get another variable. But hertz is a type (as is RPM, both are frequency types). – MSalters Jul 09 '13 at 07:49
  • Of course I meant boost::units::quantity freq = 2*hertz; boost::units::quantity sec = 1/freq; and I would expect to get sec.value() == 0.5. – Frankie Jul 09 '13 at 07:52
  • Ah, I seem to have to use 1.0/freq (cmp. answer to 11087802) – Frankie Jul 09 '13 at 07:56