Some tweaks and fixes for Common::Rational
* Fix Common::gcd to work with negative input * This fixes a bug in Common::Rational's multiplication code * Add some more basic unit tests (including one which checks for the now fixed multiplication bug) * cleanup svn-id: r49064
This commit is contained in:
parent
c7fa1074fb
commit
00cd966f3d
3 changed files with 59 additions and 25 deletions
|
@ -227,6 +227,8 @@ void sort(T first, T last) {
|
|||
*/
|
||||
template<class T>
|
||||
T gcd(T a, T b) {
|
||||
if (a <= 0) a = -a;
|
||||
if (b <= 0) b = -b;
|
||||
while (a > 0) {
|
||||
T tmp = a;
|
||||
a = b % a;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue