Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db213a2

Browse files
committed
Replace _nbits() with int.bit_length().
1 parent 76338ec commit db213a2

1 file changed

Lines changed: 1 addition & 17 deletions

File tree

Lib/decimal.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5526,23 +5526,7 @@ def _normalize(op1, op2, prec = 0):
55265526

55275527
##### Integer arithmetic functions used by ln, log10, exp and __pow__ #####
55285528

5529-
# This function from Tim Peters was taken from here:
5530-
# http://mail.python.org/pipermail/python-list/1999-July/007758.html
5531-
# The correction being in the function definition is for speed, and
5532-
# the whole function is not resolved with math.log because of avoiding
5533-
# the use of floats.
5534-
def _nbits(n, correction = {
5535-
'0': 4, '1': 3, '2': 2, '3': 2,
5536-
'4': 1, '5': 1, '6': 1, '7': 1,
5537-
'8': 0, '9': 0, 'a': 0, 'b': 0,
5538-
'c': 0, 'd': 0, 'e': 0, 'f': 0}):
5539-
"""Number of bits in binary representation of the positive integer n,
5540-
or 0 if n == 0.
5541-
"""
5542-
if n < 0:
5543-
raise ValueError("The argument to _nbits should be nonnegative.")
5544-
hex_n = "%x" % n
5545-
return 4*len(hex_n) - correction[hex_n[0]]
5529+
_nbits = int.bit_length
55465530

55475531
def _sqrt_nearest(n, a):
55485532
"""Closest integer to the square root of the positive integer n. a is

0 commit comments

Comments
 (0)