Message346969
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}) |
|
Date |
User |
Action |
Args |
2019-07-01 07:18:55 | mark.dickinson | set | recipients:
+ mark.dickinson, tim.peters, rhettinger, docs@python |
2019-07-01 07:18:55 | mark.dickinson | set | messageid: <1561965535.33.0.4802873053.issue37454@roundup.psfhosted.org> |
2019-07-01 07:18:55 | mark.dickinson | link | issue37454 messages |
2019-07-01 07:18:54 | mark.dickinson | create | |
|