本文整理汇总了Java中org.apache.commons.math3.exception.util.LocalizedFormats.OVERFLOW_IN_ADDITION属性的典型用法代码示例。如果您正苦于以下问题:Java LocalizedFormats.OVERFLOW_IN_ADDITION属性的具体用法?Java LocalizedFormats.OVERFLOW_IN_ADDITION怎么用?Java LocalizedFormats.OVERFLOW_IN_ADDITION使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.math3.exception.util.LocalizedFormats
的用法示例。
在下文中一共展示了LocalizedFormats.OVERFLOW_IN_ADDITION属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subAndCheck
/**
* Subtract two long integers, checking for overflow.
*
* @param a Value.
* @param b Value.
* @return the difference {@code a - b}.
* @throws MathArithmeticException if the result can not be represented as a
* {@code long}.
* @since 1.2
*/
public static long subAndCheck(long a, long b) throws MathArithmeticException {
long ret;
if (b == Long.MIN_VALUE) {
if (a < 0) {
ret = a - b;
} else {
throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, a, -b);
}
} else {
// use additive inverse
ret = addAndCheck(a, -b, LocalizedFormats.OVERFLOW_IN_ADDITION);
}
return ret;
}
示例2: addExact
/** Add two numbers, detecting overflows.
* @param a first number to add
* @param b second number to add
* @return a+b if no overflows occur
* @exception MathArithmeticException if an overflow occurs
* @since 3.4
*/
public static int addExact(final int a, final int b) throws MathArithmeticException {
// compute sum
final int sum = a + b;
// check for overflow
if ((a ^ b) >= 0 && (sum ^ b) < 0) {
throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, a, b);
}
return sum;
}
示例3: subAndCheck
/**
* Subtract two long integers, checking for overflow.
*
* @param a Value.
* @param b Value.
* @return the difference {@code a - b}.
* @throws MathArithmeticException if the result can not be represented as a
* {@code long}.
* @since 1.2
*/
public static long subAndCheck(long a, long b) {
long ret;
if (b == Long.MIN_VALUE) {
if (a < 0) {
ret = a - b;
} else {
throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, a, -b);
}
} else {
// use additive inverse
ret = addAndCheck(a, -b, LocalizedFormats.OVERFLOW_IN_ADDITION);
}
return ret;
}
示例4: addAndCheck
/**
* Add two integers, checking for overflow.
*
* @param x an addend
* @param y an addend
* @return the sum {@code x+y}
* @throws MathArithmeticException if the result can not be represented
* as an {@code int}.
* @since 1.1
*/
public static int addAndCheck(int x, int y)
throws MathArithmeticException {
long s = (long)x + (long)y;
if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) {
throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, x, y);
}
return (int)s;
}
示例5: incrementExact
/** Increment a number, detecting overflows.
* @param n number to increment
* @return n+1 if no overflows occur
* @exception MathArithmeticException if an overflow occurs
* @since 3.4
*/
public static int incrementExact(final int n) throws MathArithmeticException {
if (n == Integer.MAX_VALUE) {
throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, n, 1);
}
return n + 1;
}
示例6: addAndCheck
/**
* Add two integers, checking for overflow.
*
* @param x an addend
* @param y an addend
* @return the sum {@code x+y}
* @throws MathArithmeticException if the result can not be represented
* as an {@code int}.
* @since 1.1
*/
public static int addAndCheck(int x, int y) {
long s = (long)x + (long)y;
if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) {
throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, x, y);
}
return (int)s;
}