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