[units] Question about user-defined value types
Hi, I am using boost units library for a project in which I need to define quantities using rational numbers. I have a rational number class but am having trouble integrating it with units library. There seems to be a lot of places where the units library implementation assumes that the conversion values are expressed as double type. Is there a good way to get around this to make units library support rational numbers? Thanks, WZ
On Friday, January 20, 2012 8:06:46 AM UTC-8, W Z wrote:
Hi,
I am using boost units library for a project in which I need to define quantities using rational numbers. I have a rational number class but am having trouble integrating it with units library. There seems to be a lot of places where the units library implementation assumes that the conversion values are expressed as double type. Is there a good way to get around this to make units library support rational numbers?
Can you post a particular example? Does you rational type model a double type? what operation is that boost.units need and your class doesn't have? Thanks, Alfredo
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! Thanks,Wenting Date: Sat, 21 Jan 2012 19:45:35 -0800 From: alfredo.correa@gmail.com To: boostusers@googlegroups.com CC: boost-users@lists.boost.org Subject: Re: [Boost-users] [units] Question about user-defined value types On Friday, January 20, 2012 8:06:46 AM UTC-8, W Z wrote: Hi, I am using boost units library for a project in which I need to define quantities using rational numbers. I have a rational number class but am having trouble integrating it with units library. There seems to be a lot of places where the units library implementation assumes that the conversion values are expressed as double type. Is there a good way to get around this to make units library support rational numbers? Can you post a particular example? Does you rational type model a double type? what operation is that boost.units need and your class doesn't have? Thanks, Alfredo _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
W Z
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
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? Thanks!
From: olaf.meeuwissen@avasys.jp To: boost-users@lists.boost.org Date: Mon, 23 Jan 2012 08:44:10 +0900 CC: boostusers@googlegroups.com Subject: Re: [Boost-users] [units] Question about user-defined value types
W Z
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 quantity; I would think that something like
quantity
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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
W Z
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@avasys.jp To: boost-users@lists.boost.org Date: Mon, 23 Jan 2012 08:44:10 +0900 CC: boostusers@googlegroups.com Subject: Re: [Boost-users] [units] Question about user-define d value types
W Z
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 quantity; I would think that something like
quantity
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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/ boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org 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
participants (3)
-
alfC
-
Olaf Meeuwissen
-
W Z