Stable Cotangent
cot(x) = cos(x)/sin(x) should be more numerically stable close to π/2 than cot(x) = 1/tan(x). You can implement that efficiently using sincos on platforms that have it. Another possibility is cot(x) = tan(M_PI_2 – x). This should be faster than the above (even if sincos is available), but it may also be less accurate, because … Read more