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 22:51:35


W Z <zwt2002_at_[hidden]> writes:

> I am using the rational class (which is actually based on the
> boost.rational library) as the second parameter of the quantity
> field. Declaring the quantity presents no problem. However, conversion
> from one unit to another has more problems because my rational class
> doesn't support double. It shouldn't support double because I'm trying
> to make sure conversion factors are all represented as rational
> numbers. This conversion part is what I am having trouble with. I'm
> just trying to see if there is an easy way to convert units using
> rational conversion factors in boost.units without resorting to
> re-writing some of the units library code. I hope this makes more
> sense?

OK, so your problem is with the conversion factors being rational as
well. Sorry but I won't be able to help with that.

> Thanks!
>
>> From: olaf.meeuwissen_at_[hidden]
>> To: boost-users_at_[hidden]
>> Date: Mon, 23 Jan 2012 08:44:10 +0900
>> CC: boostusers_at_[hidden]
>> Subject: Re: [Boost-users] [units] Question about user-define d value types
>>
>> 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
>> http://www.fsf.org/jf?referrer=1962
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/ boost-users
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

-- 
Olaf Meeuwissen, LPIC-2           FLOSS Engineer -- AVASYS CORPORATION
FSF Associate Member #1962               Help support software freedom
                 http://www.fsf.org/jf?referrer=1962

Boost-users 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