Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2019-12/msg00192.html
* lib/xtime.h (xtime_sec): Simplify calculation and correct bug
with negative rounding. Common platforms can compute / and % with
a single instruction, so the simplified code should be shorter and
faster on these platforms anyway.
+2019-12-22 Paul Eggert <eggert@cs.ucla.edu>
+
+ gethrxtime: fix rounding bug with negative args
+ Problem reported by Bruno Haible in:
+ https://lists.gnu.org/r/bug-gnulib/2019-12/msg00192.html
+ * lib/xtime.h (xtime_sec): Simplify calculation and correct bug
+ with negative rounding. Common platforms can compute / and % with
+ a single instruction, so the simplified code should be shorter and
+ faster on these platforms anyway.
+
2019-12-22 Bruno Haible <bruno@clisp.org>
gethrxtime: remove incorrect overflow detection
XTIME_INLINE xtime_t
xtime_sec (xtime_t t)
{
- return (t < 0
- ? (t + XTIME_PRECISION - 1) / XTIME_PRECISION - 1
- : xtime_nonnegative_sec (t));
+ return t / XTIME_PRECISION - (t % XTIME_PRECISION < 0);
}
/* Return the number of nanoseconds in T, which must be nonnegative. */