[Boost-bugs] [ boost-Patches-1438626 ] rational.hpp::gcd returns a negative value sometimes

Patches item #1438626, was opened at 2006-02-25 09:49 Message generated for change (Comment added) made by dlwalker You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=307586&aid=1438626&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.hpp::gcd returns a negative value sometimes
Initial Comment: boost/rational.hpp provides a gcd function, which is supposed to be non-negative. It sometimes returns a negative value, which can cause problems in other parts of rational.hpp. For example, assuming long is a 4-byte type, boost::gcd<long>(6, -2147483648) returns -2. As a result, boost::rational<long>(-1073741821, 6) + boost::rational<long>(-1073741827, 6) produces an invalid rational number, 1073741824/-3, instead of the correct answer -1073741824/3. Here is a small patch to fix the problem. Note that this is how boost/math/common_factor_rt.hpp calculates the greatest common divisor. ----------------------------------------------------------------------
Comment By: Daryle L. Walker (dlwalker) Date: 2006-11-04 16:27
Message: Logged In: YES user_id=551024 Fixed this by depreciating boost::gcd and lcm for the ones in boost::math (i.e. in "common_factor_rt.hpp"). This forces the requirement of std::numeric_limits compatibility for your integer type (otherwise you may get negative numbers during GCD/LCM for signed types). Your issue is only for a "long" that uses 2's complement and all its bit combinations, so there's a preprocessor-level check for that in the test code. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=307586&aid=1438626&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