q_rsqrt 0.1.1

An implementation of the fast inverse square root function from quake 3
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 3.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ThatNerdUKnow/Q_rsqrt
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ThatNerdUKnow

This is a implementation of the fast inverse square root function from quake 3.
It can be up to three times as fast as using the .sqrt() method on a float32
Keep in mind that fast inverse square root is only accurate within a one percent margin of error

Here's the original implementation:

float Q_rsqrt( float number )
{
	long i;
	float x2, y;
	const float threehalfs = 1.5F;

	x2 = number * 0.5F;
	y  = number;
	i  = * ( long * ) &y;                       // evil floating point bit level hacking
	i  = 0x5f3759df - ( i >> 1 );               // what the fuck? 
	y  = * ( float * ) &i;
	y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration
//	y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration, this can be removed

	return y;
}