Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Inverse Square Root by Greg Walsh
float invSqrt(float x)
union {
float x;
int i;
} u;
float xhalf = 0.5f * x;
u.x = x;
u.i = 0x5f3759df - (u.i >> 1);
u.x = u.x * (1.5f - xhalf * u.x * u.x);
return u.x;
Copy link

NostraDavid commented Dec 30, 2020

This is a more readable version of the famous invSqrt from idTech 3 (Quake 3 engine), likely created by Greg Walsh.

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