Eli5: how do machines calculate the value of root of numbers that aren’t perfect squares.

169 views

Eli5: how do machines calculate the value of root of numbers that aren’t perfect squares.

In: 70

7 Answers

Anonymous 0 Comments

They use an algorithm. [There are a whole bunch of different algorithms for calculating roots](https://en.wikipedia.org/wiki/Methods_of_computing_square_roots), some of which have been known for thousands of years.

Some algorithms are faster than others, depending on the machine, the numbers involved, and how accurate the answer needs to be.

The 1999 computer game Quake III Arena famously used a [weird algorithm to calculate inverse square roots](https://en.wikipedia.org/wiki/Fast_inverse_square_root), which gained a lot of attention for including the seemingly random lines

i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df – ( i >> 1 ); // what the ****?

where they take away their number from 1597463007 (0x5f3759df in decimal).

This weird algorithm had been floating around the computer game and coding world since the late 80s, enough that the people at idSoftware knew of it but apparently didn’t understand it. At the time it was a much faster way of calculating inverse square roots than the standard methods (although was quickly surpassed).

You are viewing 1 out of 7 answers, click here to view all answers.