Java Utililty Methods Number Power

List of utility methods to do Number Power

Description

The list of methods to do Number Power are organized into topic(s).

Method

intpow(int a, int b)
pow
if (b > 1)
    return a * pow(a, b - 1);
else
    return a;
intpow(int a, int b, int modulus)
Calculates a^b mod modulus
int p = 1;
for (int i = 0; i < b; i++) {
    p = (p * a) % modulus;
return p;
intpow(int b, int e)
compute b to the e power (b ** e)
int a = 1;
for (int i = 0; i < e; i++) {
    a *= b;
return a;
intpow(int base, int exp)
Computes an exponent.
if (exp < 0) { 
    throw new ArithmeticException("exponent must be non-negative");
if (exp == 0) {
    return 1;
if (exp == 1) {
    return base;
...
intpow(int base, int exp)
pow
return exp == 0 ? 1 : pow(base, exp - 1) * base;
intpow(int base, int exponent)
Returns the value of the first argument raised to the power of the second argument.
boolean reciprocal = false;
if (exponent < 0) {
    reciprocal = true;
int result = 1;
while (exponent-- > 0) {
    result *= base;
return reciprocal ? 1 / result : result;
intpow(int base, int power)
pow
int i, res = 1;
for (i = 0; i < power; i++) {
    res *= base;
return res;
intpow(int i, int pow)
pow
if (pow == 0 || i == 0)
    return 1;
int r = i;
if (pow > 0) {
    for (int j = 0; j < pow; j++) {
        r *= i;
} else {
...
intpow(int leftOp, int rightOp)
pow
return (int) Math.pow(leftOp, rightOp);
intpow(int n, int p)
pow
if (p < 0) {
    throw new ArithmeticException("p cannot be negative. Invalid p: " + p);
if (p == 0)
    return 1;
if (n == 0)
    return 0;
if (n == 1)
...