Created
October 17, 2011 22:51
-
-
Save sixthgear/1294084 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| ** float q_rsqrt( float number ) | |
| */ | |
| float Q_rsqrt( float number ) | |
| { | |
| floatint_t t; | |
| float x2, y; | |
| const float threehalfs = 1.5F; | |
| x2 = number * 0.5F; | |
| t.f = number; | |
| t.i = 0x5f3759df - ( t.i >> 1 ); // what the fuck? | |
| y = t.f; | |
| y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration | |
| // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed | |
| return y; | |
| } | |
| float Q_fabs( float f ) { | |
| floatint_t fi; | |
| fi.f = f; | |
| fi.i &= 0x7FFFFFFF; | |
| return fi.f; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment