Commit 0da79aa8 authored by Paul Eggert's avatar Paul Eggert
Browse files

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.
parent f935bab8
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
......@@ -61,9 +61,7 @@ xtime_nonnegative_sec (xtime_t t)
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. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment