读书人

关于ntp协议中两个宏NTPFRAC(x)跟USEC

发布时间: 2012-11-18 10:51:22 作者: rapoo

关于ntp协议中两个宏NTPFRAC(x)和USEC(x)的疑问
/* How to multiply by 4294.967296 quickly (and not quite exactly)
* without using floating point or greater than 32-bit integers.
* If you want to fix the last 12 microseconds of error, add in
* (2911*(x))>>28)
*/
#define NTPFRAC(x) ( 4294*(x) + ( (1981*(x))>>11 ) )

/* The reverse of the above, needed if we want to set our microsecond
* clock (via settimeofday) based on the incoming time in NTP format.
* Basically exact.
*/
#define USEC(x) ( ( (x) >> 12 ) - 759 * ( ( ( (x) >> 10 ) + 32768 ) >> 16 ) )
想写关于ntp的东西,在网上找了个程序,其中有两个宏定义NTPFRAC(x)和USEC(x)。有注释但是还是不太明白,有没有高人指点。

[解决办法]
1、How to multiply by 4294.967296 quickly

2、The reverse of the above

用数学式子带进去就知道了

读书人网 >C语言

热点推荐