Created
August 24, 2019 00:58
-
-
Save lh3/9430fbb713f8a6171ab0befecfee015d to your computer and use it in GitHub Desktop.
Fast square root
This file contains 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
// a combination of inverse square root (see wiki) and inversion: https://bits.stephan-brumme.com/inverse.html | |
static inline float mg_sqrtf(float x) | |
{ | |
union { float f; uint32_t i; } z = { x }; | |
z.i = 0x5f3759df - (z.i >> 1); | |
z.f *= (1.5f - (x * 0.5f * z.f * z.f)); | |
z.i = 0x7EEEEEEE - z.i; | |
return z.f; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment