[issue11888] Add C99's log2() function to the math library

Mark Dickinson report at bugs.python.org
Thu Apr 21 10:46:02 CEST 2011


Mark Dickinson <dickinsm at gmail.com> added the comment:

See also issue 3724.

I'm -0 on this:  between log(x, 2) and int.bit_length, there's not much need for log2.  log(x, 2) should be plenty accurate enough for most numerical needs;  the exception is when you're taking log base 2 of an integer and need a guarantee of exact results for powers of 2, and int.bit_length generally solves that problem.

The main issue is that we'd have to provide (and maintain) our own implementation of log2 for Windows (and other OSs that don't have all the C99 support.  Solaris?)  That implementation should, ideally:

 - provide exact values for powers of 2, and
 - be monotonic.

and that's not trivial.  As Raymond points out, on x86 / x64 we might be able to use inline assembly directly;  that would probably cover us for Windows.

----------

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


More information about the Python-bugs-list mailing list