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

STINNER Victor report at bugs.python.org
Tue Apr 26 01:39:42 CEST 2011

STINNER Victor <victor.stinner at haypocalc.com> added the comment:

> 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?)

Can't we simply use (approximation to 1/log(2)) * log(x)? Is it worse than reimplementing it using log(x)/log(2) in Python?

> That implementation should, ideally: ...

Because some platforms are less accurate, you prefer to not provide a more accurate function when log2() is available? Can't we start with something simple and improve it later?

It can be documented than the Python log2 function may be the same than log(x)/log(2) if the platform/CPU doesn't provide a C log2 function.


"... And indeed, on Windows ...

>>> numpy.log2(8.0)

Oh. Python is better on Linux:

Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.log(8) / math.log(2)


Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list