|
Boost : |
From: Paul Moore (gustav_at_[hidden])
Date: 2001-05-13 11:06:23
Daryle Walker <darylew_at_[hidden]> writes:
> 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.)
I'm not sure what you'd get. As operator/ on rationals gives an exact
answer, operator% is always zero. So div(r1,r2) is (r1/r2, 0). No, you
can't mean that...
So I assume you're after q and r from the equation
r1 = r2 * q + r
where q and r are of type T and q > 0...
That's possible, but (a) you could write it yourself, (b) I'm not sure
what the use of such a function would be on rationals, and (c) as
evidenced by the fact that your description wasn't 100% clear to me,
it's not obvious (to a casual viewer) what such a function would do.
So my instinct is not to include this.
> The function could be something like:
[code omitted]
OK, that looks simple enough. (You can view that comment as meaning
"so I could add it easily", or "so you can write it yourself if you
need it" :-))
But if someone came up with concerns about edge cases, I don't feel
confident to comment. For example, how does it behave at the limits of
the precision of rational<T>? Is that what real users would want? Can
it suffer catastrophic loss of precision?
It took a lot of help from people more competent than me before the
issues in operator+= were teased out. I don't want the same to happen
with something like this.
So overall, I go with my instinct...
Paul.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk