John Carmack在Quake III源代码中具有一个特殊功能,该功能可以计算浮点数的反平方根,比常规速度快4倍(float)(1.0/sqrt(x)),其中包括一个奇怪的0x5f3759df常数。请参见下面的代码。有人可以逐行解释这里到底发生了什么,为什么这样做比常规实现快得多?
float Q_rsqrt( float number )
{
  long i;
  float x2, y;
  const float threehalfs = 1.5F;
  x2 = number * 0.5F;
  y  = number;
  i  = * ( long * ) &y;
  i  = 0x5f3759df - ( i >> 1 );
  y  = * ( float * ) &i;
  y  = y * ( threehalfs - ( x2 * y * y ) );
  #ifndef Q3_VM
  #ifdef __linux__
    assert( !isnan(y) );
  #endif
  #endif
  return y;
}