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


Java LocalizedFormats.OVERFLOW_IN_ADDITION属性代码示例

本文整理汇总了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;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:24,代码来源:ArithmeticUtils.java

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

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

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

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

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

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

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


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