/** * Calculates the addition (+) of this rational number and the specified argument. * * <p>The result has no loss of precision.</p> * * @param value the rational number to add * @return the resulting rational number */ public BigRational add(BigRational value) { if (denominator.equals(value.denominator)) { return(of(numerator.add(value.numerator), denominator)); } BigDecimal n = numerator.multiply(value.denominator).add(value.numerator.multiply(denominator)); BigDecimal d = denominator.multiply(value.denominator); return(of(n, d)); }
/** * Returns whether the real and imaginary parts of this complex number are strictly equal. * * <p>This method uses the strict equality as defined by {@link BigDecimal#equals(Object)} on the real and imaginary parts.</p> * <p>Please note that {@link #equals(Object) BigComplex.equals(Object)} implements <strong>mathematical</strong> equality instead * (by calling {@link BigDecimal#compareTo(BigDecimal) on the real and imaginary parts}).</p> * * @param obj the object to compare for strict equality * @return {@code true} if the specified object is strictly equal to this complex number * @see #equals(Object) */ public Boolean strictEquals(Object obj) { if (this == obj) { return(true); } if (obj == null) { return(false); } BigComplex other = (BigComplex)obj; return(re.equals(other.re) && im.equals(other.im)); }
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)); }