1
Understanding the math behind 0x5f3759df and the fast inverse square root (2012)
This post is about the magic constant 0x5f3759df and an extremely neat hack, fast inverse square root, which is where the constant comes from.
I’m Christian Plesner Hansen. I’m a software engineer working out of Århus, Denmark. This is my technical blog.
Visit h14s.p5r.org → RSS feedOn Hacker News Nov 2014 – Mar 2023
Software Engineering 3Math & Algorithms 2Programming Languages 1
This post is about the magic constant 0x5f3759df and an extremely neat hack, fast inverse square root, which is where the constant comes from.
Integer division is expensive. Much more expensive than multiplication. Much, much more expensive than addition. If you’re trying to make some integer operations really fast it’s bad news if you need to do division.