Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. public static Rational multiplyByLong(Rational rational, long factor) throws IllegalDenominatorException, TimesOverflowException {
  2. try {
  3. if (ExtMath.areMultipliable(rational.getNumerator(), factor))
  4. return new Rational(rational.getNumerator() * factor, rational.getDenominator());
  5. else {
  6. if (!Rational.hasSameValueAs(rational, simplify(rational))) {
  7. if (multiplyByLong(simplify(rational), factor) == null) return null;
  8. return multiplyByLong(simplify(rational), factor);
  9. }
  10. return multiplyByLong(simplify(new Rational(factor, rational.getDenominator())), rational.getNumerator());
  11. }
  12. } catch (TimesOverflowException e) {
  13. e.printStackTrace();
  14. return null;
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement