In layman terms, how does this black magic work?
>>58690993
https://en.wikipedia.org/wiki/Fast_inverse_square_root#Algorithm
>>58690993
The goal of this function is to do hit detection so it's got to be optimized to hell because that's a classically computationally intense process.
The obvious hit detection method is to go though and check every combination of objects for hits by their distance from each other. To do this you would need to use the distance formula, which uses square roots.
While not completely accurate, inverse square root is close enough to square root to be used to estimate what objects definitely aren't touching while being way faster. From this graph notice how terrible calculating a square root is.
newton's method is used to numerically estimate a function from its derivative. This method requires an initial guess (one of the constants) and is iterative (the blacked out line). I'm pretty sure that's what the C standard library already does to calculate square roots, they just use however many iterations are required to get a sure answer. This just uses only one iteration.
It's actually a common optimization. Read about it in "art of computer programming: bitwise tricks" and "hacker's delight", the second of which actually mentions inverse square root by name
oh yeah, and also remember that floating point = scientific notation so they use that fact to their advantage
>>58690993
It doesn't. It's undefined behavior
>>58691450
>From this graph notice how terrible calculating a square root is
ummmmmmmmm
>doom
>>58691450
Senpai, it just shows the different degrees of complexity, not the complexity of the algorithm required to calculate the square root.
>>58694561
>pic
>>58691450
>From this graph notice how terrible calculating a square root is.
Posts like these make me paranoid. The rest of your post would make me think you knew what you were talking about.
why is fuck censored in that image?
Also, this hasn't been a real optimization since SSE came into existence, since it has a fast aproximate inverse square root instruction.
>>58691726
What's undefined about that? strict aliasing was only added in C99