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


Java MathRuntimeException.createNullPointerException方法代码示例

本文整理汇总了Java中org.apache.commons.math.MathRuntimeException.createNullPointerException方法的典型用法代码示例。如果您正苦于以下问题:Java MathRuntimeException.createNullPointerException方法的具体用法?Java MathRuntimeException.createNullPointerException怎么用?Java MathRuntimeException.createNullPointerException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math.MathRuntimeException的用法示例。


在下文中一共展示了MathRuntimeException.createNullPointerException方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: BigFraction

import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 *
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR);
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:50,代码来源:BigFraction.java

示例2: BigFraction

import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 *
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException("denominator must be different from 0");
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:50,代码来源:BigFraction.java

示例3: BigFraction

import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 * 
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException("denominator must be different from 0");
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:50,代码来源:BigFraction.java


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