Java Number Power pow(double base, int exp)

Here you can find the source of pow(double base, int exp)

Description

pow

License

Open Source License

Declaration

public static double pow(double base, int exp) 

Method Source Code

//package com.java2s;

public class Main {
    public static double pow(double base, int exp) {
        return exp == 0 ? 1 : sq(pow(base, exp / 2)) * (exp % 2 == 1 ? base : 1);
    }/*from  w  w  w.j  a v a  2 s  .  c o  m*/

    public static long pow(long base, int exp) {
        return exp == 0 ? 1 : sq(pow(base, exp / 2)) * (exp % 2 == 1 ? base : 1);
    }

    public static int pow(int base, int exp) {
        return exp == 0 ? 1 : sq(pow(base, exp / 2)) * (exp % 2 == 1 ? base : 1);
    }

    private static double sq(double x) {
        return x * x;
    }

    private static long sq(long x) {
        return x * x;
    }

    private static int sq(int x) {
        return x * x;
    }
}

Related

  1. pow(double a, double b)
  2. pow(double a, double b)
  3. pow(double a, int b)
  4. pow(double base, double exp)
  5. pow(double base, int exp)
  6. pow(double base, int exponent)
  7. pow(double number)
  8. Pow(double val, Object in)
  9. Pow(double value)