Ticket #11796: trac11796.patch

File trac11796.patch, 976 bytes (added by zimmerma, 11 years ago)
  • sage/rings/integer.pyx

    # HG changeset patch
    # User Paul Zimmermann <zimmerma@loria.fr>
    # Date 1315939654 -7200
    # Node ID 45f3541b63197b2acb4df64e68f1beec9b0b8b03
    # Parent  2a2abbcad325ccca9399981ceddf5897eb467e64
    ticket #11796: inconsistency between nbits and ndigits(base=2)
    
    diff -r 2a2abbcad325 -r 45f3541b6319 sage/rings/integer.pyx
    a b  
    11581158            9
    11591159            sage: 5.nbits()
    11601160            3
     1161            sage: 0.nbits() == len(0.bits()) == 0.ndigits(base=2)
     1162            True
    11611163            sage: 12345.nbits() == len(12345.binary())
    11621164            True
    11631165        """
    1164         return int(mpz_sizeinbase(self.value, 2))
     1166        # mpz_sizeinbase(0,2) always returns 1
     1167        if mpz_cmp_si(self.value,0) == 0:
     1168           return int(0)
     1169        else:
     1170           return int(mpz_sizeinbase(self.value, 2))
    11651171
    11661172    def trailing_zero_bits(self):
    11671173        """