Hello,
Is there a more stable implementation for the cotangent function than return 1.0/tan(x);?
Hello,
Is there a more stable implementation for the cotangent function than return 1.0/tan(x);?
cot(x) = cos(x)/sin(x) should be more numerically stable close to pi/2 than cot(x) = 1/tan(x). You can implement that efficiently using sincos on platforms that have it.
EDIT: Much better answer: cot(x) = tan(M_PI_2 - x).