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.
Programming languages new (Java) and old (Fortran), and their compilers, still lack competent support for features of IEEE 754 so painstakingly provided by practically all hardware nowadays. […] Programmers seem unaware that IEEE 754 is a standard for their programming environment, not just for hardware. William Kahan