code: public static BigDecimal pow(BigDecimal x, long y, MathContext mathContext) {
  		MathContext mc = mathContext.getPrecision() == 0 ? mathContext : new MathContext(mathContext.getPrecision() + 10, mathContext.getRoundingMode());
  
  		// TODO optimize y=0, y=1, y=10^k, y=-1, y=-10^k
  
  		if (y < 0) {
  			BigDecimal value = reciprocal(pow(x, -y, mc), mc);
  			return round(value, mathContext);
  		}
  		
  		BigDecimal result = ONE;
  		while (y > 0) {
  			if ((y & 1) == 1) {
  				// odd exponent -> multiply result with x
  				result = result.multiply(x, mc);
  				y -= 1;
  			}
  			
  			if (y > 0) {
  				// even exponent -> square x
  				x = x.multiply(x, mc);
  			}
  			
  			y >>= 1;
  		}
  
  		return round(result, mathContext);
  	}
docs: Calculates {@link BigDecimal} x to the power of <code>long</code> y (x<sup>y</sup>).
  
  <p>The implementation tries to minimize the number of multiplications of {@link BigDecimal x} (using squares whenever possible).</p>
  
  <p>See: <a href="https://en.wikipedia.org/wiki/Exponentiation#Efficient_computation_with_integer_exponents">Wikipedia: Exponentiation - efficient computation</a></p>
  
  @param x the {@link BigDecimal} value to take to the power
  @param y the <code>long</code> value to serve as exponent
  @param mathContext the {@link MathContext} used for the result
  @return the calculated x to the power of y with the precision specified in the <code>mathContext</code>
  @throws ArithmeticException if y is negative and the result is inexact but the
  rounding mode is {@code UNNECESSARY} or
  {@code mc.precision == 0} and the quotient has a
  non-terminating decimal expansion.
  @throws ArithmeticException if the rounding mode is
  {@code UNNECESSARY} and the
  {@code BigDecimal}  operation would require rounding.