Search
 
SCRIPT & CODE EXAMPLE
 

C

fast inverse square root explained


    float InvSqrt(float x){
        float xhalf = 0.5f * x;
        int i = *(int*)&x;            // store floating-point bits in integer
        i = 0x5f3759df - (i >> 1);    // initial guess for Newton's method
        x = *(float*)&i;              // convert new bits into float
        x = x*(1.5f - xhalf*x*x);     // One round of Newton's method
        return x;
    }
Comment

Fast Inverse Square Root

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;
}
Comment

PREVIOUS NEXT
Code Example
C :: write a program in c to check whether the number is armstrong or not 
C :: program execution time calculate in c 
C :: C how to find substring in string 
C :: clrscr in c 
C :: merge sort code c 
C :: lldb set breakpoint function name 
C :: c convert integer to string 
C :: reverse of a string in c 
C :: function for quicksort in c 
C :: c check if character is a digit 
C :: multiplicationin c 
C :: sequelize count multiple associations 
C :: go optional parameters 
C :: c pass int by reference 
C :: gcc options to find out makefiel rules 
C :: make a function makefile 
C :: what is the usage of extern in c 
C :: replacing a character in string in C 
C :: c header file example 
C :: keep last n bits 
C :: how to malloc for matrix in c 
C :: delay in c programming for windows 
C :: function array median 
C :: imprimir matriz 
C :: why do you jerk while falling aslee 
C :: esp32 dhcp server 
C :: bool c++ 
C :: declare and initialize a string in C 
C :: what is clrsce in C 
C :: android studio sdkmanager always accept 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =