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
|