Boost logo

Boost Users :

Subject: Re: [Boost-users] [units] Question about user-defined value types
From: Olaf Meeuwissen (olaf.meeuwissen_at_[hidden])
Date: 2012-01-22 18:44:10

W Z <zwt2002_at_[hidden]> writes:

> The rational type right now has a numerator and a denominator, both
> are long type. I would like to support operations with rational
> numbers only to keep the number representation precise, so no double
> types should be involved.
> I first tried to get scaled units working with rational
> numbers. However, make_scaled_units takes in a scale and then
> internally returns a double value as a scale. I then wrote my own
> scale class but it's only partially working (conversion works one way
> only). It just seems like boost.units has a lot of places internally
> that use double as scale factors and conversion factors, and I'm
> looking for a cleaner way to make units library support rational
> numbers without re-writing a lot of code. Any idea would be greatly
> appreciated!

I've only just started looking at Boost.Unit, but your comments made me
wonder if you're specifying the second template parameter to quantity.
The boost/units/quantity.hpp file has

  template<class Unit, class Y = double> class quantity;

I would think that something like

  quantity<length, rational> distance;

ought to work as expected.

BTW, you are aware of Boost.Rational, right?

Hope this helps,

Olaf Meeuwissen, LPIC-2           FLOSS Engineer -- AVASYS CORPORATION
FSF Associate Member #1962               Help support software freedom

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