Java Code Examples for org.apache.commons.math.exception.util.LocalizedFormats#EXPONENT

The following examples show how to use org.apache.commons.math.exception.util.LocalizedFormats#EXPONENT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise an int to a long power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static int pow(final int k, long e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    int result = 1;
    int k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;
}
 
Example 2
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise a long to an int power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static long pow(final long k, int e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    long result = 1l;
    long k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;
}
 
Example 3
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise an int to a long power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static int pow(final int k, long e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    int result = 1;
    int k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;
}
 
Example 4
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise an int to an int power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static int pow(final int k, int e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    int result = 1;
    int k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;
}
 
Example 5
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise a BigInteger to a BigInteger power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static BigInteger pow(final BigInteger k, BigInteger e) {
    if (e.compareTo(BigInteger.ZERO) < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    BigInteger result = BigInteger.ONE;
    BigInteger k2p    = k;
    while (!BigInteger.ZERO.equals(e)) {
        if (e.testBit(0)) {
            result = result.multiply(k2p);
        }
        k2p = k2p.multiply(k2p);
        e = e.shiftRight(1);
    }

    return result;
}
 
Example 6
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise a BigInteger to a long power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static BigInteger pow(final BigInteger k, long e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    BigInteger result = BigInteger.ONE;
    BigInteger k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result = result.multiply(k2p);
        }
        k2p = k2p.multiply(k2p);
        e = e >> 1;
    }

    return result;

}
 
Example 7
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise a long to a long power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static long pow(final long k, long e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    long result = 1l;
    long k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;
}
 
Example 8
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise a long to an int power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static long pow(final long k, int e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    long result = 1l;
    long k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;
}
 
Example 9
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise an int to an int power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static int pow(final int k, int e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    int result = 1;
    int k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;
}
 
Example 10
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise a BigInteger to a BigInteger power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static BigInteger pow(final BigInteger k, BigInteger e) {
    if (e.compareTo(BigInteger.ZERO) < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    BigInteger result = BigInteger.ONE;
    BigInteger k2p    = k;
    while (!BigInteger.ZERO.equals(e)) {
        if (e.testBit(0)) {
            result = result.multiply(k2p);
        }
        k2p = k2p.multiply(k2p);
        e = e.shiftRight(1);
    }

    return result;
}
 
Example 11
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise a BigInteger to a BigInteger power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static BigInteger pow(final BigInteger k, BigInteger e) {
    if (e.compareTo(BigInteger.ZERO) < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    BigInteger result = BigInteger.ONE;
    BigInteger k2p    = k;
    while (!BigInteger.ZERO.equals(e)) {
        if (e.testBit(0)) {
            result = result.multiply(k2p);
        }
        k2p = k2p.multiply(k2p);
        e = e.shiftRight(1);
    }

    return result;
}
 
Example 12
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise a BigInteger to a long power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static BigInteger pow(final BigInteger k, long e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    BigInteger result = BigInteger.ONE;
    BigInteger k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result = result.multiply(k2p);
        }
        k2p = k2p.multiply(k2p);
        e = e >> 1;
    }

    return result;

}
 
Example 13
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise a long to a long power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static long pow(final long k, long e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    long result = 1l;
    long k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;
}
 
Example 14
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise a long to an int power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static long pow(final long k, int e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    long result = 1l;
    long k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;
}
 
Example 15
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise an int to a long power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static int pow(final int k, long e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    int result = 1;
    int k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;
}
 
Example 16
Source File: MathUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Raise an int to an int power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static int pow(final int k, int e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    int result = 1;
    int k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;
}
 
Example 17
Source File: ZipfDistributionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new Zipf distribution with the given number of elements and
 * exponent.
 *
 * @param numberOfElements Number of elements.
 * @param exponent Exponent.
 * @exception NotStrictlyPositiveException if {@code numberOfElements <= 0}
 * or {@code exponent <= 0}.
 */
public ZipfDistributionImpl(final int numberOfElements,
                            final double exponent) {
    if (numberOfElements <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.DIMENSION,
                                               numberOfElements);
    }
    if (exponent <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.EXPONENT,
                                               exponent);
    }

    this.numberOfElements = numberOfElements;
    this.exponent = exponent;
}
 
Example 18
Source File: MathUtils.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Raise a BigInteger to an int power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static BigInteger pow(final BigInteger k, int e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    return k.pow(e);
}
 
Example 19
Source File: MathUtils.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Raise a BigInteger to an int power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static BigInteger pow(final BigInteger k, int e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    return k.pow(e);
}
 
Example 20
Source File: MathUtils.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Raise a BigInteger to an int power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static BigInteger pow(final BigInteger k, int e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    return k.pow(e);
}