首页 > 其他 > 详细

一些函数

时间:2017-07-28 10:39:00      阅读:382      评论:0      收藏:0      [点我收藏+]

ref: http://www.guokr.com/post/90718/

开平方根

 1 // 平方根倒数 1/x
 2 float Q_rsqrt(float x)
 3 {
 4     float x2 = x * 0.5F;
 5     int i  = *(int*)&x; // evil floating point bit level hacking
 6     //i  = 0x5f3759df - (i >> 1);     // what the fuck?
 7     i  = 0x5f375a86 - (i >> 1);     // what the fuck?
 8     x  = *(float*)&i;
 9     x  = x * (1.5F - (x2 * x * x)); // 1st iteration
10     return x;
11 }
12 // 平方根
13 float SquareRootFloat(float number) {
14     long i;
15     float x, y;
16     const float f = 1.5F;
17 
18     x = number * 0.5F;
19     y  = number;
20     i  = * ( long * ) &y; 
21     i  = 0x5f3759df - ( i >> 1 );
22     y  = * ( float * ) &i; 
23 
24     y  = y * ( f - ( x * y * y ) );
25     y  = y * ( f - ( x * y * y ) );
26     return number * y;
27 }
28   

 

一些函数

原文:http://www.cnblogs.com/listenerln/p/7248775.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!