[issue3439] create a numbits() method for int and long types

Raymond Hettinger report at bugs.python.org
Tue Dec 16 13:47:13 CET 2008


Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:

Oops, forgot one part of the doc definition in the proposed additional
tests:

for x in range(-65000, 65000):
    k = x.numbits()
    assert k == len(bin(x).lstrip('-0b'))
    if x > 0:
        assert 2 ** (k-1) <= x < 2**k
        assert k == 1 + math.floor(math.log(x) / math.log(2))
    elif x == 0:
        assert k == 0
    else:
        assert k == (-x).numbits()

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3439>
_______________________________________


More information about the Python-bugs-list mailing list