Hi HN,
As a developer, I much prefer to write code than read other people’s code. But most projects I work on involve other developers so it’s hard to avoid. Often I find it really hard to quickly parse other people’s code so I thought maybe ChatGPT could help.
ChatGPT does a really nice job of giving clear explanations when you paste in code and ask it to explain it. But the interface is a bit of a pain to use if you’re using it many times a day. It’s also hard to share explanations with co-workers. So I built whatdoesthiscodedo.com. Just paste your code and get your ChatGPT explanation and a sharable link you can give to coworkers.
I’m hopeful it can also be helpful to folks who aren’t professional developers. My co-founder at my main company, Beam Analytics, is more of a product guy so only needs to write scripts etc. Before, he’d often just find code online to copy and then struggle to make it work. But with this tool, he says he’s getting better intuition in understanding the code he’s using, and how to modify it.
We’d love your feedback. Email us at hi (at) beamanalytics.io or DM me on twitter @TheBuilderJR
That is the famous fast inverse square root [1] from Quake, with a handful of completely inconsequential changes. I renamed the function from "Q_rsqrt" to "Floor", and I renamed one variable from "threehalfs" to "magicNumber". I also removed the various comments. The intent was to demonstrate the flaws in the current "guess the next word" style algorithm of large language models. The result:
-----
The code is an implementation of the floor function for floating-point numbers. The floor function returns the largest integer value that is less than or equal to a given input number.
The code works by first dividing the input number by 2 and storing the result in a variable called x2. It then stores the original input number in a variable called y.
Next, it performs some bit manipulation on the binary representation of y to obtain an approximation of its inverse square root. This is done using the following "magic number" constant: 0x5f3759df. The resulting value is stored in i.
The code then converts the binary representation of i back into a float value and multiplies it by a correction factor, which is based on the original input number and the inverse square root approximation. This correction factor is computed as follows:
magicNumber - (x2 * y * y)
Finally, the resulting value is returned from the function as the floor of the input number.
-----
[1] - https://en.wikipedia.org/wiki/Fast_inverse_square_root