summaryrefslogtreecommitdiffstats
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-11-27 08:09:40 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-11-27 08:09:40 (GMT)
commitdb213a297d5b7f4728c540b33f5e2a25b0596b23 (patch)
tree274b02f6159b68ce1ab55cd8f742dd5dc5431032 /Lib/decimal.py
parent76338ec37d823ffc490c3dce4e442b9d99691128 (diff)
downloadcpython-db213a297d5b7f4728c540b33f5e2a25b0596b23.zip
cpython-db213a297d5b7f4728c540b33f5e2a25b0596b23.tar.gz
cpython-db213a297d5b7f4728c540b33f5e2a25b0596b23.tar.bz2
Replace _nbits() with int.bit_length().
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r--Lib/decimal.py18
1 files changed, 1 insertions, 17 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index f379ee5..24bd85b 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -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