I've read this blog about the algorithm:
http://betterexplained.com/articles/understanding-quakes-fast-inverse-square-root/
I understand that we have to manipulate the exponent in order to obtain the inverse square root. To this manipulation we take advantage from the IEEE 754 notation. My problem comes in this sentence (almost at the end) of the article:
"So, the code converts the floating-point number into an integer. It then shifts the bits by one, which means the exponent bits are divided by 2"
I we do that we are also manipulating the mantissa. Why we're doing this? As I said, the idea is to manipulate the exponent so, why we are also changing the mantissa? Can anybody help me? Thanks
You number is $x=2^{e-b}·(1+m)$ where $e$ is the exponent, $b$ the bias, $m$ the mantissa interpreted as fractional part. The inverse square root of this is $$ \frac1{\sqrt{x}}=2^{(b-e)/2}·(1-m/2+O(m^2)) $$ This shows you why the bit shift in the floating point number will come close to that result and also why you need to subtract it from a "magic" number, since the negated bit shift alone produces something like (but not exactly) $$ -2^{b+2-e/2}·(1-m/2) $$
To test this, compute the magic constant by reverse engineering the formula:
with result
The magic constant used in the program,
5f3759df, is in the middle of that following some error minimization strategy or some other.