org.apache.commons.math.exception.NullArgumentException Java Examples

The following examples show how to use org.apache.commons.math.exception.NullArgumentException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BigFraction_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>
 * Subtracts the value of another fraction from the value of this one,
 * returning the result in reduced form.
 * </p>
 *
 * @param fraction {@link BigFraction} to subtract, must not be {@code null}.
 * @return a {@link BigFraction} instance with the resulting values
 * @throws NullArgumentException if the {@code fraction} is {@code null}.
 */
public BigFraction subtract(final BigFraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (ZERO.equals(fraction)) {
        return this;
    }

    BigInteger num = null;
    BigInteger den = null;
    if (denominator.equals(fraction.denominator)) {
        num = numerator.subtract(fraction.numerator);
        den = denominator;
    } else {
        num = (numerator.multiply(fraction.denominator)).subtract((fraction.numerator).multiply(denominator));
        den = denominator.multiply(fraction.denominator);
    }
    return new BigFraction(num, den);

}
 
Example #2
Source File: BigFraction_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>
 * Subtracts the value of another fraction from the value of this one,
 * returning the result in reduced form.
 * </p>
 *
 * @param fraction {@link BigFraction} to subtract, must not be {@code null}.
 * @return a {@link BigFraction} instance with the resulting values
 * @throws NullArgumentException if the {@code fraction} is {@code null}.
 */
public BigFraction subtract(final BigFraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (ZERO.equals(fraction)) {
        return this;
    }

    BigInteger num = null;
    BigInteger den = null;
    if (denominator.equals(fraction.denominator)) {
        num = numerator.subtract(fraction.numerator);
        den = denominator;
    } else {
        num = (numerator.multiply(fraction.denominator)).subtract((fraction.numerator).multiply(denominator));
        den = denominator.multiply(fraction.denominator);
    }
    return new BigFraction(num, den);

}
 
Example #3
Source File: Math_41_Variance_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 *
 * @param source Variance to copy
 * @param dest Variance to copy to
 * @throws NullArgumentException if either source or dest is null
 */
public static void copy(Variance source, Variance dest)
    throws NullArgumentException {
    MathUtils.checkNotNull(source);
    MathUtils.checkNotNull(dest);
    dest.setData(source.getDataRef());
    dest.moment = source.moment.copy();
    dest.isBiasCorrected = source.isBiasCorrected;
    dest.incMoment = source.incMoment;
}
 
Example #4
Source File: 1_Variance.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 *
 * @param source Variance to copy
 * @param dest Variance to copy to
 * @throws NullArgumentException if either source or dest is null
 */
public static void copy(Variance source, Variance dest)
    throws NullArgumentException {
    MathUtils.checkNotNull(source);
    MathUtils.checkNotNull(dest);
    dest.setData(source.getDataRef());
    dest.moment = source.moment.copy();
    dest.isBiasCorrected = source.isBiasCorrected;
    dest.incMoment = source.incMoment;
}
 
Example #5
Source File: Cardumen_00167_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 *
 * @param source Variance to copy
 * @param dest Variance to copy to
 * @throws NullArgumentException if either source or dest is null
 */
public static void copy(Variance source, Variance dest)
    throws NullArgumentException {
    MathUtils.checkNotNull(source);
    MathUtils.checkNotNull(dest);
    dest.setData(source.getDataRef());
    dest.moment = source.moment.copy();
    dest.isBiasCorrected = source.isBiasCorrected;
    dest.incMoment = source.incMoment;
}
 
Example #6
Source File: Math_41_Variance_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 *
 * @param source Variance to copy
 * @param dest Variance to copy to
 * @throws NullArgumentException if either source or dest is null
 */
public static void copy(Variance source, Variance dest)
    throws NullArgumentException {
    MathUtils.checkNotNull(source);
    MathUtils.checkNotNull(dest);
    dest.setData(source.getDataRef());
    dest.moment = source.moment.copy();
    dest.isBiasCorrected = source.isBiasCorrected;
    dest.incMoment = source.incMoment;
}
 
Example #7
Source File: Math_58_GaussianFitter_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Constructs instance with the specified observed points.
 *
 * @param observations observed points upon which should base guess
 */
public ParameterGuesser(WeightedObservedPoint[] observations) {
    if (observations == null) {
        throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
    }
    if (observations.length < 3) {
        throw new NumberIsTooSmallException(observations.length, 3, true);
    }
    this.observations = observations.clone();
}
 
Example #8
Source File: Nopol2017_0075_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Validates parameters to ensure they are appropriate for the evaluation of
 * the {@link #value(double,double[])} and {@link #gradient(double,double[])}
 * methods.
 *
 * @param param Values of norm, mean and standard deviation.
 * @throws NullArgumentException if {@code param} is {@code null}.
 * @throws DimensionMismatchException if the size of {@code param} is
 * not 3.
 * @throws NotStrictlyPositiveException if {@code param[2]} is negative.
 */
private void validateParameters(double[] param) {
    if (param == null) {
        throw new NullArgumentException();
    }
    if (param.length != 3) {
        throw new DimensionMismatchException(param.length, 3);
    }
    if (param[2] <= 0) {
        throw new NotStrictlyPositiveException(param[2]);
    }
}
 
Example #9
Source File: jMutRepair_0012_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Validates parameters to ensure they are appropriate for the evaluation of
 * the {@link #value(double,double[])} and {@link #gradient(double,double[])}
 * methods.
 *
 * @param param Values of norm, mean and standard deviation.
 * @throws NullArgumentException if {@code param} is {@code null}.
 * @throws DimensionMismatchException if the size of {@code param} is
 * not 3.
 * @throws NotStrictlyPositiveException if {@code param[2]} is negative.
 */
private void validateParameters(double[] param) {
    if (param == null) {
        throw new NullArgumentException();
    }
    if (param.length != 3) {
        throw new DimensionMismatchException(param.length, 3);
    }
    if (param[2] == 0) {
        throw new NotStrictlyPositiveException(param[2]);
    }
}
 
Example #10
Source File: Cardumen_0043_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 *
 * @param source Variance to copy
 * @param dest Variance to copy to
 * @throws NullArgumentException if either source or dest is null
 */
public static void copy(Variance source, Variance dest)
    throws NullArgumentException {
    MathUtils.checkNotNull(source);
    MathUtils.checkNotNull(dest);
    dest.setData(source.getDataRef());
    dest.moment = source.moment.copy();
    dest.isBiasCorrected = source.isBiasCorrected;
    dest.incMoment = source.incMoment;
}
 
Example #11
Source File: Arja_0037_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Constructs instance with the specified observed points.
 *
 * @param observations observed points upon which should base guess
 */
public ParameterGuesser(WeightedObservedPoint[] observations) {
    if (observations == null) {
        throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
    }
    if (observations.length < 3) {
        throw new NumberIsTooSmallException(observations.length, 3, true);
    }
    this.observations = observations.clone();
}
 
Example #12
Source File: Arja_0037_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Constructs instance with the specified observed points.
 *
 * @param observations observed points upon which should base guess
 */
public ParameterGuesser(WeightedObservedPoint[] observations) {
    if (observations == null) {
        throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
    }
    if (observations.length < 3) {
        throw new NumberIsTooSmallException(observations.length, 3, true);
    }
    this.observations = observations.clone();
}
 
Example #13
Source File: Elixir_0029_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Constructs instance with the specified observed points.
 *
 * @param observations observed points upon which should base guess
 */
public ParameterGuesser(WeightedObservedPoint[] observations) {
    if (observations == null) {
        throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
    }
    if (observations.length < 3) {
        throw new NumberIsTooSmallException(observations.length, 3, true);
    }
    this.observations = observations.clone();
}
 
Example #14
Source File: Cardumen_00261_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 *
 * @param source Variance to copy
 * @param dest Variance to copy to
 * @throws NullArgumentException if either source or dest is null
 */
public static void copy(Variance source, Variance dest)
    throws NullArgumentException {
    MathUtils.checkNotNull(source);
    MathUtils.checkNotNull(dest);
    dest.setData(source.getDataRef());
    dest.moment = source.moment.copy();
    dest.isBiasCorrected = source.isBiasCorrected;
    dest.incMoment = source.incMoment;
}
 
Example #15
Source File: Cardumen_00112_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 *
 * @param source Variance to copy
 * @param dest Variance to copy to
 * @throws NullArgumentException if either source or dest is null
 */
public static void copy(Variance source, Variance dest)
    throws NullArgumentException {
    MathUtils.checkNotNull(source);
    MathUtils.checkNotNull(dest);
    dest.setData(source.getDataRef());
    dest.moment = source.moment.copy();
    dest.isBiasCorrected = source.isBiasCorrected;
    dest.incMoment = source.incMoment;
}
 
Example #16
Source File: Nopol2017_0075_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Validates parameters to ensure they are appropriate for the evaluation of
 * the {@link #value(double,double[])} and {@link #gradient(double,double[])}
 * methods.
 *
 * @param param Values of norm, mean and standard deviation.
 * @throws NullArgumentException if {@code param} is {@code null}.
 * @throws DimensionMismatchException if the size of {@code param} is
 * not 3.
 * @throws NotStrictlyPositiveException if {@code param[2]} is negative.
 */
private void validateParameters(double[] param) {
    if (param == null) {
        throw new NullArgumentException();
    }
    if (param.length != 3) {
        throw new DimensionMismatchException(param.length, 3);
    }
    if ((param[2]) == 0) {
        if (param[2] <= 0) {
            throw new NotStrictlyPositiveException(param[2]);
        }
    }
}
 
Example #17
Source File: Cardumen_00217_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 *
 * @param source Variance to copy
 * @param dest Variance to copy to
 * @throws NullArgumentException if either source or dest is null
 */
public static void copy(Variance source, Variance dest)
    throws NullArgumentException {
    MathUtils.checkNotNull(source);
    MathUtils.checkNotNull(dest);
    dest.setData(source.getDataRef());
    dest.moment = source.moment.copy();
    dest.isBiasCorrected = source.isBiasCorrected;
    dest.incMoment = source.incMoment;
}
 
Example #18
Source File: Math_36_BigFraction_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * <p>
 * Multiplies the value of this fraction by another, returning the result in
 * reduced form.
 * </p>
 *
 * @param fraction Fraction to multiply by, must not be {@code null}.
 * @return a {@link BigFraction} instance with the resulting values.
 * @throws NullArgumentException if {@code fraction} is {@code null}.
 */
public BigFraction multiply(final BigFraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (numerator.equals(BigInteger.ZERO) ||
        fraction.numerator.equals(BigInteger.ZERO)) {
        return ZERO;
    }
    return new BigFraction(numerator.multiply(fraction.numerator),
                           denominator.multiply(fraction.denominator));
}
 
Example #19
Source File: Cardumen_00113_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns a {@code Complex} whose value is {@code this * factor}.
 * Implements preliminary checks for {@code NaN} and infinity followed by
 * the definitional formula:
 * <pre>
 *  <code>
 *   (a + bi)(c + di) = (ac - bd) + (ad + bc)i
 *  </code>
 * </pre>
 * Returns {@link #NaN} if either {@code this} or {@code factor} has one or
 * more {@code NaN} parts.
 * <br/>
 * Returns {@link #INF} if neither {@code this} nor {@code factor} has one
 * or more {@code NaN} parts and if either {@code this} or {@code factor}
 * has one or more infinite parts (same result is returned regardless of
 * the sign of the components).
 * <br/>
 * Returns finite values in components of the result per the definitional
 * formula in all remaining cases.
 *
 * @param  factor value to be multiplied by this {@code Complex}.
 * @return {@code this * factor}.
 * @throws NullArgumentException if {@code factor} is {@code null}.
 */
public Complex multiply(Complex factor)
    throws NullArgumentException {
    MathUtils.checkNotNull(factor);
    if (isNaN || factor.isNaN) {
        return NaN;
    }
    if (Double.isInfinite(real) ||
        Double.isInfinite(imaginary) ||
        Double.isInfinite(factor.real) ||
        Double.isInfinite(factor.imaginary)) {
        // we don't use isInfinite() to avoid testing for NaN again
        return INF;
    }
    return createComplex(real * factor.real - imaginary * factor.imaginary,
                         real * factor.imaginary + imaginary * factor.real);
}
 
Example #20
Source File: Cardumen_00262_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns a {@code Complex} whose value is {@code this * factor}.
 * Implements preliminary checks for {@code NaN} and infinity followed by
 * the definitional formula:
 * <pre>
 *  <code>
 *   (a + bi)(c + di) = (ac - bd) + (ad + bc)i
 *  </code>
 * </pre>
 * Returns {@link #NaN} if either {@code this} or {@code factor} has one or
 * more {@code NaN} parts.
 * <br/>
 * Returns {@link #INF} if neither {@code this} nor {@code factor} has one
 * or more {@code NaN} parts and if either {@code this} or {@code factor}
 * has one or more infinite parts (same result is returned regardless of
 * the sign of the components).
 * <br/>
 * Returns finite values in components of the result per the definitional
 * formula in all remaining cases.
 *
 * @param  factor value to be multiplied by this {@code Complex}.
 * @return {@code this * factor}.
 * @throws NullArgumentException if {@code factor} is {@code null}.
 */
public Complex multiply(Complex factor)
    throws NullArgumentException {
    MathUtils.checkNotNull(factor);
    if (isNaN || factor.isNaN) {
        return NaN;
    }
    if (Double.isInfinite(real) ||
        Double.isInfinite(imaginary) ||
        Double.isInfinite(factor.real) ||
        Double.isInfinite(factor.imaginary)) {
        // we don't use isInfinite() to avoid testing for NaN again
        return INF;
    }
    return createComplex(real * factor.real - imaginary * factor.imaginary,
                         real * factor.imaginary + imaginary * factor.real);
}
 
Example #21
Source File: Math_43_SummaryStatistics_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Copies source to dest.
 * <p>Neither source nor dest can be null.</p>
 *
 * @param source SummaryStatistics to copy
 * @param dest SummaryStatistics to copy to
 * @throws NullArgumentException if either source or dest is null
 */
public static void copy(SummaryStatistics source, SummaryStatistics dest)
    throws NullArgumentException {
    MathUtils.checkNotNull(source);
    MathUtils.checkNotNull(dest);
    dest.maxImpl = source.maxImpl.copy();
    dest.minImpl = source.minImpl.copy();
    dest.sumImpl = source.sumImpl.copy();
    dest.sumLogImpl = source.sumLogImpl.copy();
    dest.sumsqImpl = source.sumsqImpl.copy();
    dest.secondMoment = source.secondMoment.copy();
    dest.n = source.n;

    // Keep commons-math supplied statistics with embedded moments in synch
    if (source.getVarianceImpl() instanceof Variance) {
        dest.varianceImpl = new Variance(dest.secondMoment);
    } else {
        dest.varianceImpl = source.varianceImpl.copy();
    }
    if (source.meanImpl instanceof Mean) {
        dest.meanImpl = new Mean(dest.secondMoment);
    } else {
        dest.meanImpl = source.meanImpl.copy();
    }
    if (source.getGeoMeanImpl() instanceof GeometricMean) {
        dest.geoMeanImpl = new GeometricMean((SumOfLogs) dest.sumLogImpl);
    } else {
        dest.geoMeanImpl = source.geoMeanImpl.copy();
    }

    // Make sure that if stat == statImpl in source, same
    // holds in dest; otherwise copy stat
    if (source.geoMean == source.geoMeanImpl) {
        dest.geoMean = (GeometricMean) dest.geoMeanImpl;
    } else {
        GeometricMean.copy(source.geoMean, dest.geoMean);
    }
    if (source.max == source.maxImpl) {
        dest.max = (Max) dest.maxImpl;
    } else {
        Max.copy(source.max, dest.max);
    }
    if (source.mean == source.meanImpl) {
        dest.mean = (Mean) dest.meanImpl;
    } else {
        Mean.copy(source.mean, dest.mean);
    }
    if (source.min == source.minImpl) {
        dest.min = (Min) dest.minImpl;
    } else {
        Min.copy(source.min, dest.min);
    }
    if (source.sum == source.sumImpl) {
        dest.sum = (Sum) dest.sumImpl;
    } else {
        Sum.copy(source.sum, dest.sum);
    }
    if (source.variance == source.varianceImpl) {
        dest.variance = (Variance) dest.varianceImpl;
    } else {
        Variance.copy(source.variance, dest.variance);
    }
    if (source.sumLog == source.sumLogImpl) {
        dest.sumLog = (SumOfLogs) dest.sumLogImpl;
    } else {
        SumOfLogs.copy(source.sumLog, dest.sumLog);
    }
    if (source.sumsq == source.sumsqImpl) {
        dest.sumsq = (SumOfSquares) dest.sumsqImpl;
    } else {
        SumOfSquares.copy(source.sumsq, dest.sumsq);
    }
}
 
Example #22
Source File: 1_Complex.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
/**
     * Return the sum of this complex number and the given complex number.
     * <p>
     * Uses the definitional formula
     * <pre>
     * (a + bi) + (c + di) = (a+c) + (b+d)i
     * </pre></p>
     * <p>
     * If either this or <code>rhs</code> has a NaN value in either part,
     * {@link #NaN} is returned; otherwise Infinite and NaN values are
     * returned in the parts of the result according to the rules for
     * {@link java.lang.Double} arithmetic.</p>
     *
     * @param rhs the other complex number
     * @return the complex number sum
     * @throws NullArgumentException if <code>rhs</code> is null
     */
    public Complex add(Complex rhs)
        throws NullArgumentException {
// start of generated patch
MathUtils.checkNotNull(rhs);
if(isNaN||rhs.isNaN){
return NaN;
}
return createComplex(real+rhs.getReal(),imaginary+rhs.getImaginary());
// end of generated patch
/* start of original code
        MathUtils.checkNotNull(rhs);
        return createComplex(real + rhs.getReal(),
            imaginary + rhs.getImaginary());
 end of original code*/
    }
 
Example #23
Source File: Math_47_Complex_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns a {@code Complex} whose value is {@code this * factor}.
 * Implements preliminary checks for {@code NaN} and infinity followed by
 * the definitional formula:
 * <pre>
 *  <code>
 *   (a + bi)(c + di) = (ac - bd) + (ad + bc)i
 *  </code>
 * </pre>
 * Returns {@link #NaN} if either {@code this} or {@code factor} has one or
 * more {@code NaN} parts.
 * <br/>
 * Returns {@link #INF} if neither {@code this} nor {@code factor} has one
 * or more {@code NaN} parts and if either {@code this} or {@code factor}
 * has one or more infinite parts (same result is returned regardless of
 * the sign of the components).
 * <br/>
 * Returns finite values in components of the result per the definitional
 * formula in all remaining cases.
 *
 * @param  factor value to be multiplied by this {@code Complex}.
 * @return {@code this * factor}.
 * @throws NullArgumentException if {@code factor} is {@code null}.
 */
public Complex multiply(Complex factor)
    throws NullArgumentException {
    MathUtils.checkNotNull(factor);
    if (isNaN || factor.isNaN) {
        return NaN;
    }
    if (Double.isInfinite(real) ||
        Double.isInfinite(imaginary) ||
        Double.isInfinite(factor.real) ||
        Double.isInfinite(factor.imaginary)) {
        // we don't use isInfinite() to avoid testing for NaN again
        return INF;
    }
    return createComplex(real * factor.real - imaginary * factor.imaginary,
                         real * factor.imaginary + imaginary * factor.real);
}
 
Example #24
Source File: Cardumen_00113_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns a {@code Complex} whose value is {@code this * factor}.
 * Implements preliminary checks for {@code NaN} and infinity followed by
 * the definitional formula:
 * <pre>
 *  <code>
 *   (a + bi)(c + di) = (ac - bd) + (ad + bc)i
 *  </code>
 * </pre>
 * Returns {@link #NaN} if either {@code this} or {@code factor} has one or
 * more {@code NaN} parts.
 * <br/>
 * Returns {@link #INF} if neither {@code this} nor {@code factor} has one
 * or more {@code NaN} parts and if either {@code this} or {@code factor}
 * has one or more infinite parts (same result is returned regardless of
 * the sign of the components).
 * <br/>
 * Returns finite values in components of the result per the definitional
 * formula in all remaining cases.
 *
 * @param  factor value to be multiplied by this {@code Complex}.
 * @return {@code this * factor}.
 * @throws NullArgumentException if {@code factor} is {@code null}.
 */
public Complex multiply(Complex factor)
    throws NullArgumentException {
    MathUtils.checkNotNull(factor);
    if (isNaN || factor.isNaN) {
        return NaN;
    }
    if (Double.isInfinite(real) ||
        Double.isInfinite(imaginary) ||
        Double.isInfinite(factor.real) ||
        Double.isInfinite(factor.imaginary)) {
        // we don't use isInfinite() to avoid testing for NaN again
        return INF;
    }
    return createComplex(real * factor.real - imaginary * factor.imaginary,
                         real * factor.imaginary + imaginary * factor.real);
}
 
Example #25
Source File: Cardumen_00218_t.java    From coming with MIT License 3 votes vote down vote up
/**
 * Returns a {@code Complex} whose value is
 * {@code (this - subtrahend)}.
 * Uses the definitional formula
 * <pre>
 *  <code>
 *   (a + bi) - (c + di) = (a-c) + (b-d)i
 *  </code>
 * </pre>
 * If either {@code this} or {@code subtrahend} has a {@code NaN]} value in either part,
 * {@link #NaN} is returned; otherwise infinite and {@code NaN} values are
 * returned in the parts of the result according to the rules for
 * {@link java.lang.Double} arithmetic.
 *
 * @param  subtrahend value to be subtracted from this {@code Complex}.
 * @return {@code this - subtrahend}.
 * @throws NullArgumentException if {@code subtrahend} is {@code null}.
 */
public Complex subtract(Complex subtrahend)
    throws NullArgumentException {
    MathUtils.checkNotNull(subtrahend);
    if (isNaN || subtrahend.isNaN) {
        return NaN;
    }

    return createComplex(real - subtrahend.getReal(),
                         imaginary - subtrahend.getImaginary());
}
 
Example #26
Source File: Cardumen_00218_s.java    From coming with MIT License 3 votes vote down vote up
/**
 * Returns a {@code Complex} whose value is
 * {@code (this + addend)}.
 * Uses the definitional formula
 * <pre>
 *  <code>
 *   (a + bi) + (c + di) = (a+c) + (b+d)i
 *  </code>
 * </pre>
 * <br/>
 * If either {@code this} or {@code addend} has a {@code NaN} value in
 * either part, {@link #NaN} is returned; otherwise {@code Infinite}
 * and {@code NaN} values are returned in the parts of the result
 * according to the rules for {@link java.lang.Double} arithmetic.
 *
 * @param  addend Value to be added to this {@code Complex}.
 * @return {@code this + addend}.
 * @throws NullArgumentException if {@code addend} is {@code null}.
 */
public Complex add(Complex addend) throws NullArgumentException {
    MathUtils.checkNotNull(addend);
    if (isNaN || addend.isNaN) {
        return NaN;
    }

    return createComplex(real + addend.getReal(),
                         imaginary + addend.getImaginary());
}
 
Example #27
Source File: Variance.java    From SimFix with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the variance of the entries in the input array, or
 * <code>Double.NaN</code> if the array is empty.
 * <p>
 * See {@link Variance} for details on the computing algorithm.</p>
 * <p>
 * Returns 0 for a single-value (i.e. length = 1) sample.</p>
 * <p>
 * Throws <code>IllegalArgumentException</code> if the array is null.</p>
 * <p>
 * Does not change the internal state of the statistic.</p>
 *
 * @param values the input array
 * @return the variance of the values or Double.NaN if length = 0
 * @throws IllegalArgumentException if the array is null
 */
@Override
public double evaluate(final double[] values) {
    if (values == null) {
        throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
    }
    return evaluate(values, 0, values.length);
}
 
Example #28
Source File: JGenProg2015_007_t.java    From coming with MIT License 3 votes vote down vote up
/**
 * Return the product of this complex number and the given complex number.
 * <p>
 * Implements preliminary checks for NaN and infinity followed by
 * the definitional formula:
 * <pre><code>
 * (a + bi)(c + di) = (ac - bd) + (ad + bc)i
 * </code></pre>
 * </p>
 * <p>
 * Returns {@link #NaN} if either this or <code>rhs</code> has one or more
 * NaN parts.
 * </p>
 * Returns {@link #INF} if neither this nor <code>rhs</code> has one or more
 * NaN parts and if either this or <code>rhs</code> has one or more
 * infinite parts (same result is returned regardless of the sign of the
 * components).
 * </p>
 * <p>
 * Returns finite values in components of the result per the
 * definitional formula in all remaining cases.
 *  </p>
 *
 * @param rhs the other complex number
 * @return the complex number product
 * @throws NullArgumentException if <code>rhs</code> is null
 */
public Complex multiply(Complex rhs)
    throws NullArgumentException {
    MathUtils.checkNotNull(rhs);
    if (isNaN || rhs.isNaN) {
        return NaN;
    }
    if (Double.isInfinite(real) || Double.isInfinite(imaginary) ||
        Double.isInfinite(rhs.real)|| Double.isInfinite(rhs.imaginary)) {
        // we don't use Complex.isInfinite() to avoid testing for NaN again
        return INF;
    }
    return createComplex(real * rhs.real - imaginary * rhs.imaginary,
            real * rhs.imaginary + imaginary * rhs.real);
}
 
Example #29
Source File: JGenProg2017_0028_s.java    From coming with MIT License 3 votes vote down vote up
/**
 * Return the sum of this complex number and the given complex number.
 * <p>
 * Uses the definitional formula
 * <pre>
 * (a + bi) + (c + di) = (a+c) + (b+d)i
 * </pre></p>
 * <p>
 * If either this or <code>rhs</code> has a NaN value in either part,
 * {@link #NaN} is returned; otherwise Infinite and NaN values are
 * returned in the parts of the result according to the rules for
 * {@link java.lang.Double} arithmetic.</p>
 *
 * @param rhs the other complex number
 * @return the complex number sum
 * @throws NullArgumentException if <code>rhs</code> is null
 */
public Complex add(Complex rhs)
    throws NullArgumentException {
    MathUtils.checkNotNull(rhs);
    return createComplex(real + rhs.getReal(),
        imaginary + rhs.getImaginary());
}
 
Example #30
Source File: Math_46_Complex_s.java    From coming with MIT License 3 votes vote down vote up
/**
 * Returns a {@code Complex} whose value is
 * {@code (this - subtrahend)}.
 * Uses the definitional formula
 * <pre>
 *  <code>
 *   (a + bi) - (c + di) = (a-c) + (b-d)i
 *  </code>
 * </pre>
 * If either {@code this} or {@code subtrahend} has a {@code NaN]} value in either part,
 * {@link #NaN} is returned; otherwise infinite and {@code NaN} values are
 * returned in the parts of the result according to the rules for
 * {@link java.lang.Double} arithmetic.
 *
 * @param  subtrahend value to be subtracted from this {@code Complex}.
 * @return {@code this - subtrahend}.
 * @throws NullArgumentException if {@code subtrahend} is {@code null}.
 */
public Complex subtract(Complex subtrahend)
    throws NullArgumentException {
    MathUtils.checkNotNull(subtrahend);
    if (isNaN || subtrahend.isNaN) {
        return NaN;
    }

    return createComplex(real - subtrahend.getReal(),
                         imaginary - subtrahend.getImaginary());
}