Live data from Hacker News

0x5f3759df and the fast inverse square root (2012)

h14s.p5r.org

21–27 of 27 posts

Re: 0x5f3759df and the fast inverse square root (2012)

#22
post #4
post #2

I may be going on rampage here but " It does contain a fair bit of math " really grinds my gears! Of course it does, it is about square roots and inversions. In most of the cases, in order to optimize an algorithm or solve a problem, mathematics will do it for you, and that ranges from simple arithmetic properties to base changing theorems in linear algebra. You just can not tackle such subjects without expecting it…

loads of things do not require math (in the sort of "doing stuff with functions in (R -> R), or multiplications/division). Pretty much no sorting algorithm requires mathematical knowledge to work through, nor do many data structure algorithms. Concurrency resolution issues neither. This is of course, so long as you consider math to be "do stuff with these numbers." Group theory and the like can help guide your result…

> Pretty much no sorting algorithm requires mathematical knowledge to work through, nor do many data structure algorithms. Concurrency resolution issues neither.

None of those requires _calculus_. I disagree about them not requiring maths.

Re: 0x5f3759df and the fast inverse square root (2012)

#23
post #2

I may be going on rampage here but " It does contain a fair bit of math " really grinds my gears! Of course it does, it is about square roots and inversions. In most of the cases, in order to optimize an algorithm or solve a problem, mathematics will do it for you, and that ranges from simple arithmetic properties to base changing theorems in linear algebra. You just can not tackle such subjects without expecting it…

All I do is make buttons blink with jquery and I'm supposedly an engineer.

If you also make things happen on the click event of the button then I would say that counts.

Re: 0x5f3759df and the fast inverse square root (2012)

#24

Tl;DR : The fast inverse square root is based on the fact that the integer representation of a floating point number is a rough approximation of its logarithm. So convert floating point to its integer representation. So now you have its approximate logarithm. Now take half of that and improve that with some Newton raphson.

It would be exact if we used a logarithm based number system: http://en.wikipedia.org/wiki/Logarithmic_number_system

This kind of system is beautiful, but there is no easy way to add and subtract.

Re: 0x5f3759df and the fast inverse square root (2012)

#25

If anyone wants a fast atan2 that I wrote a while ago (2007), for making a microcontroller navigate, it's at http://robots-everywhere.com/portfolio/math/

how's it compare to a CORDIC?

I wrote it for the Parallax Propeller, which is slow at doing divisions - so I tried to keep those to a minimum (one, which isn't too bad).

Re: 0x5f3759df and the fast inverse square root (2012)

#26

Earlier quoted context omitted.

how's it compare to a CORDIC?

I wrote it for the Parallax Propeller, which is slow at doing divisions - so I tried to keep those to a minimum (one, which isn't too bad).

With a CORDIC the only divides should be by powers of 2 in the main loop and taking out the gain factor at the end, all of which can be turned into multiplies?

Re: 0x5f3759df and the fast inverse square root (2012)

#27

Earlier quoted context omitted.

I wrote it for the Parallax Propeller, which is slow at doing divisions - so I tried to keep those to a minimum (one, which isn't too bad).

With a CORDIC the only divides should be by powers of 2 in the main loop and taking out the gain factor at the end, all of which can be turned into multiplies?

Thanks, I'm going to go back and try it :)
Post reply on HN