Message361316
To be clear: the following is flawed as an accuracy test, because the *multiplication* by 1e9 introduces additional error.
# int/int: int.__truediv__(int)
>>> abs(t - int(t/10**9 * 1e9))
172
Try this instead, which uses the Fractions module to get the exact error. (The error is converted to a float before printing, for convenience, to show the approximate size of the errors.)
>>> from fractions import Fraction as F
>>> exact = F(t, 10**9)
>>> int_int = t / 10**9
>>> float_float = t / 1e9
>>> int_int_error = F(int_int) - exact
>>> float_float_error = F(float_float) - exact
>>> print(float(int_int_error))
8.85650634765625e-08
>>> print(float(float_float_error))
-1.49853515625e-07 |
|
Date |
User |
Action |
Args |
2020-02-03 17:57:54 | mark.dickinson | set | recipients:
+ mark.dickinson, lemburg, rhettinger, vstinner, larry, stutzbach, serhiy.storchaka, vxgmichel |
2020-02-03 17:57:54 | mark.dickinson | set | messageid: <1580752674.72.0.755478183049.issue39484@roundup.psfhosted.org> |
2020-02-03 17:57:54 | mark.dickinson | link | issue39484 messages |
2020-02-03 17:57:54 | mark.dickinson | create | |
|