title: Exact Sine/Cosine/Tangent of Various Angles
body: <p>Is there a way to get the exact Tangent/Cosine/Sine of an angle (in radians)?</p>
  
  <p><code>math.tan()</code>/<code>math.sin()</code>/<code>math.cos()</code> does not give the exact for some angles:</p>
  
  <pre><code>&gt;&gt;&gt; from math import *
  &gt;&gt;&gt; from decimal import Decimal
  &gt;&gt;&gt; sin(pi) # should be 0
  1.2246467991473532e-16
  &gt;&gt;&gt; sin(2*pi) # should be 0
  -2.4492935982947064e-16
  &gt;&gt;&gt; cos(pi/2) # should be 0
  6.123233995736766e-17
  &gt;&gt;&gt; cos(3*pi/2) # 0
  -1.8369701987210297e-16
  &gt;&gt;&gt; tan(pi/2) # invalid; tan(pi/2) is undefined
  1.633123935319537e+16
  &gt;&gt;&gt; tan(3*pi/2) # also undefined
  5443746451065123.0
  &gt;&gt;&gt; tan(2*pi) # 0
  -2.4492935982947064e-16
  &gt;&gt;&gt; tan(pi) # 0
  -1.2246467991473532e-16
  </code></pre>
  
  <p>I tried using Decimal(), but this does not help either:</p>
  
  <pre><code>&gt;&gt;&gt; tan(Decimal(pi)*2)
  -2.4492935982947064e-16
  </code></pre>
  
  <p><code>numpy.sin(x)</code> and the other trigonometric functions also have the same issue.</p>
  
  <p>Alternatively, I could always create a new function with a dictionary of values such as:</p>
  
  <pre><code>def new_sin(x):
      sin_values = {math.pi: 0, 2*math.pi: 0}
      return sin_values[x] if x in sin_values.keys() else math.sin(x)
  </code></pre>
  
  <p>However, this seems like a cheap way to get around it. Is there any other way? Thanks!</p>