On Thursday 06 April 2017 09:54 PM, Thierry Reding wrote: > * PGP Signed by an unknown key > > On Thu, Apr 06, 2017 at 07:50:59PM +0530, Laxman Dewangan wrote: >> The rate of the PWM calculated as follows: >> hz = NSEC_PER_SEC / period_ns; >> rate = (rate + (hz / 2)) / hz; >> >> This has the precision loss in lower PWM rate. >> Changing this to have more precision as: >> hz = DIV_ROUND_CLOSE(NSEC_PER_SEC * 100, period_ns); >> rate = DIV_ROUND_CLOSE(rate * 100, hz) > DIV_ROUND_CLOSEST(). And I much prefer this to the actual code below. I > don't think it's necessary to have a local variable for the precision. Do you suggest to use DIV_ROUND_CLOSEST() instead of DIV_ROUND_CLOSEST_ULL()? This is ULL division and so we need to use this one. Or am I missing something