Commits

Mark Dickinson committed 43bc723

Remove unneeded _bit_length function; use int.bit_length instead.

Comments (0)

Files changed (1)

bigfloat_cython/bigfloat/core.py

 PRECISION_MIN = mpfr.MPFR_PREC_MIN
 PRECISION_MAX = mpfr.MPFR_PREC_MAX
 
-_bit_length_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,
-    }
-
-
-def _bit_length(n):
-    """Bit length of an integer"""
-    hex_n = '%x' % _builtin_abs(n)
-    return 4 * len(hex_n) - _bit_length_correction[hex_n[0]]
-
 
 def _format_finite(negative, digits, dot_pos):
     """Given a (possibly empty) string of digits and an integer
             if isinstance(value, float):
                 precision = _builtin_max(DBL_PRECISION, PRECISION_MIN)
             elif isinstance(value, int):
-                precision = _builtin_max(_bit_length(value), PRECISION_MIN)
+                precision = _builtin_max(value.bit_length(), PRECISION_MIN)
             elif isinstance(value, BigFloat):
                 precision = value.precision
             else: