tags:

views:

322

answers:

1

why doesn't it exist?

import math [x for x in dir(math) if 'log' in x] ['log', 'log10', 'log1p']

I know I can do log(x,2), but log2 is really common, so I'm kind of baffled.

Oh, it looks like it's only defined in C99, not C90, I guess that answers my question. Still seems kind of silly.

+7  A: 

I think you've answered your own question. :-) There's no log2(x) because you can do log(x, 2). As The Zen of Python (PEP 20) says, "There should be one-- and preferably only one --obvious way to do it."

That said, log2 was considered in Issue3366 (scroll down to the last 3 messages) which added several other C99 math functions to the math module for Python 2.7 and 3.2.

Daniel Stutzbach
That begs the question, why does `log10` exist?
Mark Ransom
log10 is C89, so it exists on all common platforms, including Windows. So it's trivial for Python to add a wrapper round it.
Mark Dickinson
Well, fair enough. I guess people like log10 enough to include it specially but not log2. It looks like it's actually in numpy, so that solves that.
nmaxwell