]> git.eshelyaron.com Git - emacs.git/commit
Fix rounding errors with float timestamps
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 15 Aug 2019 17:40:11 +0000 (10:40 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 15 Aug 2019 17:41:40 +0000 (10:41 -0700)
commitaf82a6248ce77f1b14f89cfee677250ff024c2c4
treef93ac7f0f37c16ad1cbf1292d3427d7357ac3e52
parentf6ae51c71d69b4d1a02fc8f6536f3f8cc0dc1009
Fix rounding errors with float timestamps

When converting from float to (TICKS . HZ) form, do the
conversion exactly.  When converting from (TICKS . HZ) form to
float, round to even precisely.  This way, successfully
converting a float to (TICKS . HZ) and back yields a value
numerically equal to the original.
* src/timefns.c (flt_radix_power_size): New constant.
(flt_radix_power): New static var.
(decode_float_time): Convert the exact numeric value rather
than guessing TIMESPEC_HZ resolution.
(s_ns_to_double): Remove; no longer needed.
(frac_to_double): New function.
(decode_ticks_hz): It is now the caller’s responsibility to
pass a valid TICKS and HZ.  All callers changed.
Use frac_to_double to round (TICKS . HZ) precisely.
(decode_time_components): When decoding nil, use
decode_ticks_hz since it rounds precisely.
(syms_of_timefns): Initialize flt_radix_power.
* test/src/timefns-tests.el (float-time-precision): New test.
src/timefns.c
test/src/timefns-tests.el