Now this is simply an amazing little snippet of math here. This function performs a 1/sqrt(x) operation in a fraction of the time, while maintaining accuracy. This operation is performed alot in graphics, and seeing it distilled down to such a simple and fast function… Well, it’s amazing.

It’s basically a Newton-Raphson approximation that exploits the X86 memory to perform some fancy floating-point match in Integer registers (eg. much much faster), with a very clever first approximation (0x5f3759df ). Very impressive stuff.

Found this via Beyond3d.
Update: Just curious of the accuracy of this snippet, so I coded it up so see what happened.. Click through for the results…

Update 12/20: I added some more results. Now I have some Timing Figures.  Also, a friend just sent me a link to This PDF Paper by Chris Lomont describing the “Magic number” and how the entire process works.  It’s an interesting read, but gonna be a while before I can fully understand it.

[tag:algorithm][tag:sqrt][tag:snippet]