bpo-31031: Unify duplicate bits_in_digit and bit_length (GH-2866)

Add _Py_bit_length() to unify duplicate bits_in_digit() and bit_length().
This commit is contained in:
Niklas Fiekas 2020-01-16 15:09:19 +01:00 committed by Victor Stinner
parent 4691a2f2a2
commit c5b79003f5
4 changed files with 35 additions and 54 deletions

View file

@ -227,4 +227,12 @@ PyAPI_FUNC(void) _Py_set_387controlword(unsigned short);
* behavior. */
#define _Py_InIntegralTypeRange(type, v) (_Py_IntegralTypeMin(type) <= v && v <= _Py_IntegralTypeMax(type))
/* Return the smallest integer k such that n < 2**k, or 0 if n == 0.
* Equivalent to floor(log2(x))+1. Also equivalent to: bitwidth_of_type -
* count_leading_zero_bits(x)
*/
#ifndef Py_LIMITED_API
PyAPI_FUNC(unsigned int) _Py_bit_length(unsigned long d);
#endif
#endif /* Py_PYMATH_H */