Boost logo

Boost :

From: (noreply_at_[hidden])
Date: 2006-11-02 11:03:06

Patches item #1434821, was opened at 2006-02-19 16:24
Message generated for change (Comment added) made by dlwalker
You can respond by visiting:

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Private: No
Submitted By: David Benbennick (dbenbenn)
Assigned to: Jonathan Turkanis (turkanis)
Summary: rational::operator< fails for unsigned value types

Initial Comment:
There's a minor bug in rational.hpp when using unsigned
values. Consider the following simple program:

int main(void) {
  boost::rational<unsigned int> x = 0;

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;
       return -i < (-num/den);
The last line is bogus for unsigned types if num == 0
and i > 0. The problem can be fixed by changing (num >
zero) to (num >= zero).

Another issue with the same section of code is that it
uses up to 5 comparisons of IntType values. Attached
is a patch that fixes the bug described, and also makes
the function only perform up to 3 comparisons. That
can make a difference, of course, if IntType is a
complicated type with a slow comparison operator.


>Comment By: Daryle L. Walker (dlwalker)
Date: 2006-11-02 11:03

Logged In: YES

An extra change while fixing bug #798357 fixes
this issue, without using this patch. The current
solution performs a floor-rounding division and
modulus, followed by a comparison. The floor
division involves either one or two extra comparisons,
for possibly converting from a truncating division.
(The assert currently there uses another comparison.)


You can respond by visiting:

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
Boost-bugs mailing list

Boost list run by bdawes at, gregod at, cpdaniel at, john at