# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1174958655 25200
# Node ID 064c034bc5092d983c94f4197725201611be005b
# Parent  561d3ab71067df906b7cdbaed36fee35fb2bce0c
Fix bug in shifting by a non-integer.

diff -r 561d3ab71067 -r 064c034bc509 sage/rings/integer.pyx
--- a/sage/rings/integer.pyx	Mon Mar 26 16:48:32 2007 -0700
+++ b/sage/rings/integer.pyx	Mon Mar 26 18:24:15 2007 -0700
@@ -1689,9 +1689,21 @@ cdef class Integer(sage.structure.elemen
             128
             sage: int(32) << 2
             128
-        """
+            sage: 1 >> 2.5
+            Traceback (most recent call last):
+            ...
+            TypeError: unsupported operands for >>            
+        """
+        try:
+            if not PY_TYPE_CHECK(x, Integer):
+                x = Integer(x)
+            elif not PY_TYPE_CHECK(y, Integer):
+                y = Integer(y)
+            return (<Integer>x)._lshift(long(y))
+        except TypeError:
+            raise TypeError, "unsupported operands for <<"
         if PY_TYPE_CHECK(x, Integer) and isinstance(y, (Integer, int, long)):
-            return (<Integer>x)._lshift(long(y)) 
+            return (<Integer>x)._lshift(long(y))
         return bin_op(x, y, operator.lshift)
     
     cdef _rshift(Integer self, long int n):
@@ -1715,10 +1727,23 @@ cdef class Integer(sage.structure.elemen
             8
             sage: int(32) >> 2
             8
-        """
-        if PY_TYPE_CHECK(x, Integer) and isinstance(y, (Integer, int, long)):
+            sage: 1<< 2.5
+            Traceback (most recent call last):
+            ...
+            TypeError: unsupported operands for <<
+        """
+        try:
+            if not PY_TYPE_CHECK(x, Integer):
+                x = Integer(x)
+            elif not PY_TYPE_CHECK(y, Integer):
+                y = Integer(y)
             return (<Integer>x)._rshift(long(y))
-        return bin_op(x, y, operator.rshift)
+        except TypeError:
+            raise TypeError, "unsupported operands for >>"
+    
+        #if PY_TYPE_CHECK(x, Integer) and isinstance(y, (Integer, int, long)):
+        #    return (<Integer>x)._rshift(long(y))
+        #return bin_op(x, y, operator.rshift)
         
     cdef _and(Integer self, Integer other):
         cdef Integer x
diff -r 561d3ab71067 -r 064c034bc509 sage/rings/real_double.pyx
--- a/sage/rings/real_double.pyx	Mon Mar 26 16:48:32 2007 -0700
+++ b/sage/rings/real_double.pyx	Mon Mar 26 18:24:15 2007 -0700
@@ -510,13 +510,13 @@ cdef class RealDoubleElement(FieldElemen
         """
         LShifting a double is not supported; nor is lshifting a RealDoubleElement.    
         """
-        raise TypeError, "unsupported operand type(s) for <<: '%s' and '%s'"%(typeof(self), typeof(n))
+        raise TypeError, "unsupported operand type(s) for <<"
 
     def __rshift__(x, y):
         """
         RShifting a double is not supported; nor is rshifting a RealDoubleElement.
         """
-        raise TypeError, "unsupported operand type(s) for >>: '%s' and '%s'"%(typeof(self), typeof(n))
+        raise TypeError, "unsupported operand type(s) for >>"
     
     def multiplicative_order(self):
         if self == 1:
diff -r 561d3ab71067 -r 064c034bc509 sage/rings/real_mpfr.pyx
--- a/sage/rings/real_mpfr.pyx	Mon Mar 26 16:48:32 2007 -0700
+++ b/sage/rings/real_mpfr.pyx	Mon Mar 26 18:24:15 2007 -0700
@@ -995,10 +995,17 @@ cdef class RealNumber(sage.structure.ele
         EXAMPLES:
             sage: 1.0 << 32
             4294967296.00000
-        """
-        if isinstance(x, RealNumber) and isinstance(y, (int,long, Integer)):
-            return x._lshift_(y)
-        return sage.structure.coerce.bin_op(x, y, operator.lshift)
+            sage: 1.5 << 2.5
+            Traceback (most recent call last):
+            ...
+            TypeError: unsupported operands for <<
+        """
+        if not PY_TYPE_CHECK(x, RealNumber):
+            raise TypeError, "unsupported operands for <<"
+        try:
+            return x._lshift_(Integer(y))
+        except TypeError:
+            raise TypeError, "unsupported operands for <<"            
 
     def _rshift_(RealNumber self, n):
         if n > sys.maxint:
@@ -1013,10 +1020,18 @@ cdef class RealNumber(sage.structure.ele
         EXAMPLES:
             sage: 1024.0 >> 7
             8.00000000000000
-        """
-        if isinstance(x, RealNumber) and isinstance(y, (int,long,Integer)):
-            return x._rshift_(y)
-        return sage.structure.coerce.bin_op(x, y, operator.rshift)
+            sage: 1.5 >> 2.5
+            Traceback (most recent call last):
+            ...
+            TypeError: unsupported operands for >>            
+        """
+        if not PY_TYPE_CHECK(x, RealNumber):
+            raise TypeError, "unsupported operands for >>"
+        try:
+            return x._rshift_(Integer(y))
+        except TypeError:
+            raise TypeError, "unsupported operands for >>"
+        
     
     def multiplicative_order(self):
         if self == 1:
diff -r 561d3ab71067 -r 064c034bc509 sage/rings/real_qdrf.pyx
--- a/sage/rings/real_qdrf.pyx	Mon Mar 26 16:48:32 2007 -0700
+++ b/sage/rings/real_qdrf.pyx	Mon Mar 26 18:24:15 2007 -0700
@@ -446,13 +446,13 @@ cdef class QuadDoubleElement(FieldElemen
         """
         LShifting a quad double is not supported; nor is lshifting a RealDoubleElement.    
         """
-        raise TypeError, "unsupported operand type(s) for <<: '%s' and '%s'"%(typeof(self), typeof(n))
+        raise TypeError, "unsupported operand type(s) for <<"
 
     def __rshift__(x, y):
         """
         RShifting a quad double is not supported; nor is rshifting a RealDoubleElement.
         """
-        raise TypeError, "unsupported operand type(s) for >>: '%s' and '%s'"%(typeof(self), typeof(n))
+        raise TypeError, "unsupported operand type(s) for >>"
     
     def multiplicative_order(self):
         """
diff -r 561d3ab71067 -r 064c034bc509 sage/rings/ring.pyx
--- a/sage/rings/ring.pyx	Mon Mar 26 16:48:32 2007 -0700
+++ b/sage/rings/ring.pyx	Mon Mar 26 18:24:15 2007 -0700
@@ -841,7 +841,7 @@ def is_Field(x):
 
     EXAMPLES:    
     """
-    return isinstance(x, Field)
+    return bool(isinstance(x, Field))
 
 cdef class Field(PrincipalIdealDomain):
     """
