◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
8 changes: 0 additions & 8 deletions Include/pymath.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,4 @@ 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 */
1 change: 1 addition & 0 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ raised for division by zero and mod by zero.
*/

#include "Python.h"
#include "pycore_dtoa.h"
#include "_math.h"

Expand Down
15 changes: 0 additions & 15 deletions Python/pymath.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,3 @@ round(double x)
return copysign(y, x);
}
#endif /* HAVE_ROUND */

static const unsigned int BitLengthTable[32] = {
0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
};

unsigned int _Py_bit_length(unsigned long d) {
unsigned int d_bits = 0;
while (d >= 32) {
d_bits += 6;
d >>= 6;
}
d_bits += BitLengthTable[d];
return d_bits;
}
Toggle all file notes Toggle all file annotations