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 12:05:35PM +0800, Paul Goyette wrote:
> On Thu, 5 Jan 2017, Paul Goyette wrote:
> 
> > Currently, we have
> > 
> > static __inline struct bintime
> > ms2bintime(uint64_t ms)
> > {
> >        struct bintime bt;
> > 
> >        bt.sec = (time_t)(ms / 1000U);
> >        bt.frac = (((ms % 1000U) >> 32)/1000U) >> 32;
> > 
> >        return bt;
> > }
> > 
> > As far as I can tell, this will result in bt.frac always set to zero,
> > since the (ms % 1000U) portion is a number less than 1000, and if you
> > shift a number less than 1000 to the right by 32 bits, you end up with
> > zero!
> > 
> > I suspect we should have a left shift here, rather than a right shift:
> > 
> >        bt.frac = (((ms % 1000U) << 32)/1000U) >> 32;
> > 
> > ---------------------------------^^           ^^
>                                                 ^^
> also here --------------------------------------^^

Why also here? (Guessing shift left to help division, then shift back again?)

P


Home | Main Index | Thread Index | Old Index