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

2011-04-20 Thread Raymond Hettinger
New submission from Raymond Hettinger : The three most popular logarithm bases are 10, e, and 2. The math library has direct function calls for the first two but not the latter which is important in informatics. Since a direct call can use a custom algorithm or native hardware support (such

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

2011-04-20 Thread Jesús Cea Avión
Changes by Jesús Cea Avión : -- nosy: +jcea ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.

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

2011-04-21 Thread Mark Dickinson
Mark Dickinson 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 guarant

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

2011-04-21 Thread STINNER Victor
STINNER Victor 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?) No, we don't have to. Python has already a lot of optional functions, see for example the

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

2011-04-21 Thread Mark Dickinson
Mark Dickinson added the comment: > We can provide log2() only if the C library has this function. Big -1 from me: I'd hate to see working Python scripts written on Unix fail on Windows because of a missing log2. -- ___ Python tracker

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

2011-04-21 Thread Mark Dickinson
Mark Dickinson added the comment: Rather than reinventing the wheel, it may be worth looking at what numpy does here. -- ___ Python tracker ___

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

2011-04-21 Thread Mark Dickinson
Mark Dickinson added the comment: > it may be worth looking at what numpy does here. ... or it may not. NumPy just uses (approximation to 1/log(2)) * log(x) when log2 doesn't already exist. And indeed, on Windows: Python 2.7.1 |EPD 7.0-2 (64-bit)| (r271:86832, Dec 2 2010, 10:23:25) [MSC v

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

2011-04-25 Thread STINNER Victor
STINNER Victor 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

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

2011-04-25 Thread STINNER Victor
STINNER Victor added the comment: > 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? Hum. With a x86 and the right compiler optimization level, log(x)/log(2) in C can be more accurate than log(x)/log(2) in Python, bec

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

2011-05-01 Thread STINNER Victor
STINNER Victor added the comment: Oh... math.log() has an optional second argument: base. math.log(x, 2). But it is equivalent as math.log(x) / math.log(2) in Python. math.log(x, 2) is implemented as: num=math.log(x) den=math.log(2) return num / den where num and den are Python floats (6

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

2011-05-02 Thread Mark Dickinson
Mark Dickinson added the comment: Here's a patch implementing log2. Still to do: use the system log2 where available. -- keywords: +patch Added file: http://bugs.python.org/file21861/issue11888.patch ___ Python tracker

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

2011-05-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: Wow Mark, that is really nice work. Thanks. -- ___ Python tracker ___ ___ Python-bugs-list mail

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

2011-05-05 Thread STINNER Victor
STINNER Victor added the comment: Updated patch to use the system log2() if it is available. The test pass with the system log2() on Linux (Debian Sid, eglibc 2.11.2). -- Added file: http://bugs.python.org/file21897/issue11888-2.patch ___ Python tra

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

2011-05-06 Thread Mark Dickinson
Mark Dickinson added the comment: Thanks, Victor. I suspect we're going to need to be a bit more careful, though: when the extra tests were added for math.log, it turned out that it had all sorts of strange special-case behaviour on various platforms. So I suspect that even on platforms tha

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

2011-05-07 Thread STINNER Victor
STINNER Victor added the comment: > Thanks, Victor. I suspect we're going to need to be a bit more > careful, though: when the extra tests were added for math.log, it > turned out that it had all sorts of strange special-case behaviour on > various platforms. > > So I suspect that even on pla

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

2011-05-07 Thread STINNER Victor
STINNER Victor added the comment: (Oh, I hit the wrong keyboard shortcut and sent my email too fast) You can commit issue11888.patch first if you would like to test it. In this case, here is a patch to use system log2(), patch to apply *after* issue11888.patch. It only uses log2() if x > 0.0.

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

2011-05-07 Thread STINNER Victor
Changes by STINNER Victor : Removed file: http://bugs.python.org/file21897/issue11888-2.patch ___ Python tracker ___ ___ Python-bugs-list mail

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

2011-05-07 Thread STINNER Victor
STINNER Victor added the comment: By the way, issue11888.patch is just fine: you can commit it. I like your frexp "trick" to improve the accuracy. -- ___ Python tracker ___ ___

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

2011-05-08 Thread Roundup Robot
Roundup Robot added the comment: New changeset 6d1cbfcee45a by Victor Stinner in branch 'default': Issue #11888: Add log2 function to math module. Patch written by Mark http://hg.python.org/cpython/rev/6d1cbfcee45a -- nosy: +python-dev ___ Python tra

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

2011-05-09 Thread Mark Dickinson
Mark Dickinson added the comment: Thanks, Victor. You caught me by surprise a bit: I had some more minor changes to that patch pending, so I've committed those separately. Any news from the buildbots? -- ___ Python tracker

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

2011-05-09 Thread STINNER Victor
STINNER Victor added the comment: > Thanks, Victor. You caught me by surprise a bit Oh, I thought that the patch was ready to be commited. > I had some more minor changes to that patch pending, > so I've committed those separately. You should add "Issue #11888: " prefix to your commit messag

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

2011-05-09 Thread STINNER Victor
STINNER Victor added the comment: > we have to wait 12 hours or maybe one day to wait for all buildbots Oh, it's faster than expected: test_math passed on FreeBSD 6.4 3.x buildbot. I was waiting for this one because it's an old OS and many tests fail on this buildbot (because it's old but als

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

2011-05-09 Thread Roundup Robot
Roundup Robot added the comment: New changeset 565f43f6bed4 by Victor Stinner in branch 'default': Issue #11888: Use system log2() when available http://hg.python.org/cpython/rev/565f43f6bed4 -- ___ Python tracker

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

2011-05-09 Thread STINNER Victor
STINNER Victor added the comment: Issue #11888: Use system log2() when available http://hg.python.org/cpython/rev/565f43f6bed4 "I expect the system libc to use more accurate functions than Python." You know what? Mac OS X log2 is less accurate than Python log2! A log2 test failed on "x86 Tige

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

2011-05-09 Thread Mark Dickinson
Mark Dickinson added the comment: > You know what? Mac OS X log2 is less accurate than Python log2! That doesn't surprise me much. Though it's probably still true that log2 from OS X is more accurate than our log2 for some other values. It's just that getting the answer wrong for a power of

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

2011-05-09 Thread Mark Dickinson
Mark Dickinson added the comment: One other thought: we should check that it's not pow that's at fault here, rather than log2. The test uses math.log2(2.0**n). It would probably be better off using math.log2(ldexp(1.0, n)), or similar: the libm pow operation is also notorious for inaccura

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

2011-05-09 Thread STINNER Victor
STINNER Victor added the comment: > we should check that it's not pow that's at fault here Some tests on Mac OS X Tiger: >>> (2.0 ** -255).hex() '0x1.0p-255' => pow is correct >>> import ctypes; import ctypes.util, math >>> libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library(

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

2011-05-09 Thread Mark Dickinson
Mark Dickinson added the comment: Okay, thanks. We should still be using ldexp rather than 2.0**... in the tests, though; I've fixed this, and also fixed the incorrect (too small) range for those tests, so that all representable powers of 2 are now covered. -- _

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

2011-05-09 Thread Mark Dickinson
Mark Dickinson added the comment: Grr. Got the issue number wrong in the commit message; see msg135584. New changeset 1f23d63b578c by Mark Dickinson in branch 'default': Issue #11188: In log2 tests, create powers of 2 using ldexp(1, n) instead of the less reliable 2.0**n. http://hg.python.o

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

2011-05-10 Thread Roumen Petrov
Roumen Petrov added the comment: Why configure script check two times for log2 function ? -- nosy: +rpetrov ___ Python tracker ___ __

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

2011-05-10 Thread Roundup Robot
Roundup Robot added the comment: New changeset d3f9895e2e19 by Mark Dickinson in branch 'default': Issue #11888: remove duplicate check for log2 in configure.in. http://hg.python.org/cpython/rev/d3f9895e2e19 -- ___ Python tracker

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

2011-05-10 Thread Mark Dickinson
Mark Dickinson added the comment: Thanks, Roumen. Fixed. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: h

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

2011-05-10 Thread Mark Dickinson
Mark Dickinson added the comment: Victor, what do you think about simply #undefining HAVE_LOG2 on Tiger (e.g. in pyport.h), so that the fallback log2 version is used there instead of the system version? Does anyone know the appropriate preprocessor check for OS X <= 10.4? I can get as far a

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

2011-05-10 Thread Roundup Robot
Roundup Robot added the comment: New changeset 34871c3072c9 by Victor Stinner in branch 'default': Issue #11888: skip some log2 tests on Mac OS X Tiger http://hg.python.org/cpython/rev/34871c3072c9 -- ___ Python tracker

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

2011-05-10 Thread STINNER Victor
STINNER Victor added the comment: > New changeset 34871c3072c9 by Victor Stinner in branch 'default': > Issue #11888: skip some log2 tests on Mac OS X Tiger Oh... I realized that the test doesn't fail on Mac OS X Tiger PPC, only on Mac OS X Tiger x86. But I am too lazy to patch the test. Or sh

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

2011-05-11 Thread STINNER Victor
STINNER Victor added the comment: > I wait for the following build to close this issue. > http://www.python.org/dev/buildbot/all/builders/x86%20Tiger%203.x/builds/2507 Oh, it's the wrong build. The correct build is: http://www.python.org/dev/buildbot/all/builders/x86%20Tiger%203.x/builds/2508

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

2011-05-12 Thread Mark Dickinson
Mark Dickinson added the comment: Thanks, Victor. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://ma