Ticket #5759: divides.patch

File divides.patch, 876 bytes (added by kkilger, 14 years ago)
  • sage/structure/element.pyx

    # HG changeset patch
    # User Kilian Kilger <kilian@nihilnovi.de>
    # Date 1239486731 -7200
    # Node ID c89e7b89e2002a4345bbf42b1f7101d04ad7a8b0
    # Parent  71536f6f921082ad6a837f1a1149c7ef5c5f308e
    Fix generic "divides" function.
      1. try first to coerce
      2. check for division by zero!
    
    diff -r 71536f6f9210 -r c89e7b89e200 sage/structure/element.pyx
    a b  
    13721372            sage: (x^2+2).divides(x)
    13731373            False
    13741374        """
    1375         return (x % self) == 0
     1375
     1376        x2 = self._parent._coerce_c(x)
     1377        if x2 == self:
     1378            return True
     1379        else:
     1380            try:
     1381                return (x2 % self) == 0
     1382            except ZeroDivisionError:
     1383                return False   
    13761384   
    13771385    def mod(self, I):
    13781386        r"""