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: [PATCH v2.2][BZ #12515] Improve precision of clock function


On Thu, Jun 13, 2013 at 12:57:18AM +0530, Siddhesh Poyarekar wrote:
> +  return (ts.tv_sec * CLOCKS_PER_SEC
> +	  + ts.tv_nsec / (1000000000 / CLOCKS_PER_SEC));
>  }

What is the value of using CLOCKS_PER_SEC? There is a hidden
assumption here that CLOCKS_PER_SEC evenly divides 1000000000. It's
true since the standard requires CLOCKS_PER_SEC to be 1000000, but in
that case, I would think it makes more sense either to write out the
/1000, or to add a comment that CLOCKS_PER_SEC is 1000000 and thus the
arithmetic is safe, rather than leaving the reader wondering why
you're doing suspicious integer arithmetic that would not be correct
for arbitrary values of the macro.

Rich


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