There are two commonly used conventions for cotangent inversion, since, for example, cot (1) = cot (1-pi). It is important to consider which definition to use.
Let arccot ​​(x) correspond to atan (1 / x) with values ​​between -pi / 2 and pi / 2. This gives breaks at 0 (jumps from -pi / 2 to pi / 2). This agreement is used in the response of Greg Hugh.

public static double Acot(double x) { return (x < 0 ? -Math.PI/2 : Math.PI/2) - Math.Atan(x); }
or
public static double Acot(double x) { return x == 0 ? 0 : Math.Atan(1/x); }
Let arccot ​​(x) be a continuous function with values ​​from 0 to pi. This is the agreement used in Daniel Martin's answer.

public static double Acot(double x) { return Math.PI/2 - Math.Atan(x); }
source share