1 How the Bits are Interpreted (IEEE 754)
Before doing math, know how your the computer stores floating point numbers.
Here is how your input
4.0 looks in memory:
[sign]
[exponent]
[mantissa]
Sign Bit (ORANGE)
Determines if the number is positive or negative.
0 = Positive (+)
1 = Negative (-) (not supported)
Exponent (BLUE)
Uses a 127-bias. To get the real power of 2, subtract 127:
0 - 127 = 0
Meaning: 20
Mantissa (green)
These bits represent the fractional precision. The computer assumes a hidden leading
1.
Value: 1 + 0 = 0
Combined: (1.0 + 0) × 20 = 0
⚠️ MATHEMATICAL ERROR
Negative numbers are not supported by this algorithm.
2 The Magic Subtraction
We shift the bits and subtract them from the magic constant 0x5f3759df.
=
Resulting
Bits
(The "Dirty" Guess)
How bit subtraction works: Subtracting from this constant "flips" the exponent (positive to
negative) and adjusts for the IEEE 754 bias. This magically performs the 1/x and square root steps at the
same time.
Interpretation of Bits
Exponent: 0
(20)
Scientific Formula
1.00 × 20
Accuracy Comparison
Initial Hack Error: 0%