Question: I have been implementing control software in C and one of the control algorithms requires square root calculation. I have been looking for suitable square root calculation algorithm which will have constant execution time irrespective to the radicand value. This requirement rules out the `sqrt` function from the standard library.

As far as my platform I have been working with floating point 32 bits ARM Cortex A9 based machine. As far as the radicand range in my application the algorithms are calculated in physical units so I expect following range `<0, 400>`. As far as the required error I think that error about 1 % could be sufficient. Can anybody recommend me a square root calculation algorithm suitable for my purposes?

Answer: 
My initial approach would be to use the Taylor serie for square root with precalculated coefficients at a number of fixed points. This will reduce the calculation to a subtraction and a number of multiplication.

The look-up table would be a 2D array like:

```
point | C0  | C1  | C2  | C3  | C4  | ...
-----------------------------------------
 0.5  | f00 | f01 | f02 | f03 | f04 |
-----------------------------------------
 1.0  | f10 | f11 | f12 | f13 | f14 |
-----------------------------------------
 1.5  | f20 | f21 | f22 | f23 | f24 |
-----------------------------------------
....

```

So when calculating sqrt(x) use the table row with the point closest to x.

Example:

```
sqrt(1.1) (i.e. use point 1.0 coeffients)

f10 + 
f11 * (1.1 - 1.0) + 
f12 * (1.1 - 1.0) ^ 2 + 
f13 * (1.1 - 1.0) ^ 3 + 
f14 * (1.1 - 1.0) ^ 4

```

The table above suggest a fixed distance between the points at which you precalculate coeffients (i.e. 0.5 between each point). However, due to the natur of square root you may find that the distance between points shall differ for different ranges of `x`. For instance `x` in [0 - 1] -> distance 0.1,`x` in [1 - 2] -> distance 0.25, `x` in [2 - 10] -> distance 0.5 and so on.

Another thing is the number of terms needed to get the desired precision. Here you may also find that different ranges of `x` may require a different number of coefficients.

All this is easy to precalculation on a normal computer (e.g. using excel).

Note: For values very close to zero this method isn't good. Maybe Newtons method will be a better choice.

Taylor series: <https://en.wikipedia.org/wiki/Taylor_series>

Newtons method: <https://en.wikipedia.org/wiki/Newton%27s_method>

Also relevant: <https://math.stackexchange.com/questions/291168/algorithms-for-approximating-sqrt2>
I have decided to use following approach. I have chosen the Newton method and then I have experimentally set the fixed number of iterations so that the error in whole range of the radicand i.e. `<0,400>` doesn't exceed the prescribed value. I have ended at six iterations. As far as the radicand with value 0 I have decided to return 0 without any calculations.