https://github.com/epiqc/ScaffCC
Raw File
Tip revision: 9d2cca71cf54ddfebda26e247d82ae7b71d9e03c authored by Pranav Gokhale on 30 June 2018, 18:56:21 UTC
Fix OpenQASM output formatting of Rx and Ry
Tip revision: 9d2cca7
gcd.c
// Extended Euclidean algorithm
//
// It's assumed inputs a and b are both positive
//
// We return gcd and set ap and bp to the corresponding integer
// coefficients such that gcd(a,b) = a*ap + b*bp.  Note that one of ap or bp
// will necessarily be negative
//
rkqc gcd(int a, int b, int *ap, int *bp)
{
  int x = 0;
  int y = 1;
  int lx = 1;
  int ly = 0;
  int q, t;
  
  // the so-called "iterative method"; this avoids recursion
  //
  while (b != 0)
  {
    q = a / b;

    t = a % b;  a = b;  b = t;

    t = lx - q*x;  lx = p;  x = t;
    t = ly - q*y;  ly = p;  y = t;
  }

  *ap = x;
  *bp = y;

  return a;
}
back to top