title: Java how to compute BigDecimal to the power of BigDecimal (both possibly negative)
body: <p>Given in input two BigDecimal, one for the base and one for the exponent:</p>
  
  <pre><code>BigDecimal base;
  BigDecimal exponent;
  </code></pre>
  
  <p>Considering that they can have both <strong>positive</strong> and <strong>negative</strong> signums, how can I calculate the power <code>base^exponent</code> ?</p>
  
  <p>I found the following method in the <code>BigDecimal class</code>, but it accepts only <code>int</code> as the exponent.</p>
  
  <pre><code>public BigDecimal pow(int n);
  </code></pre>
  
  <p>Then after an extra search I found <a href="https://github.com/aaiyer/SuanShu/blob/master/src/main/java/com/numericalmethod/suanshu/number/big/BigDecimalUtils.java#LC147" rel="nofollow noreferrer">https://github.com/aaiyer/SuanShu/blob/master/src/main/java/com/numericalmethod/suanshu/number/big/BigDecimalUtils.java#LC147</a></p>
  
  <p>exploiting the equality <code>z = x^y --&gt; z = exp ( ln(x) * y )</code></p>
  
  <p>but how can I calculate it in the case of negative base and exponents?</p>