pcp
[Top] [All Lists]

Re: [pcp] pcp updates - 2 big changes

To: Ken McDonell <kenj@xxxxxxxxxxxxxxxx>, pcp@xxxxxxxxxxx
Subject: Re: [pcp] pcp updates - 2 big changes
From: Mark Goodwin <mgoodwin@xxxxxxxxxx>
Date: Mon, 15 Sep 2014 11:02:01 +1000
Delivered-to: pcp@xxxxxxxxxxx
In-reply-to: <54160E99.4060607@xxxxxxxxxxxxxxxx>
References: <54160E99.4060607@xxxxxxxxxxxxxxxx>
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0
On 09/15/2014 07:54 AM, Ken McDonell wrote:
2. (more significantly) Following Mark's investigations of arithmetic errors ...

Thanks Ken, I didn't push my patch because after reading
tv.c more closely I realized there was a more substantial
audit and patch required, which you've now completed by the
looks of it.

Couple of comments on your new code, as below.

/*
 * convert a timeval to a double (units = seconds)
 */
double
__pmtimevalToReal(const struct timeval *val)
{
    return val->tv_sec + ((long double)val->tv_usec / (long double)1000000);
}
                          ^^^ cast isn't needed?, but doesn't hurt.

/*
 * convert double (units == seconds) to a timeval
 */
void
__pmtimevalFromReal(double secs, struct timeval *val)
{
    val->tv_sec = (time_t)secs;
val->tv_usec = (long)((long double)(secs - val->tv_sec) * (long double)1000000 + 0.5);
}

Just wondering how come you decided to add the half of one millionth
of a second here, to force rounding up. Doesn't the compiler automatically
round up appropriately, so this is redundant? Or did you find a corner
case where the rounding wasn't right? I assume the 0.5 doesn't need
an explicit long double cast (or the equivalent L suffix).

Cheers
-- Mark


<Prev in Thread] Current Thread [Next in Thread>