Boost logo

Boost Users :

Subject: Re: [Boost-users] [mpl, units] rational and static_rational
From: Matthias Schabel (boost_at_[hidden])
Date: 2009-09-02 13:32:15


> 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


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