Q10.1.2Evaluating \(\sqrt{\tan(\pi)}\)
\(\sqrt{\tan(\pi)} = 0\) is mathematically well-defined, so why does the folllowing calculation fail with a math domain error?
In [x]: math.sqrt(math.tan(math.pi))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-135-7bfdceeef434> in <module>()
----> 1 math.sqrt(math.tan(math.pi))
Show solution
This occurs because math.pi is only a (floating point, double precision) approximation to \(\pi\), and the tangent of this approximate value happens to be negative:
In [x]: math.tan(math.pi)
Out[x]: -1.2246467991473532e-16
Taking the square root leads to the math domain error.