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 eryksun
Recipients eryksun, larry, lemburg, mark.dickinson, rhettinger, serhiy.storchaka, stutzbach, vstinner, vxgmichel
Date 2020-02-10.04:50:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1581310242.46.0.248495071154.issue39484@roundup.psfhosted.org>
In-reply-to
Content
A binary float has the form (-1)**sign * (1 + frac) * 2**exp, where sign is 0 or 1, frac is a rational value in the range [0, 1), and exp is a signed integer (but stored in non-negative, biased form). The smallest value of frac is epsilon, and the smallest increment for a given power of two is thus epsilon * 2**exp. To get exp for a given value, we have log2(abs(value)) == log2((1 + frac) * 2**exp) == log2(1 + frac) + log2(2**exp) == log2(1 + frac) + exp. Thus exp == log2(abs(value)) - log2(1 + frac). We know log2(1 + frac) is in the range [0, 1), so exp is the floor of the log2 result. For a binary64, epsilon is 2**-52, but we can leave it up to the floating point implementation by using sys.float_info:

    >>> exp = math.floor(math.log2(time.time()))
    >>> sys.float_info.epsilon * 2**exp
    2.384185791015625e-07

Anyway, it's better to leave it to the experts:

    >>> t = time.time()
    >>> math.nextafter(t, math.inf) - t
    2.384185791015625e-07
History
Date User Action Args
2020-02-10 04:50:42eryksunsetrecipients: + eryksun, lemburg, rhettinger, mark.dickinson, vstinner, larry, stutzbach, serhiy.storchaka, vxgmichel
2020-02-10 04:50:42eryksunsetmessageid: <1581310242.46.0.248495071154.issue39484@roundup.psfhosted.org>
2020-02-10 04:50:42eryksunlinkissue39484 messages
2020-02-10 04:50:42eryksuncreate