[issue17958] int(math.log(2**i, 2))

Mark Dickinson report at bugs.python.org
Sun May 12 12:33:04 CEST 2013


Mark Dickinson added the comment:

Sorry: this is not a bug, but a difficult-to-avoid consequence of floating-point imprecision: math.log(n, 2) is computed as log(n) / log(2), and each of the log computations and the division can introduce small errors.

For what it's worth, Python 3.3 has a `log2` function, which has accuracy that's a little bit better than math.log(n, 2), and gives the 'correct' answer exact powers of 2.

Closing as invalid.

----------
nosy: +mark.dickinson
resolution:  -> invalid
status: open -> closed

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


More information about the Python-bugs-list mailing list