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

Double[]PowerOutageDistr()
Power Outage Distr
return PowerOutageDistr;
StringpowerString(int power)
power String
float scaledPower = Math.abs(power);
String unit;
if (power >= 1000000) {
    scaledPower /= 1000000;
    unit = "mE";
} else if (power >= 1000) {
    scaledPower /= 1000;
    unit = "kE";
...
StringpowerString(int power)
power String
if (power == 1) {
    return "";
if (power < 0) {
    return "^(" + power + ")";
return "^" + power;
intpowerToInteger(String pow)
convert power to integer.
if (POWER_LOW.equalsIgnoreCase(pow)) {
    return 1;
} else if (POWER_MEDIUM.equalsIgnoreCase(pow)) {
    return 2;
} else if (POWER_HIGH.equalsIgnoreCase(pow)) {
    return 3;
return 0;
...
StringpowerTrim(String s)
power Trim
return s.replaceAll("^\\W+", "").replaceAll("\\W+$", "");
intpowerType(float power)
power Type
if (power < 400) {
    return 0;
int type = 1;
return (type += Float.valueOf((power - 400) / 400).intValue()) > 3 ? 3 : type;
longpowerX(long a, long b)
Cheap, unsafe, long power.
long x = 1;
while (b > 0) {
    x *= a;
    --b;
return x;
longpowExact(long x, int y)
Returns value of x raised in power y, throwing an exception if the result overflows a long.
if (y >= 0) {
    long z = 1L;
    while (true) {
        if ((y & 1) != 0)
            z = Math.multiplyExact(z, x);
        y >>>= 1;
        if (y == 0)
            break;
...
floatpowf(float v1, float v2)
powf
return (float) Math.pow(v1, v2);
doublepowi(double x, int p)
Fast loop for computing Math.pow(x, p) for p >= 0 integer.
if (p < 0) { 
    return Math.pow(x, p);
double ret = 1.;
for (; p > 0; p >>= 1) {
    if ((p & 1) == 1) {
        ret *= x;
    x *= x;
return ret;