Skip to content

Instantly share code, notes, and snippets.

@sixthgear
Created October 17, 2011 22:51
Show Gist options
  • Select an option

  • Save sixthgear/1294084 to your computer and use it in GitHub Desktop.

Select an option

Save sixthgear/1294084 to your computer and use it in GitHub Desktop.
/*
** float q_rsqrt( float number )
*/
float Q_rsqrt( float number )
{
floatint_t t;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
t.f = number;
t.i = 0x5f3759df - ( t.i >> 1 ); // what the fuck?
y = t.f;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
return y;
}
float Q_fabs( float f ) {
floatint_t fi;
fi.f = f;
fi.i &= 0x7FFFFFFF;
return fi.f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment