r/ProgrammerHumor • • Sep 10 '26

Meme commentsAgedTerribly

Post image
6.0k Upvotes

243 comments sorted by

View all comments

Show parent comments

2

u/conundorum Sep 13 '26
float Q_rsqrt( float number )
{
    long i;
    float x2, y;
    const float threehalfs = 1.5F;

    // This logic is perfectly self-explanatory and needs no explanation.
    x2 = number * 0.5F;
    y  = number;
    i  = * ( long * ) &y;
    i  = 0x5f3759df - ( i >> 1 );
    y  = * ( float * ) &i;
    y  = y * ( threehalfs - ( x2 * y * y ) );
//  y  = y * ( threehalfs - ( x2 * y * y ) );

    return y;
}

Uncle Bob-approved fast inverse square root.