c++ - What is the difference between '*(<type> *) &x' and 'x'? -


what difference between

int = 123; int k; k = *(int *) &i; cout << k << endl; //output: 123 

and

int = 123; int k; k = i; cout << k << endl; //output: 123 

both of them give same output there difference?

(i found first snippet in quake3 code of fast inverse square root)

in q3:

float q_rsqrt( float number ) {     long i;     float x2, y;     const float threehalfs = 1.5f;      x2 = number * 0.5f;     y  = number;      = * ( long * ) &y;                       // evil floating point bit level hacking      = 0x5f3759df - ( >> 1 );               // fuck?     y  = * ( float * ) &i;     y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration //  y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration, can removed      return y; } 

as understand, interested in following line:

     = * ( long * ) &y; 

the y float, , i long. reinterpretation of floating point bit pattern integer bit pattern.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -