[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug in xtime.h
From: |
Akim Demaille |
Subject: |
Re: bug in xtime.h |
Date: |
Wed, 25 Dec 2019 18:28:24 +0100 |
Hi friends,
> Le 22 déc. 2019 à 21:48, Paul Eggert <address@hidden> a écrit :
>
> On 12/22/19 3:31 AM, Bruno Haible wrote:
>
>> diff --git a/lib/xtime.h b/lib/xtime.h
>> index 77f1c30..5e0ae89 100644
>> --- a/lib/xtime.h
>> +++ b/lib/xtime.h
>> @@ -42,12 +42,13 @@ extern "C" {
>> XTIME_INLINE xtime_t
>> xtime_make (xtime_t s, long int ns)
>> {
>> - const long int giga = 1000 * 1000 * 1000;
>> - s += ns / giga;
>> - ns %= giga;
>> return XTIME_PRECISION * s + ns;
>> }
>
> Akim put in that code in October 2018, but I can't see the need for it
> either. I
> installed the first attached patch to revert that, and am cc'ing this to Akim
> to
> see why it might be needed. If it is needed, we'll need to complicate the
> overflow suppression a bit.
Well, when I installed it (b159aa5da7e1aa7abeb2f77ba644aa164d25a46d), the diff
looked like this:
> /* Return an extended time value that contains S seconds and NS
> - nanoseconds, without any overflow checking. */
> + nanoseconds. */
> XTIME_INLINE xtime_t
> xtime_make (xtime_t s, long int ns)
> {
> + const long int giga = 1000 * 1000 * 1000;
> + s += ns / giga;
> + ns %= giga;
> if (XTIME_PRECISION == 1)
> return s;
> else
> return XTIME_PRECISION * s + ns;
> }
So the first case (one-second precision) was incorrect.
The commit Bruno refers to (xtime: Assume that the compiler supports 'long
long') is indeed about that:
> commit 896daf273035e889c50dc5b33e74b5fb891851bc
> Author: Bruno Haible <address@hidden>
> Date: Sun Dec 22 09:46:46 2019 +0100
>
> gethrxtime: Assume that the compiler supports 'long long'.
>
> * lib/xtime.h (xtime_t): Define to 'long long int' always.
> (XTIME_PRECISION): Define to 1000000000 always.
>
> @@ -57,10 +45,7 @@ xtime_make (xtime_t s, long int ns)
> const long int giga = 1000 * 1000 * 1000;
> s += ns / giga;
> ns %= giga;
> - if (XTIME_PRECISION == 1)
> - return s;
> - else
> - return XTIME_PRECISION * s + ns;
> + return XTIME_PRECISION * s + ns;
> }
Merry xtime!
- bug in xtime.h, Bruno Haible, 2019/12/22
- Re: bug in xtime.h, Paul Eggert, 2019/12/22
- Re: bug in xtime.h, Bruno Haible, 2019/12/22
- Re: bug in xtime.h, Bruno Haible, 2019/12/23
- Re: bug in xtime.h, Paul Eggert, 2019/12/23
- Re: bug in xtime.h, Bruno Haible, 2019/12/23
- Re: bug in xtime.h, Paul Eggert, 2019/12/24
- Re: bug in xtime.h, Bruno Haible, 2019/12/24
- Re: bug in xtime.h, Paul Eggert, 2019/12/24
Re: bug in xtime.h,
Akim Demaille <=