|
|
|
|
|
by commandlinefan
1150 days ago
|
|
I've always wondered why they did the casting rather than a union like: float my_rsqrt( float number )
{
float x2;
union {
float y;
long i;
} u;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
u.y = number;
u.i = 0x5f3759df - ( u.i >> 1 ); // what the fuck?
u.y = u.y * ( threehalfs - ( x2 * u.y * u.y ) ); // 1st iteration
return u.y;
}
Were unions not supported by the compilers back then? |
|