精度不是很高  代码如下

 1 float SqrtByCarmack( float number )
 2 {
 3     int i;
 4     float x2, y;
 5     const float threehalfs = 1.5F;
 6 
 7     x2 = number * 0.5F;
 8     y  = number;
 9     i  = * ( int * ) &y;
10     i  = 0x5f375a86 - ( i >> 1 );
11     y  = * ( float * ) &i;
12     y  = y * ( threehalfs - ( x2 * y * y ) );
13     y  = y * ( threehalfs - ( x2 * y * y ) );
14     y  = y * ( threehalfs - ( x2 * y * y ) );
15     return number*y;
16 }

 

相关文章:

  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-11
  • 2021-06-08
  • 2021-08-06
  • 2021-04-07
  • 2021-12-24
相关资源
相似解决方案