# Sqrt + code improvement

Hi everyone,
I’m writing a code in Hydra for virtual sources positioning in 3D space, this means that for each virtual sound source (16 total) I have a X,Y,Z coordinate and then I have to calculate the distance from this point to a matrix, the single part of the sqrt(x^2+y^2+z^2) is the following:

``````root[0] = (float)((((modpos[f][c][0] + speakpos[s][0]) - srcpos[src][0]) * ((modpos[f][c][0] + speakpos[s][0]) - srcpos[src][0])) + (((modpos[f][c][1] + speakpos[s][1]) - srcpos[src][1]) * ((modpos[f][c][1] + speakpos[s][1]) - srcpos[src][1])) + (((0 + speakpos[s][2]) - srcpos[src][2]) * ((0 + speakpos[s][2]) - srcpos[src][2])));

Q_rsqrt.Invoke(root, length, value);
``````

The problem is only this two lines (first one the squares and second the sqrt which I already implemented in RLP) is consuming 80% of the total execution time of the program. This distance calculation is inside a loop of 65536 executions. Implementing the sqrt in RLP only improved 1s the speed of the algorithm; with sqrt in c# it is around 6s, with sqrt RLP is 5s and the objective is to execute this algorithm in 125ms.