Boost logo

Boost :

From: David Richardson (dgr24_at_[hidden])
Date: 2003-10-16 07:58:34

David Abrahams wrote:

> Well, you can make "compile-time rationals", but they can't look like
> our Boost rational class because the numerator and denominator have to
> be part of the type.

The syntax I ended up with is a bit messy, but it works. You can
use it as:

typedef Rational::New<1,2>::type oneHalf;
typedef Rational::New<3,2>::type threeHalves;

//all rationals are stored in reduced terms
Rational::Add<oneHalf, threeHalves>::type two;

//get at the numerator and denominator
assert(two::n == 2);
assert(two::d == 1);

There are 'methods' for addition, subtraction, multiplication,
division, and absolute value.

I considered arbitrary precision compile-time integers for the
numerator and denominator, but that seemed like far too much work
for no clear payoff.


Boost list run by bdawes at, gregod at, cpdaniel at, john at