]> granicus.if.org Git - python/commitdiff
Replace _nbits() with int.bit_length().
authorRaymond Hettinger <python@rcn.com>
Sat, 27 Nov 2010 08:09:40 +0000 (08:09 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 27 Nov 2010 08:09:40 +0000 (08:09 +0000)
Lib/decimal.py

index f379ee57ce0d8d44db941d088bc677e1aac6830a..24bd85b4935032d2ea06fced764b06b153998890 100644 (file)
@@ -5526,23 +5526,7 @@ def _normalize(op1, op2, prec = 0):
 
 ##### Integer arithmetic functions used by ln, log10, exp and __pow__ #####
 
-# This function from Tim Peters was taken from here:
-# http://mail.python.org/pipermail/python-list/1999-July/007758.html
-# The correction being in the function definition is for speed, and
-# the whole function is not resolved with math.log because of avoiding
-# the use of floats.
-def _nbits(n, correction = {
-        '0': 4, '1': 3, '2': 2, '3': 2,
-        '4': 1, '5': 1, '6': 1, '7': 1,
-        '8': 0, '9': 0, 'a': 0, 'b': 0,
-        'c': 0, 'd': 0, 'e': 0, 'f': 0}):
-    """Number of bits in binary representation of the positive integer n,
-    or 0 if n == 0.
-    """
-    if n < 0:
-        raise ValueError("The argument to _nbits should be nonnegative.")
-    hex_n = "%x" % n
-    return 4*len(hex_n) - correction[hex_n[0]]
+_nbits = int.bit_length
 
 def _sqrt_nearest(n, a):
     """Closest integer to the square root of the positive integer n.  a is