[PATCHv3 00/24] ILP32 support in ARM64
Paul Eggert
eggert@cs.ucla.edu
Tue Feb 17 22:17:00 GMT 2015
On 02/17/2015 10:38 AM, Zack Weinberg wrote:
> I expect the
> overwhelming majority of programs print tv_nsec by converting it to
> _double_ for ease of combination with tv_sec.
No, because that loses precision. The most common solution in portable
programs is to convert tv_nsec to 'long' (or to 'int' -- that's good
enough for POSIX) before printing. This works on both POSIX and x32
GNU/Linux. One needs to convert tv_sec anyway, and it's easy to convert
tv_nsec too. Something like this, say:
int
printf_timespec (struct timespec ts)
{
if ((time_t) -1 < 0)
return printf ("%jd.%.9d", (intmax_t) ts.tv_sec, (int) ts.tv_nsec);
else
return printf ("%ju.%.9d", (uintmax_t) ts.tv_sec, (int) ts.tv_nsec);
}
Typical GNU software already does this sort of thing.
More information about the Libc-alpha
mailing list