Dennis Sweeney <sweeney.dennis...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue45348>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to