[issue31980] Special case log(x, 2), log(x, 10) and pow(2, x)

Serhiy Storchaka report at bugs.python.org
Wed Nov 8 14:48:52 EST 2017


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

There is no two-argument libm `log`. Two-argument log(x, base) is implemented as log(x) / log(base). log(base) adds an error.

>>> import math
>>> math.log(2**31, 2)
31.000000000000004

Since two-argument log() doesn't correspond a C function, I think we are free to use more precise implementation.

We could correct also two-argument logarithms with other bases. For example:

def prec_log(x, y):
    a = math.log(x, y)
    return a + math.log(x / math.pow(y, a), y)

>>> math.log(3**20, 3)
19.999999999999996
>>> prec_log(3**20, 3)
20.0

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31980>
_______________________________________


More information about the Python-bugs-list mailing list