• Paul Eggert's avatar
    Fix rounding errors with float timestamps · af82a624
    Paul Eggert authored
    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.
    af82a624
timefns.c 58.9 KB