/** * Calculates the subtraction (-) of this rational number and the specified argument. * * <p>This is functionally identical to * <code>this.subtract(BigRational.valueOf(value))</code> * but slightly faster.</p> * * <p>The result has no loss of precision.</p> * * @param value the {@link BigInteger} to subtract * @return the resulting rational number */ public BigRational subtract(BigInteger value) { if (value.equals(BigInteger.ZERO)) { return(this); } return(subtract(new BigDecimal(value))); }
/** * Calculates the division (/) of this rational number and the specified argument. * * <p>This is functionally identical to * <code>this.divide(BigRational.valueOf(value))</code> * but slightly faster.</p> * * <p>The result has no loss of precision.</p> * * @param value the {@link BigInteger} to divide (0 is not allowed) * @return the resulting rational number * @throws ArithmeticException if the argument is 0 (division by zero) */ public BigRational divide(BigInteger value) { if (value.equals(BigInteger.ONE)) { return(this); } return(divide(new BigDecimal(value))); }
/** * Calculates the multiplication (*) of this rational number and the specified argument. * * <p>This is functionally identical to * <code>this.multiply(BigRational.valueOf(value))</code> * but slightly faster.</p> * * <p>The result has no loss of precision.</p> * * @param value the {@link BigInteger} to multiply * @return the resulting rational number */ public BigRational multiply(BigInteger value) { if (isZero() || value.signum() == 0) { return(ZERO); } if (equals(ONE)) { return(valueOf(value)); } if (value.equals(BigInteger.ONE)) { return(this); } return(multiply(new BigDecimal(value))); }