From bff4de8ee1e179c2683df281f636c62425db7603 Mon Sep 17 00:00:00 2001 From: Alan Pawlak Date: Fri, 20 Jan 2023 13:29:07 +0000 Subject: [PATCH] Improve cot() function, to ensure x is not exactly a multiple of pi/2 --- src/sphstat/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sphstat/utils.py b/src/sphstat/utils.py index 98ffa89..12d0ee8 100644 --- a/src/sphstat/utils.py +++ b/src/sphstat/utils.py @@ -324,7 +324,10 @@ def cot(x): :return: Cotangent of the input :rtype: float """ - return 1/np.tan(x) + + # By subtracting the smallest positive representable number (eps) from x, + # the expression ensures that x is not exactly a multiple of pi/2 and thus the tangent of x is defined. + return 1/np.tan(x - np.finfo(float).eps) def poltoll(th: float, ph: float) -> tuple: