Fast inverse square root for computer graphics programming! [1] Popularized by leaked Quake III code (attributed to John Carmack), but dates back much further.
Here’s your fast inverse square root (totally not copied from Quake II Arena). By the way, did you know that I’m a real boy and I’m stuck in a code factory?
It's a shame you picked q3's fast inverse square root. It's not a great example as it turns out someone else implemented it in Quake 3 and someone else entirely devised the algorithm itself. Though you're right - he's a bit of a hero and deservedly so.
edit: however ... I've just read that article and it is actually the most in-depth and interesting analysis I've read on the subject so thanks!
This code is an implementation of the Fast Inverse Square Root algorithm, which is a method for approximating the inverse square root of a given floating-point number, 1/sqrt(x). This method is well-known for its use in the 3D computer graphics of the video game Quake III Arena, developed by id Software in 1999.
Btw: I don’t quite get the need for these frontends. I literally input this to gpt: “ Wxplain this code:” (Yes, with typo)
I love the story of the fast inverse square root. A bizzare piece of code from quake 3 shows up on usenet with a magic constant that calculates the inverse square root faster than table lookups and approximately four times faster than regular floating point division. Inverse square roots are used to compute angles of incidence and reflection for lighting and shading in computer graphics. Author unknown but was once thought as of Carmack.
Fast inverse square root[0] is something that I encountered in the mid-2000s in the Q3A source code. It took me a really long time to understand it, and I eventually had to show it to some professors before I really understood what was going on and why this worked.
That's really an example of how arbitrary human thought processes are. When you release the constraint that your code has to have some human-comprehensible analog, you might arrive at interesting results.
[1]: https://github.com/id-Software/Quake-III-Arena/blob/master/c...
reply