Skip to content

Instantly share code, notes, and snippets.

@piyush01123
Last active March 16, 2023 01:36
Show Gist options
  • Save piyush01123/bb9a736e5b1a895e8c1e0e841e963a40 to your computer and use it in GitHub Desktop.
Save piyush01123/bb9a736e5b1a895e8c1e0e841e963a40 to your computer and use it in GitHub Desktop.
Fast Inverse Square Root - Quake III
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;
}
@piyush01123
Copy link
Author

piyush01123 commented Aug 11, 2021

IMG_20210811_105159-3

IMG_20210811_102519-2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment