Skip to content

Commit 9b6a151

Browse files
Remove ilog2().
1 parent 3299bf7 commit 9b6a151

File tree

4 files changed

+1
-78
lines changed

4 files changed

+1
-78
lines changed

Doc/library/intmath.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,6 @@ integers.
4949
returns ``0``.
5050

5151

52-
.. function:: ilog2(n)
53-
54-
Return the integer base 2 logarithm of the positive integer *n*. This is the
55-
floor of the exact base 2 logarithm root of *n*, or equivalently the
56-
greatest integer *k* such that
57-
2\ :sup:`k` |nbsp| ≤ |nbsp| *n* |nbsp| < |nbsp| 2\ :sup:`k+1`.
58-
59-
It is equivalent to ``n.bit_length() - 1`` for positive *n*.
60-
61-
6252
.. function:: isqrt(n)
6353

6454
Return the integer square root of the nonnegative integer *n*. This is the

Lib/test/test_intmath.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,6 @@ def test_lcm(self):
200200
self.assertRaises(TypeError, lcm, 120, 0, 84.0)
201201
self.assertEqual(lcm(MyIndexable(120), MyIndexable(84)), 840)
202202

203-
def test_ilog2(self):
204-
ilog2 = self.module.ilog2
205-
for value in range(1, 1000):
206-
k = ilog2(value)
207-
self.assertLessEqual(2**k, value)
208-
self.assertLess(value, 2**(k+1))
209-
self.assertRaises(ValueError, ilog2, 0)
210-
self.assertRaises(ValueError, ilog2, -1)
211-
self.assertRaises(ValueError, ilog2, -2**1000)
212-
213-
self.assertIntEqual(ilog2(True), 0)
214-
self.assertIntEqual(ilog2(IntSubclass(5)), 2)
215-
self.assertIntEqual(ilog2(MyIndexable(5)), 2)
216-
217-
self.assertRaises(TypeError, ilog2, 5.0)
218-
self.assertRaises(TypeError, ilog2, Decimal('5'))
219-
self.assertRaises(TypeError, ilog2, Fraction(5, 1))
220-
self.assertRaises(TypeError, ilog2, '5')
221-
222203
def test_isqrt(self):
223204
isqrt = self.module.isqrt
224205
# Test a variety of inputs, large and small.
@@ -405,7 +386,6 @@ def test_comb(self):
405386

406387
class MathTests(IntMathTests):
407388
import math as module
408-
test_ilog2 = None
409389

410390

411391
if __name__ == '__main__':

Modules/clinic/intmathmodule.c.h

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/intmathmodule.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -151,43 +151,6 @@ intmath_lcm_impl(PyObject *module, PyObject * const *args,
151151
}
152152

153153

154-
/*[clinic input]
155-
intmath.ilog2
156-
157-
n: object
158-
/
159-
160-
Return the integer part of the base 2 logarithm of the input.
161-
[clinic start generated code]*/
162-
163-
static PyObject *
164-
intmath_ilog2(PyObject *module, PyObject *n)
165-
/*[clinic end generated code: output=5cd0b0553370e109 input=bf17dd4e720e922e]*/
166-
{
167-
int64_t bits;
168-
169-
n = PyNumber_Index(n);
170-
if (n == NULL) {
171-
return NULL;
172-
}
173-
174-
if (!_PyLong_IsPositive((PyLongObject *)n)) {
175-
PyErr_SetString(
176-
PyExc_ValueError,
177-
"ilog2() argument must be positive");
178-
Py_DECREF(n);
179-
return NULL;
180-
}
181-
182-
bits = _PyLong_NumBits(n);
183-
Py_DECREF(n);
184-
if (bits == -1) {
185-
return NULL;
186-
}
187-
return PyLong_FromInt64(bits - 1);
188-
}
189-
190-
191154
/* Integer square root
192155
193156
Given a nonnegative integer `n`, we want to compute the largest integer
@@ -1270,7 +1233,6 @@ static PyMethodDef intmath_methods[] = {
12701233
INTMATH_COMB_METHODDEF
12711234
INTMATH_FACTORIAL_METHODDEF
12721235
INTMATH_GCD_METHODDEF
1273-
INTMATH_ILOG2_METHODDEF
12741236
INTMATH_ISQRT_METHODDEF
12751237
INTMATH_LCM_METHODDEF
12761238
INTMATH_PERM_METHODDEF

0 commit comments

Comments
 (0)