专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 网络通信

关于ntp协议中两个宏NTPFRAC(x)和USEC(x)的疑问解决方案

发布时间:2011-07-03 07:02:19 文章来源:www.iduyao.cn 采编人员:星星草
关于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)。有注释胆识还是不太明白,有没有高人指点。
------解决方案--------------------
英文注释里不是写了吗?
#define NTPFRAC(x) ( 4294*(x) + ( (1981*(x))>>11 ) )
这个宏是用于计算x*4294.967296的非精确写法,这样就避免了浮点计算

#define USEC(x) ( ( (x) >> 12 ) - 759 * ( ( ( (x) >> 10 ) + 32768 ) >> 16 ) )
这个是上面过程的反过程,表示x/4294.967296

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: