Mark Dickinson <dicki...@gmail.com> added the comment:
Ah, now I've looked at the script. There's an issue with using `random.random()` to create "small" values for testing, since its result is always an integer multiple of 2**-53. That means in particular that if x = random.random(), then 1 - x is always *exactly* representable (and 1 + x is also exactly representable approximately half of the time), so there's no loss of accuracy in the intermediate step of computing log(1 + x) if x = -random.random(). Here's what I get if I run your script exactly as it stands (Python 3.7.3, macOS 10.14.5) mirzakhani:Desktop mdickinson$ python test.py Counter({'equal': 51839, 'offset_log': 41988, 'regular_log': 6173}) Counter({'equal': 93727, 'regular_log': 6273}) But if I replace each `random.random()` call with `1e-3 * random.random()`, in order to test small values of `x`, here's what I get: mirzakhani:Desktop mdickinson$ python test.py Counter({'offset_log': 99945, 'equal': 55}) Counter({'offset_log': 99893, 'equal': 107}) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue37454> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com