|
Boost : |
From: Bill Seymour (bsey_at_[hidden])
Date: 2001-03-07 08:22:31
Daryle Walker wrote:
>
> A bunch of these are also in the "more_math.zip" package
> I uploaded to the vault a while back.
>
I didn't see those...I just checked for similar things in
the already existing integer library. I'll look for it.
>
> Some of these functions look more appropriate as part of
> "rational.hpp".
>
Indeed, the class was inspired by my attempt to make an existing
rational number class a template class. (It was written before
I knew about Boost and rational.hpp.)
>
> enum rounding_mode
> {
> nearest, // down if < 1/2, up if >= 1/2
> nearest_even, // down if < 1/2, up if > 1/2, to even if == 1/2
> // following should be obvious from names
> towards_zero,
> towards_pos_infinity,
> towards_neg_infinity,
> leaving_zero
> };
>
This is a little different from what I wrote...my round function
always rounds to the nearest integer except in the special case
where the remainder is exactly half of the divisor, so there is
no "nearest" integer.
>
> >
> > 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 don't get what you're trying to say here. Wouldn't the greater-
> than-zero property be dependent on what you put in the "divisor"
> argument, and not as a template parameter.
>
Normally, the user would just let the second template argument
default to false. In the example of the rational number class
that I gave, the denominator is _known_ to be greater than zero
at compile time (because the rational number class is written
that way), so the code for floor, ceil, gcd, etc. can be more
efficient.
--Bill Seymour
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk