|
Boost : |
From: Bill Seymour (bsey_at_[hidden])
Date: 2001-03-04 09:06:54
For my newbie submission to Boost, I have:
template<class T, bool Dp = false>
struct integer_division_traits
{
typedef /* unsigned members iff T is unsigned type */ div_t;
static div_t div(T dividend, T divisor);
static T gcd(T, T); // greatest common divisor
static T lcm(T, T); // least common multiple
static T floor(T dividend, T divisor);
static T ceil (T dividend, T divisor);
static T trunc(T dividend, T divisor); // toward zero
enum rounding_mode
{
nearest_even,
// other obvious ones
}
static T round(T dividend, T divisor,
rounding_mode = nearest_even);
// other minor stuff
};
The second template argument indicates whether a signed divisor
is known to be > 0, for example, in a rational number class that
eagerly keeps its denominator positive. It has no effect iff
T is an unsigned type.
I'm in the process of Boostifying the documentation, and expect
to have a package ready to upload by the middle of the week
if there's sufficient interest.
Thanks,
--Bill Seymour
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk