This routine computes the element-wise gcd and
coefficients s and t such that a*t + b*s = d. In other words, if
x = extended.gcd(a,b)
, then x$a*x$t + x$b*x$s == x$gcd
The Wikipedia page, from which this algorithm was stolen, has the
following statement, 'The quotients of a and b by their greatest common divisor,
which are output, may have an incorrect sign. This is easy to correct at the end
of the computation, but has not been done here for simplifying the code.'
I have absolutely no
idea what that means, but include it as a warning. For purposes of
SDraw
, elements of a and b are always positive, and I have never
observed "incorrect signs". But, there may be some pathological cases
where "incorrect signs" occur, and the user should "correct" for this.
This routine does check that the output gcd is
positive, and corrects this and the signs of s and t if so.