Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2001-05-12 19:48:18


Could/should we have a version of the "div" function defined for rational
numbers? This would provide a dividend and remainder. (You can't use
operator% because operator/ gives an exact answer, not an integer cutoff.)
The function could be something like:

template < typename T >
std::pair< boost::rational<T>, boost::rational<T> >
div( boost::rational<T> dividend, boost::rational<T> divisor )
{
    typedef boost::rational<T> rational_type;

    rational_type const result = dividend / divisor;

    return make_pair( rational_type(result.numerator() /
     result.denominator()), rational_type(result.numerator() %
     result.denominator(), result.denominator() );
}

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk