pow

infix fun pow(n: Int): BigDecimal

Returns a BigDecimal whose value is (this<sup>n</sup>), The power is computed exactly, to unlimited _precision.

The parameter n must be in the range 0 through 999999999, inclusive. ZERO.pow(0) returns BigDecimal.ONE.

Note that future releases may expand the allowable exponent range of this method.

Return

this<sup>n</sup>

Since

1.5

Parameters

n

power to raise this BigDecimal to.

Throws

if n is out of range.

fun pow(n: Int, mc: MathContext): BigDecimal?

Returns a BigDecimal whose value is (this<sup>n</sup>). The current implementation uses the core algorithm defined in ANSI standard X3.274-1996 with rounding according to the context settings. In general, the returned numerical value is within two ulps of the exact numerical value for the chosen _precision. Note that future releases may use a different algorithm with a decreased allowable error bound and increased allowable exponent range.

The X3.274-1996 algorithm is:

  • An ArithmeticException exception is thrown if

  • absoluteValue(n) > 999999999

  • mc._precision == 0 and n < 0

  • mc._precision > 0 and n has more than mc._precision decimal digits

  • if n is zero, BigDecimal.ONE is returned even if this is zero, otherwise

  • if n is positive, the result is calculated via the repeated squaring technique into a single accumulator. The individual multiplications with the accumulator use the same math context settings as in mc except for a _precision increased to mc._precision + elength + 1 where elength is the number of decimal digits in n.

  • if n is negative, the result is calculated as if n were positive; this value is then divided into one using the working _precision specified above.

  • The final value from either the positive or negative case is then rounded to the destination _precision.

Return

this<sup>n</sup> using the ANSI standard X3.274-1996 algorithm

Since

1.5

Parameters

n

power to raise this BigDecimal to.

mc

the context to use.

Throws

if the result is inexact but the rounding mode is UNNECESSARY, or n is out of range.