How is the square root function implemented?
A:
If you're interested, the Numerical Recipes book has lots on how to calculate square roots, sines and cosines, exponentials, logarithms, and so on.
Philip Potter
2010-08-27 07:58:14
A:
Take a look here. It contains 13 C++ implementations of sqrt, together with speed and precision comparison.
Lior Kogan
2010-08-27 08:11:37
The author of the article tries to measure the speed of the functions by averaging the time, which is good. It's just that it's implemented wrong.
Peter Stuifzand
2010-08-27 09:22:35
A:
On Intel hardware, it's often implemented on top of the hardware SQRT instruction. Some libraries just use the result of that straight off, some may put it through a couple of rounds of Newton optimisation to make it more accurate in the corner cases.
Tom Anderson
2010-08-27 09:42:09