# Math 101: Where is cubic root function?

Another quickie in the "Math 101" cycle. From time to time users approach support asking how can they calculate cubic root and why such function is missing.

The answer is: it is not missing.

Root of any order can be calculated by rising to power (1/root), so square root is equivalent to

``````x ^ (1/2)
``````

and cubic root is just

``````x ^ (1/3)
``````

And 5th order root is just

``````x ^ (1/5)
``````

You can use the following functions if you wish:

``````function anyroot( x, order )
{
return x ^ (1/order);
}

function cubicroot( x )
{
return x ^ ( 1/3 );
}
``````

You may wonder why then there is a special function `sqrt()` that implements just square root. The reason is that square root (and only square root) is implemented in HARDWARE in all modern CPUs (actually floating processing units). Why? That is because square root is used pretty often in many areas (calculating distances in 2D space, Pythagorean theorem, standard deviation, etc, etc) and for speed CPUs implement this in hardware for speed. It works faster than rising to power of (1/2). Other roots are used way less often so they are all handled by generic power function.

4 Likes