当前位置: 首页>>代码示例>>Java>>正文


Java LocalizedFormats.OVERFLOW_IN_SUBTRACTION属性代码示例

本文整理汇总了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;

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:20,代码来源:FastMath.java

示例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;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:17,代码来源:ArithmeticUtils.java

示例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;

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:15,代码来源:FastMath.java

示例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;
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:17,代码来源:ArithmeticUtils.java


注:本文中的org.apache.commons.math3.exception.util.LocalizedFormats.OVERFLOW_IN_SUBTRACTION属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。