src/Utilities/FastMath.hh
//------------------------------------------------------------------------------
// A iterative sqrt estimate.  This appears to start with a very similar trick
// to the Quake 3 idea.
//------------------------------------------------------------------------------
A iterative sqrt estimate.  This appears to start with a very similar trick
to the Quake 3 idea.
A iterative sqrt estimate . This appears to start with a very similar trick to the Quake 3 idea .
inline
double Sqrt(const double y) {
  double x, z, tempf;
  tempf = y;
  unsigned long *tfptr = ((unsigned long *)&tempf) + 1;
  *tfptr = (0xbfcdd90a - *tfptr)>>1; 
  x =  tempf;
  z =  y*0.5;                        
  x = (1.5*x) - (x*x)*(x*z);         
  x = (1.5*x) - (x*x)*(x*z);
  x = (1.5*x) - (x*x)*(x*z);
  x = (1.5*x) - (x*x)*(x*z);
  x = (1.5*x) - (x*x)*(x*z);
  return x*y;
}
inline double Sqrt ( const double y ) { double x , z , tempf ; tempf = y ; unsigned long * tfptr = ( ( unsigned long * ) & tempf ) + 1 ; * tfptr = ( 0xbfcdd90a - * tfptr ) >> 1 ; x = tempf ; z = y * 0.5 ; x = ( 1.5 * x ) - ( x * x ) * ( x * z ) ; x = ( 1.5 * x ) - ( x * x ) * ( x * z ) ; x = ( 1.5 * x ) - ( x * x ) * ( x * z ) ; x = ( 1.5 * x ) - ( x * x ) * ( x * z ) ; x = ( 1.5 * x ) - ( x * x ) * ( x * z ) ; return x * y ; }
A iterative sqrt estimate.
A iterative sqrt estimate .
// estimate of 1/sqrt(y) // hoist out the ~/2~ // iteration formula