Last active
March 16, 2023 01:36
-
-
Save piyush01123/bb9a736e5b1a895e8c1e0e841e963a40 to your computer and use it in GitHub Desktop.
Fast Inverse Square Root - Quake III
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 fisr(float n){ | |
long x = 0x5f3759df - (*(long *)&n >> 1); //magic number = 1.5*2^23*(127-mu); mu represents log(1+x)=x+mu; mu=0.0450465 | |
float y = *(float *)&x; // Solution from bit manipulation | |
y = 1.5F*y - 0.5F*n*y*y*y; // Newton improvement 1 | |
y = 1.5F*y - 0.5F*n*y*y*y; // Newton improvement 2 | |
return y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.