3 ms·
Floating point representations are approximately logarithms. It should be clear to anyone with working knowledge of floating point numerics that dividing by tw
by stephencanon 14y ago
Floating point representations are approximately logarithms. It should be clear to anyone with working knowledge of floating point numerics that dividing by two and negating the representation of a floating point number corresponds to taking the reciprocal square root of the number. That's not magic, that's math.
The constant simply accounts for the bias in the floating point representation and balances the error over the domain of interest. Again, not magic.
There is no "bit-twiddling" at all.
- lmkg 14y agoExplaining the details of the bit-twiddles does not make it any less bit-twiddling. And explaining the details behind the opaque steps does not make them any less opaque to the uninitiated. You're using bit operations on a data type with a non-trivial bit structure. That's pretty much the definition of bit-twiddling. The fact that blunt bit operations on such a finely-defined structure can correspond to useful mathematical operations is non-obvious.
- mrbrowning 14y agoThe fast inverse square root trick is clever, but this is right on. It's bypassing the provided interface for FP operations and mucking around with implementation details. That's not to say that that's a bad thing, or that floating point numbers aren't a leaky abstraction, or that the real world doesn't demand this sort of optimization from time to time. But it's still true.
- stephencanon 14y ago> You're using bit operations on a data type with a non-trivial bit structure. It’s using integer operations on an encoding that has a meaningful (approximate) interpretation as an integer.
- coldtea 14y ago>And explaining the details behind the opaque steps does not make them any less opaque to the uninitiated. Emm, by definition it does.