Commit 59d7bfbb authored by Morten Welinder's avatar Morten Welinder

Fix GCD.

parent 26184230
1999-06-08 David Chan <dpc29@hermes.cam.ac.uk>
* src/fn-math.c (gcd): Correct.
1999-06-08 Morten Welinder <terra@diku.dk>
* src/file.c (workbook_read): Temporarily switch to "C" locale
......
1999-06-08 David Chan <dpc29@hermes.cam.ac.uk>
* src/fn-math.c (gcd): Correct.
1999-06-08 Morten Welinder <terra@diku.dk>
* src/file.c (workbook_read): Temporarily switch to "C" locale
......
1999-06-08 David Chan <dpc29@hermes.cam.ac.uk>
* src/fn-math.c (gcd): Correct.
1999-06-08 Morten Welinder <terra@diku.dk>
* src/file.c (workbook_read): Temporarily switch to "C" locale
......
1999-06-08 David Chan <dpc29@hermes.cam.ac.uk>
* src/fn-math.c (gcd): Correct.
1999-06-08 Morten Welinder <terra@diku.dk>
* src/file.c (workbook_read): Temporarily switch to "C" locale
......
......@@ -37,30 +37,19 @@ static char *help_ = {
#endif
static int
gcd(int a, int b)
gcd (int a, int b)
{
int ri, ri_1, ri_2, qi;
/* Euclid's Algorithm. Assumes non-negative numbers. */
if (b == 0)
return a;
while (b != 0) {
int r;
qi = a/b;
ri_2 = a - qi*b;
if (ri_2 == 0)
return 1;
qi = b/ri_2;
ri = ri_1 = b - qi*ri_2;
while (ri > 0) {
qi = ri_2/ri_1;
ri = ri_2 - qi*ri_1;
ri_2 = ri_1;
ri_1 = ri;
r = a - (a / b) * b; /* r = remainder from
* dividing a by b */
a = b;
b = r;
}
return ri_2;
return a;
}
......
......@@ -37,30 +37,19 @@ static char *help_ = {
#endif
static int
gcd(int a, int b)
gcd (int a, int b)
{
int ri, ri_1, ri_2, qi;
/* Euclid's Algorithm. Assumes non-negative numbers. */
if (b == 0)
return a;
while (b != 0) {
int r;
qi = a/b;
ri_2 = a - qi*b;
if (ri_2 == 0)
return 1;
qi = b/ri_2;
ri = ri_1 = b - qi*ri_2;
while (ri > 0) {
qi = ri_2/ri_1;
ri = ri_2 - qi*ri_1;
ri_2 = ri_1;
ri_1 = ri;
r = a - (a / b) * b; /* r = remainder from
* dividing a by b */
a = b;
b = r;
}
return ri_2;
return a;
}
......
......@@ -37,30 +37,19 @@ static char *help_ = {
#endif
static int
gcd(int a, int b)
gcd (int a, int b)
{
int ri, ri_1, ri_2, qi;
/* Euclid's Algorithm. Assumes non-negative numbers. */
if (b == 0)
return a;
while (b != 0) {
int r;
qi = a/b;
ri_2 = a - qi*b;
if (ri_2 == 0)
return 1;
qi = b/ri_2;
ri = ri_1 = b - qi*ri_2;
while (ri > 0) {
qi = ri_2/ri_1;
ri = ri_2 - qi*ri_1;
ri_2 = ri_1;
ri_1 = ri;
r = a - (a / b) * b; /* r = remainder from
* dividing a by b */
a = b;
b = r;
}
return ri_2;
return a;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment