You are viewing a single comment's thread.

view the rest of the comments →

0
10

[–] taxation_is_slavery 0 points 10 points (+10|-0) ago 


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?   <-- THIS HERE
    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;
}

Probably a few others in business apps, but they elicit the wtf, and don't ask it.

0
4

[–] for_satan [S] 0 points 4 points (+4|-0) ago 

That one is always a good one. Made a lot of game code faster.

0
4

[–] CathyTheGreatsHorse 0 points 4 points (+4|-0) ago 

That one is always a good one.

Is it well known? Just curious if there is a story behind it.

Seems like that witchcraft would be near impossible to troubleshoot without a deep understanding of how the floating point data type worked.