Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#OVERFLOW

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#OVERFLOW . 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 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Short.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static short copySign(short magnitude, short sign) {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Short.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return (short) -magnitude; // Flip sign.
    }
}
 
Example 2
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Integer.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static int copySign(int magnitude, int sign) {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Integer.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return -magnitude; // Flip sign.
    }
}
 
Example 3
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Long.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static long copySign(long magnitude, long sign)
    throws MathArithmeticException {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Long.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return -magnitude; // Flip sign.
    }
}
 
Example 4
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Byte.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static byte copySign(byte magnitude, byte sign) {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Byte.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return (byte) -magnitude; // Flip sign.
    }
}
 
Example 5
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Long.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static long copySign(long magnitude, long sign)
    throws MathArithmeticException {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Long.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return -magnitude; // Flip sign.
    }
}
 
Example 6
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Integer.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static int copySign(int magnitude, int sign)
        throws MathArithmeticException {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Integer.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return -magnitude; // Flip sign.
    }
}
 
Example 7
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Short.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static short copySign(short magnitude, short sign)
        throws MathArithmeticException {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Short.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return (short) -magnitude; // Flip sign.
    }
}
 
Example 8
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Integer.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static int copySign(int magnitude, int sign)
        throws MathArithmeticException {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Integer.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return -magnitude; // Flip sign.
    }
}
 
Example 9
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Integer.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static int copySign(int magnitude, int sign)
        throws MathArithmeticException {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Integer.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return -magnitude; // Flip sign.
    }
}
 
Example 10
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Long.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static long copySign(long magnitude, long sign) {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Long.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return -magnitude; // Flip sign.
    }
}
 
Example 11
Source File: FastMath.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Convert a long to interger, detecting overflows
 * @param n number to convert to int
 * @return integer with same valie as n if no overflows occur
 * @exception MathArithmeticException if n cannot fit into an int
 * @since 3.4
 */
public static int toIntExact(final long n) throws MathArithmeticException {
    if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    }
    return (int) n;
}
 
Example 12
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Byte.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static byte copySign(byte magnitude, byte sign) {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Byte.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return (byte) -magnitude; // Flip sign.
    }
}
 
Example 13
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Long.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static long copySign(long magnitude, long sign)
    throws MathArithmeticException {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Long.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return -magnitude; // Flip sign.
    }
}
 
Example 14
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Integer.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static int copySign(int magnitude, int sign)
        throws MathArithmeticException {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Integer.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return -magnitude; // Flip sign.
    }
}
 
Example 15
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Short.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static short copySign(short magnitude, short sign)
        throws MathArithmeticException {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Short.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return (short) -magnitude; // Flip sign.
    }
}
 
Example 16
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Byte.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static byte copySign(byte magnitude, byte sign)
    throws MathArithmeticException {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Byte.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return (byte) -magnitude; // Flip sign.
    }
}
 
Example 17
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Long.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static long copySign(long magnitude, long sign)
    throws MathArithmeticException {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Long.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return -magnitude; // Flip sign.
    }
}
 
Example 18
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Byte.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static byte copySign(byte magnitude, byte sign)
    throws MathArithmeticException {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Byte.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return (byte) -magnitude; // Flip sign.
    }
}
 
Example 19
Source File: MathUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the first argument with the sign of the second argument.
 *
 * @param magnitude Magnitude of the returned value.
 * @param sign Sign of the returned value.
 * @return a value with magnitude equal to {@code magnitude} and with the
 * same sign as the {@code sign} argument.
 * @throws MathArithmeticException if {@code magnitude == Short.MIN_VALUE}
 * and {@code sign >= 0}.
 */
public static short copySign(short magnitude, short sign)
        throws MathArithmeticException {
    if ((magnitude >= 0 && sign >= 0) ||
        (magnitude < 0 && sign < 0)) { // Sign is OK.
        return magnitude;
    } else if (sign >= 0 &&
               magnitude == Short.MIN_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    } else {
        return (short) -magnitude; // Flip sign.
    }
}
 
Example 20
Source File: FastMath.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Convert a long to interger, detecting overflows
 * @param n number to convert to int
 * @return integer with same valie as n if no overflows occur
 * @exception MathArithmeticException if n cannot fit into an int
 * @since 3.4
 */
public static int toIntExact(final long n) throws MathArithmeticException {
    if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
    }
    return (int) n;
}