Re: [Boost-users] [mpl, units] rational and static_rational

I am looking for a template library that can handle compile time rationals, ideally with a similar interface to mpl::int_ and that plays well with boost::rational (the dynamic type).
First I found boost/mpl/math/rational_c.hpp but soon I realized that it doesn't work with basic operations like mpl::plus, it doesn't even simplify reducible fractions (i.e. 2/4 -> 1/2), in fact it looks like it is just the storage of two (static) integers. Is this something that will be developed in the future or am I using it in the wrong way?
Then I found boost::units::static_rational which is more promising, because it simplifies fractions and works with mpl::plus, but it is not integrated with boost::rational nor has an interface similar to that of mpl metatypes.
Is there a way of extending mpl::math::rational_c with the existing libraries in boost, or a simple way to make boost::units::static_rational have an interface similar to mpl and also have a value type that returns it runtime boost::rational value?
I certainly would have no objection to repackaging the static_rational type used in Boost.Units as an MPL type that plays nicely with Boost.Rational. My advice would be to put together a functional implementation and propose it for a mini-review. We could easily typedef units::static_rational -> mpl::rational_ in the units library. Matthias

AMDG Matthias Schabel wrote:
I am looking for a template library that can handle compile time rationals, ideally with a similar interface to mpl::int_ and that plays well with boost::rational (the dynamic type).
First I found boost/mpl/math/rational_c.hpp but soon I realized that it doesn't work with basic operations like mpl::plus, it doesn't even simplify reducible fractions (i.e. 2/4 -> 1/2), in fact it looks like it is just the storage of two (static) integers. Is this something that will be developed in the future or am I using it in the wrong way?
Then I found boost::units::static_rational which is more promising, because it simplifies fractions and works with mpl::plus, but it is not integrated with boost::rational nor has an interface similar to that of mpl metatypes.
Is there a way of extending mpl::math::rational_c with the existing libraries in boost, or a simple way to make boost::units::static_rational have an interface similar to mpl and also have a value type that returns it runtime boost::rational value?
I certainly would have no objection to repackaging the static_rational type used in Boost.Units as an MPL type that plays nicely with Boost.Rational.
The main issue will be that Boost.Units requires unique types (to keep template instantiations down). MPL doesn't care about unique types.
My advice would be to put together a functional implementation and propose it for a mini-review. We could easily typedef units::static_rational -> mpl::rational_ in the units library.
You can't typedef a template like that. In Christ, Steven Watanabe
participants (2)
-
Matthias Schabel
-
Steven Watanabe