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

longpower(final long x, final long n, final long p)
Return x^n (mod p) Assumes x, n >= 0, p > 0, x < p, 0^0 = 1 Overflow may occur if p > 31 bits.
if (n == 0)
    return 1;
long tmp = power((x * x) % p, n / 2, p);
if (n % 2 != 0)
    tmp = (tmp * x) % p;
return tmp;
intpower(int base, int power)
Returns the integer result of base^power
int result = 1;
int absPower = Math.abs(power);
for (int p = 0; p < absPower; p++) {
    result *= base;
if (power < 0) {
    result = 1 / result;
return result;
intpower(int i)
Calculates 2 to the power i as a helper in determining timings for some of the operations.
if (i <= 0) {
    return 1;
} else if (i == 1) {
    return 2;
} else if (i == 2) {
    return 4;
} else if (i > 32) {
    return Integer.MAX_VALUE;
...
intpower(int val, int numOfPower)
power
for (int i = 0; i < numOfPower; i++) {
    val *= 10;
return val;
intpower(int x, int n)
Returns x to the power n.
return (int) (Math.pow(x, n));
longpower(long x, long y)
The power function for long arguments.
if (y < 0)
    throw new ArithmeticException("power to a negative integer is not sensible here.");
long r = 1;
for (long i = 0; i < y; i++)
    r *= x;
return r;
longpower2(int power)
Calculating the number 2 ^ stated figure, used by itob function to convert decimal / binary
long integer = 1;
for (int i = 0; i < power; i++) {
    integer *= 2;
return integer;
intpowerConverter(String _varSymbol)
Converts a unit prefix to power of base 10.
if (_varSymbol == null || _varSymbol.length() < 2) {
    return 0;
if (_varSymbol.startsWith("d")) {
    return -1;
} else if (_varSymbol.startsWith("c")) {
    return -2;
} else if (_varSymbol.startsWith("m") && _varSymbol.length() > 1) {
...
doublepowerLevelToDb(double value)
power Level To Db
return 10.0 * Math.log10(value);
doublepowerLevelToDb0(double value)
power Level To Db
double result = powerLevelToDb(value);
if (result < MIN_GAIN)
    return MIN_GAIN;
return result;