本文整理汇总了Java中org.apache.commons.math3.exception.util.LocalizedFormats.FRACTION属性的典型用法代码示例。如果您正苦于以下问题:Java LocalizedFormats.FRACTION属性的具体用法?Java LocalizedFormats.FRACTION怎么用?Java LocalizedFormats.FRACTION使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.math3.exception.util.LocalizedFormats
的用法示例。
在下文中一共展示了LocalizedFormats.FRACTION属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subtract
/**
* <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 (fraction.numerator.signum() == 0) {
return this;
}
if (numerator.signum() == 0) {
return fraction.negate();
}
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);
}
示例2: multiply
/**
* <p>Multiplies the value of this fraction by another, returning the
* result in reduced form.</p>
*
* @param fraction the fraction to multiply by, must not be {@code null}
* @return a {@code Fraction} instance with the resulting values
* @throws NullArgumentException if the fraction is {@code null}
* @throws MathArithmeticException if the resulting numerator or denominator exceeds
* {@code Integer.MAX_VALUE}
*/
public Fraction multiply(Fraction fraction) {
if (fraction == null) {
throw new NullArgumentException(LocalizedFormats.FRACTION);
}
if (numerator == 0 || fraction.numerator == 0) {
return ZERO;
}
// knuth 4.5.1
// make sure we don't overflow unless the result *must* overflow.
int d1 = ArithmeticUtils.gcd(numerator, fraction.denominator);
int d2 = ArithmeticUtils.gcd(fraction.numerator, denominator);
return getReducedFraction
(ArithmeticUtils.mulAndCheck(numerator/d1, fraction.numerator/d2),
ArithmeticUtils.mulAndCheck(denominator/d2, fraction.denominator/d1));
}
示例3: add
/**
* <p>
* Adds the value of this fraction to another, returning the result in
* reduced form.
* </p>
*
* @param fraction
* the {@link BigFraction} to add, must not be <code>null</code>.
* @return a {@link BigFraction} instance with the resulting values.
* @throws NullArgumentException if the {@link BigFraction} is {@code null}.
*/
public BigFraction add(final BigFraction fraction) {
if (fraction == null) {
throw new NullArgumentException(LocalizedFormats.FRACTION);
}
if (fraction.numerator.signum() == 0) {
return this;
}
if (numerator.signum() == 0) {
return fraction;
}
BigInteger num = null;
BigInteger den = null;
if (denominator.equals(fraction.denominator)) {
num = numerator.add(fraction.numerator);
den = denominator;
} else {
num = (numerator.multiply(fraction.denominator)).add((fraction.numerator).multiply(denominator));
den = denominator.multiply(fraction.denominator);
}
if (num.signum() == 0) {
return ZERO;
}
return new BigFraction(num, den);
}
示例4: divide
/**
* <p>
* Divide the value of this fraction by the passed {@code BigInteger},
* ie {@code this * 1 / bg}, returning the result in reduced form.
* </p>
*
* @param bg the {@code BigInteger} to divide by, must not be {@code null}
* @return a {@link BigFraction} instance with the resulting values
* @throws NullArgumentException if the {@code BigInteger} is {@code null}
* @throws MathArithmeticException if the fraction to divide by is zero
*/
public BigFraction divide(final BigInteger bg) {
if (bg == null) {
throw new NullArgumentException(LocalizedFormats.FRACTION);
}
if (bg.signum() == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
}
if (numerator.signum() == 0) {
return ZERO;
}
return new BigFraction(numerator, denominator.multiply(bg));
}
示例5: multiply
/**
* <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.signum() == 0 ||
fraction.numerator.signum() == 0) {
return ZERO;
}
return new BigFraction(numerator.multiply(fraction.numerator),
denominator.multiply(fraction.denominator));
}
示例6: divide
/**
* <p>Divide the value of this fraction by another.</p>
*
* @param fraction the fraction to divide by, must not be {@code null}
* @return a {@code Fraction} instance with the resulting values
* @throws IllegalArgumentException if the fraction is {@code null}
* @throws MathArithmeticException if the fraction to divide by is zero
* @throws MathArithmeticException if the resulting numerator or denominator exceeds
* {@code Integer.MAX_VALUE}
*/
public Fraction divide(Fraction fraction) {
if (fraction == null) {
throw new NullArgumentException(LocalizedFormats.FRACTION);
}
if (fraction.numerator == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_FRACTION_TO_DIVIDE_BY,
fraction.numerator, fraction.denominator);
}
return multiply(fraction.reciprocal());
}