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