prjemian/pysumreg

Math domain error

Closed this issue · 1 comments

CI for apstools encounters a math domain error occasionally. This line:

return math.sqrt((self.YY - self.mean_y * self.Y) / (self.n - 1))

Calling code is the problem yet the reporting here could be more informative (such as checking for negative argument to math.sqrt() or (n-1) < 1.

Note:

In [1]: import math

In [2]: math.sqrt(1)
Out[2]: 1.0

In [3]: math.sqrt(0)
Out[3]: 0.0

In [4]: math.sqrt(1/0)
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
Cell In[4], line 1
----> 1 math.sqrt(1/0)

ZeroDivisionError: division by zero

In [5]: math.sqrt(-1)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[5], line 1
----> 1 math.sqrt(-1)

ValueError: math domain error

Only one possibility for a math domain error.