# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1285830330 18000 # Node ID 604dfbaf50103a5f0c326be50464e7b9436f10a8 # Parent 54697b37d8bf16e97923fa534c66101eb360c1c5 Fix off-by-one and typo bugs in gcd diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2010-09-30 Jordi GutiƩrrez Hermoso + + * DLD-FUNCTIONS/gcd.cc (extended_gcd): Fix bug that didn't + distinguish the two output coefficients. + (Fgcd): Fix off-by-one bug and typo from copy-pasted code. + 2010-09-30 Jaroslav Hajek * oct-parse.yy (Fautoload): Replace Octave_map by octave_map. diff --git a/src/DLD-FUNCTIONS/gcd.cc b/src/DLD-FUNCTIONS/gcd.cc --- a/src/DLD-FUNCTIONS/gcd.cc +++ b/src/DLD-FUNCTIONS/gcd.cc @@ -75,7 +75,7 @@ ("gcd: all values must be integers"); double aa = fabs (a), bb = fabs (b); - double xx = 0, lx = 1, yy = 0, ly = 1; + double xx = 0, lx = 1, yy = 1, ly = 0; while (bb != 0) { double qq = floor (aa / bb); @@ -101,7 +101,7 @@ octave_int& x, octave_int& y) { T aa = a.abs ().value (), bb = b.abs ().value (); - T xx = 0, lx = 1, yy = 0, ly = 1; + T xx = 0, lx = 1, yy = 1, ly = 0; while (bb != 0) { T qq = aa / bb; @@ -350,10 +350,10 @@ for (int j = 2; j < nargin; j++) { octave_value x; - retval(0) = do_extended_gcd (retval(0), args(1), + retval(0) = do_extended_gcd (retval(0), args(j), x, retval(j+1)); for (int i = 0; i < j; i++) - retval(i).assign (octave_value::op_el_mul_eq, x); + retval(i+1).assign (octave_value::op_el_mul_eq, x); if (error_state) break; }