tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Typo(s) in sys/time.h ?
On Thu, Jan 05, 2017 at 04:31:12PM +0000, Taylor R Campbell wrote:
> Date: Thu, 5 Jan 2017 11:58:46 +0800 (PHT)
> From: Paul Goyette <paul%whooppee.com@localhost>
>
> I suspect we should have a left shift here, rather than a right shift:
>
> bt.frac = (((ms % 1000U) << 32)/1000U) >> 32;
>
> They should both be left shifts. The point of the exercise is to
> reduce ms to the range [0, 999) as a fraction of a second, and then to
> convert a number of milliseconds (= 1000ths of a second) to a number
> of 2^64ths of a second by
>
> ms*2^64/1000 = ((ms*2^32)/1000)*2^32 = (ms << 32)/1000 << 32.
Modulo rounding, of course. The precise conversion would actually be:
uint32_t true_ms = ms % 1000U;
bt.frac = UINT64_C(18446744073709551) * true_ms + (616U * true_ms) / 1000U;
The first part of the expression is no worse than the 64bit divide by
1000, the second part could be optimised on platforms where we don't
care as much about the precision.
Joerg
Home |
Main Index |
Thread Index |
Old Index