[issue18739] math.log of a long returns a different value of math.log of an int
Tim Peters
report at bugs.python.org
Wed Aug 14 18:48:58 CEST 2013
Tim Peters added the comment:
Yup - 2.7 evaluates this in a less precise way, as
log(10L) = log(10./16 * 2**4) = log(0.625) + log(2)*4
>>> log(10L) == log(0.625) + log(2)*4
True
This patterns works well even for longs that are far too large to represent as a double; e.g.,
>>> log(1L << 50000)
34657.35902799726
which is evaluated internally as log(0.5) + log(2) * 50001:
>>> log(1L << 50000) == log(0.5) + log(2) * 50001
True
Python 3 is more careful, falling back to this pattern _only_ if converting the long to a double overflows. Of course 10L can be represented exactly as a double, so Python 3 evaluates it directly as log(float(10L)) = log(10.0). It's minor difference overall, but definitely visible ;-)
----------
nosy: +tim_one
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18739>
_______________________________________
More information about the Python-bugs-list
mailing list