q_rsqrt

Crates.ioq_rsqrt
lib.rsq_rsqrt
version0.1.1
sourcesrc
created_at2022-06-27 05:16:42.50546
updated_at2022-06-27 05:20:52.923209
descriptionAn implementation of the fast inverse square root function from quake 3
homepage
repositoryhttps://github.com/ThatNerdUKnow/Q_rsqrt
max_upload_size
id613926
size3,433
Brandon PiƱa (ThatNerdUKnow)

documentation

README

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;
}
Commit count: 4

cargo fmt