On Jul 8, 2013, at 5:19 PM, Alan Barrett wrote:
On Mon, 08 Jul 2013, Arthur David Olson wrote: [localtime.c]
--- 1514,1521 ---- } { register int_fast32_t seconds;
! seconds = tdays * SECSPERDAY + 0.5; tdays = seconds / SECSPERDAY; rem += seconds - tdays * SECSPERDAY; }
If time_t is an integer type, then that will multiply tdays * SECSPERDAY using time_t arithmetic, convert to double to add 0.5, then convert to int_fast32_t for the assignment. The conversion to and from double may lose precision, if double has less than 32 bits of mantissa precision (but that's unlikely).
Perhaps this will work without either a compiler warning or potential loss of precision:
seconds = tdays * SECSPERDAY + (time_t)0.5;
--apb (Alan Barrett)
I rather doubt it. Casting 0.5 to an integer type (as time_t is) ends up adding 0 or 1, but not 0.5. How about (tdays * SECSPERDAY * 2 + 1) / 2; ? paul