|
Boost : |
From: David Benbennick (dbenbenn_at_[hidden])
Date: 2006-02-19 04:47:26
There's a minor bug in rational.hpp when using unsigned values.
Consider the following simple program:
#include <boost/rational.hpp>
#include <cassert>
int main(void) {
boost::rational<unsigned int> x = 0;
assert(x.operator<(1));
}
The assertion fails. The reason is that in
rational.hpp::rational<IntType>::operator< (param_type i) are the
lines
if (num > zero)
return (num/den) < i;
else
return -i < (-num/den); <-- this is bogus for unsigned types
if num == 0.
Attached are two patches to fix the problem. The first is a minimal
patch, changing the > to >=. The second patch changes more: in the
current code, up to 5 comparisons can happen. In the patched version,
only 3 comparisons are done.
Cheers,
David Benbennick
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk