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][BZ #12515] Improve precision of clock function


On Tue, 2013-05-21 at 13:07 -0700, Paul Eggert wrote:
> On 05/21/13 10:00, Steven Munroe wrote:
> 
> >>> > > 	return (ts.tv_sec * CLOCKS_PER_SEC
> >>> > > 		+ ts.tv_nsec / (1000000000 / CLOCKS_PER_SEC));
> 
> > That will cause its own round error problems, so need to cast to long
> > long for multiply and divide to avoid this.
> 
> I don't see any rounding error here -- can you give an example?
> Note that 1000000000 % CLOCKS_PER_SEC is guaranteed to be zero,
> which means it's safe to rewrite (x*1000000000)/CLOCKS_PER_SEC
> to x/(1000000000/CLOCKS_PER_SEC).
> 
> If that isn't clear, perhaps we can prepend a line like the
> following, to make it clear:
> 
>    static_assert (1000000000 % CLOCKS_PER_SEC == 0);
> 

That assume that __clock_gettime (CLOCK_REALTIME,) and CLOCKS_PER_SEC
are multiples of 10. 

"Although the value of CLOCKS_PER_SEC is required to be 1 million on all
XSI-conformant systems, it may be variable on other systems, and it
should not be assumed that CLOCKS_PER_SEC is a compile-time constant."


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