# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1188232556 25200
# Node ID 0c790861a323612e4ad24d872b403778d5572fed
# Parent  c0ce4368f56c18928f5e011cfd3264194f8e4ce9
Fix a bug Justin Walker reported with xgcd.

diff -r c0ce4368f56c -r 0c790861a323 sage/rings/arith.py
--- a/sage/rings/arith.py	Sun Aug 26 21:31:48 2007 -0700
+++ b/sage/rings/arith.py	Mon Aug 27 09:35:56 2007 -0700
@@ -1111,17 +1111,32 @@ def __GCD_list(v):
 
 def xgcd(a, b):
     """
-    Returns triple of integers (g,s,t) such that g = s*a+t*b =
-    gcd(a,b).
-    
+    Returns triple (g,s,t) such that g = s*a+t*b = gcd(a,b).
+
+    INPUT:
+        a, b -- integers or univariate polynomials (or any type
+                with an xgcd method).
+    OUTPUT:
+        g, s, t -- such that g = s*a + t*b
+
+    EXAMPLES:
         sage: xgcd(56, 44)
         (4, 4, -5)
         sage: 4*56 + (-5)*44
         4
-    """
-    if not isinstance(a, RingElement):
+        sage: xgcd(5/1, 7/1)
+        (1, 3, -2)
+        sage: x = polygen(QQ)
+        sage: xgcd(x^3 - 1, x^2 - 1)
+        (x - 1, 1, -x)
+    """
+    try:
+        return a.xgcd(b)
+    except AttributeError:
+        pass
+    if not isinstance(a, sage.rings.integer.Integer):
         a = integer_ring.ZZ(a)
-    return a.xgcd(b)
+    return a.xgcd(integer_ring.ZZ(b))
 
 XGCD = xgcd
 
