This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients docs@python, mark.dickinson, rhettinger, tim.peters
Date 2019-07-01.07:18:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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
    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
    Counter({'offset_log': 99945, 'equal': 55})
    Counter({'offset_log': 99893, 'equal': 107})
Date User Action Args
2019-07-01 07:18:55mark.dickinsonsetrecipients: + mark.dickinson, tim.peters, rhettinger, docs@python
2019-07-01 07:18:55mark.dickinsonsetmessageid: <>
2019-07-01 07:18:55mark.dickinsonlinkissue37454 messages
2019-07-01 07:18:54mark.dickinsoncreate