title: Calculating power for Decimals in Python
body: <p>I want to calculate power for <code>Decimal</code> in Python like:</p>
  
  <pre><code>from decimal import Decimal
  Decimal.power(2,2)
  </code></pre>
  
  <p>Above should return me as <code>Decimal('2)</code></p>
  
  <p>How can I calculate power for <code>Decimals</code>?</p>
  
  <p>EDIT:
  This is what i did </p>
  
  <pre><code>y = Decimal('10')**(x-deci_x+Decimal(str(n))-Decimal('1'))
  </code></pre>
  
  <p>x,deci_x are of decimal type</p>
  
  <p>but above expression is throwing error as:</p>
  
  <pre><code>decimal.InvalidOperation: x ** (non-integer)
  </code></pre>
  
  <p>Stacktrace:</p>
  
  <pre><code>Traceback (most recent call last):
    File "ha.py", line 28, in ?
      first_k_1=first_k(2,n-1,k)
    File "ha.py", line 18, in first_k
      y = Decimal('10')**(x-deci_x+Decimal(str(n))-Decimal('1'))
    File "/usr/lib64/python2.4/decimal.py", line 1709, in __pow__
      return context._raise_error(InvalidOperation, 'x ** (non-integer)')
    File "/usr/lib64/python2.4/decimal.py", line 2267, in _raise_error
      raise error, explanation
  </code></pre>