[Boost-bugs] [ boost-Patches-1434821 ] rational::operator< fails for unsigned value types

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: https://sourceforge.net/tracker/?func=detail&atid=307586&aid=1434821&group_id=7586 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; 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); 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
Message: Logged In: YES user_id=551024 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: https://sourceforge.net/tracker/?func=detail&atid=307586&aid=1434821&group_id=7586 ------------------------------------------------------------------------- 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 http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Boost-bugs mailing list Boost-bugs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/boost-bugs
participants (1)
-
SourceForge.net