[issue45348] math.log(243, 3) value issue
Dennis Sweeney
report at bugs.python.org
Sat Oct 2 21:26:50 EDT 2021
Dennis Sweeney <sweeney.dennis650 at gmail.com> added the comment:
It turns out that the current implementation is already very good, within 1ulp in 99.85% of cases and perfect (as good as floats can get) in 65% of cases. So my thinking would be to leave the implementation as is.
#################################################
from decimal import Decimal as D, getcontext
from math import log, nextafter
from random import uniform
getcontext().prec = 200
N = 10_000
perfect = 0
good = 0
for i in range(N):
x, base = uniform(1, 10**6), uniform(2, 100)
d_result = float(D(x).ln() / D(base).ln())
f_result = log(x, base)
if d_result == f_result:
perfect += 1
good += 1
elif nextafter(d_result, f_result) == f_result:
good += 1
print(f"{perfect/N = }")
print(f"{good/N = }")
# results:
# perfect/N = 0.6503
# good/N = 0.9985
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45348>
_______________________________________
More information about the Python-bugs-list
mailing list