Ejemplo n.º 1
0
        /**
         * Calculates {@link BigComplex} x to the power of {@link BigDecimal} y (x<sup>y</sup>).
         *
         * @param x the {@link BigComplex} value to take to the power
         * @param y the {@link BigDecimal} 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>
         */
        public static BigComplex pow(this BigComplex x, BigDecimal y, MathContext mathContext)
        {
            MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode());

            BigDecimal angleTimesN = x.angle(mc).multiply(y, mc);

            return(BigComplex.valueOf(
                       BigDecimalMath.cos(angleTimesN, mc),
                       BigDecimalMath.sin(angleTimesN, mc)).multiply(BigDecimalMath.pow(x.abs(mc), y, mc), mc).round(mathContext));
        }