/** * Returns the largest of the specified rational numbers. * * @param values the rational numbers to compare * @return the largest rational number, 0 if no numbers are specified * @see #max(BigRational) */ public static BigRational max(params BigRational[] values) { if (values.Length == 0) { return(BigRational.ZERO); } BigRational result = values[0]; for (int i = 1; i < values.Length; i++) { result = result.max(values[i]); } return(result); }
public Boolean equals(Object obj) { if (obj == this) { return(true); } //if (!(obj instanceof BigRational)) { // return false; //} BigRational other = (BigRational)obj; if (!numerator.equals(other.numerator)) { return(false); } return(denominator.equals(other.denominator)); }
/** * Calculates the multiplication (*) of this rational number and the specified argument. * * <p>The result has no loss of precision.</p> * * @param value the rational number to multiply * @return the resulting rational number */ public BigRational multiply(BigRational value) { if (isZero() || value.isZero()) { return(ZERO); } if (equals(ONE)) { return(value); } if (value.equals(ONE)) { return(this); } BigDecimal n = numerator.multiply(value.numerator); BigDecimal d = denominator.multiply(value.denominator); return(of(n, d)); }
/** * Finds the maximum (larger) of two rational numbers. * * @param value the rational number to compare with * @return the minimum rational number, either <code>this</code> or the argument <code>value</code> */ private BigRational max(BigRational value) { return(compareTo(value) >= 0 ? this : value); }
/** * Finds the minimum (smaller) of two rational numbers. * * @param value the rational number to compare with * @return the minimum rational number, either <code>this</code> or the argument <code>value</code> */ private BigRational min(BigRational value) { return(compareTo(value) <= 0 ? this : value); }