This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCHv3 00/24] ILP32 support in ARM64


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]