Boost logo

Boost :

From: helmut.zeisel_at_[hidden]
Date: 2001-07-04 15:10:59

I tested gcd from rational.hpp with my big_int class.
As a good citizen of the C++ community

I think, however, that it is not really necessary
to provide a swap function for the special case
of gcd, since the swap is undone in every other step.
Two steps per loop make the swap unnecessary.
I tried to use a slightly different version for gcd:

template<typename IntType>
IntType gcd_alternative(IntType n, IntType m)
    IntType zero(0);

    if (n < zero)
        n = -n;
    if (m < zero)
        m = -m;

      if(m == zero) return n;
      n %= m;
      if(n == zero) return m;
      m %= n;

For my specific big_int,
I get a performance gain of 15-20%.

How do you like this alternative version?


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