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

longpow10(final int exponent)
A very efficient function to compute powers of 10.
return POWER10[exponent];
doublepow10(int degree)
Adapted from com.devexperts.dxpro.common.util.MathUtils.
double pow;
if (degree >= 0) {
    pow = 1;
    for (int i = 0; i < degree; i++) {
        pow *= 10;
} else {
    pow = 0.1;
...
doublepow10(int n)
pow
if (n == 0)
    return 1;
else if (n > 0) {
    double d = 1;
    for (int i = 0; i < n; i++)
        d = d * 10.;
    return d;
} else {
...
floatpow16(float a)
pow
a = pow4(a);
return pow4(a);
doublepow2(double base, double power)
pow
double result = 1;
while (power != 0) {
    if (power > 0) {
        --power;
        result *= base;
    } else {
        result /= base;
        ++power;
...
doublepow2(double num)
pow
return num * num;
doublepow2(double x, int n)
Alternate implementation of the power method.
if (x == 0 && n <= 0)
    throw new IllegalArgumentException("x is zero and n=" + n);
else if (n == 0)
    return 1;
else if (n > 0)
    return x * pow2(x, n - 1);
else
    return 1 / pow2(x, -n);
...
intpow2(final int a)
pow
return a * a;
intpow2(final int n)
Return 2^n.
return 1 << n;
intpow2(final int x)
Simple 2^x
if (x <= 0) {
    return 1;
return 2 << x - 1;