[rational] operator< fails for unsigned value types. Here's a small patch to fix it

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
participants (1)
-
David Benbennick