精度不是很高 代码如下
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 }