Java BigDecimal Power power(BigDecimal base, int exponent)

Here you can find the source of power(BigDecimal base, int exponent)

Description

Returns the exponentiation of the given base raised to power of the given exponent.

License

Open Source License

Parameter

Parameter Description
base The decimal base to be raised to the power of the given exponent.
exponent The exponent to raise the given base to.

Return

The result of raising the given base to the power of the given exponent.

Declaration

public static BigDecimal power(BigDecimal base, int exponent) 

Method Source Code


//package com.java2s;
/*//from  w  w w.  j  a v  a2s  .  co m
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Lachlan Dowding
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

import java.math.BigDecimal;
import java.math.BigInteger;

public class Main {
    /**
     * Returns the exponentiation of the given base raised to power of the given exponent.
     *
     * @param base     The decimal base to be raised to the power of the given exponent.
     * @param exponent The exponent to raise the given base to.
     * @return The result of raising the given base to the power of the given exponent.
     */
    public static BigDecimal power(BigDecimal base, BigInteger exponent) {
        if (exponent == null)
            return base;
        return power(base, exponent.intValue());
    }

    /**
     * Returns the exponentiation of the given base raised to power of the given exponent.
     *
     * @param base     The decimal base to be raised to the power of the given exponent.
     * @param exponent The exponent to raise the given base to.
     * @return The result of raising the given base to the power of the given exponent.
     */
    public static BigDecimal power(BigDecimal base, int exponent) {
        if (base == null)
            return null;
        return base.pow(exponent);
    }
}

Related

  1. pow(BigDecimal b, int p, int q)
  2. pow(BigDecimal base, BigDecimal exponent)
  3. pow(BigDecimal base, BigDecimal power)
  4. pow(BigDecimal one, int another)
  5. pow(BigDecimal savedValue, BigDecimal value)
  6. power(final BigDecimal value, final long power)