/** * <p>Gets a fraction that is the negative (-fraction) of this one.</p> * * <p>The returned fraction is not reduced.</p> * * @return a new fraction instance with the opposite signed numerator */ public Fraction negate() { // the positive range is one smaller than the negative range of an int. if (numerator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: too large to negate"); } return new Fraction(-numerator, denominator); }
/** * <p>Gets a fraction that is the inverse (1/fraction) of this one.</p> * * <p>The returned fraction is not reduced.</p> * * @return a new fraction instance with the numerator and denominator * inverted. * @throws ArithmeticException if the fraction represents zero. */ public Fraction invert() { if (numerator == 0) { throw new ArithmeticException("Unable to invert zero."); } if (numerator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: can't negate numerator"); } if (numerator<0) { return new Fraction(-denominator, -numerator); } else { return new Fraction(denominator, numerator); } }
/** * <p>Creates a <code>Fraction</code> instance with the 2 parts * of a fraction Y/Z.</p> * * <p>Any negative signs are resolved to be on the numerator.</p> * * @param numerator the numerator, for example the three in 'three sevenths' * @param denominator the denominator, for example the seven in 'three sevenths' * @return a new fraction instance * @throws ArithmeticException if the denomiator is <code>zero</code> */ public static Fraction getFraction(int numerator, int denominator) { if (denominator == 0) { throw new ArithmeticException("The denominator must not be zero"); } if (denominator < 0) { if (numerator==Integer.MIN_VALUE || denominator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: can't negate"); } numerator = -numerator; denominator = -denominator; } return new Fraction(numerator, denominator); }
throw new ArithmeticException("Numerator too large to represent as an Integer."); return new Fraction((int) numeratorValue, denominator);
numerator /= gcd; denominator /= gcd; return new Fraction(numerator, denominator);
/** * <p>Gets a fraction that is the negative (-fraction) of this one.</p> * * <p>The returned fraction is not reduced.</p> * * @return a new fraction instance with the opposite signed numerator */ public Fraction negate() { // the positive range is one smaller than the negative range of an int. if (numerator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: too large to negate"); } return new Fraction(-numerator, denominator); }
/** * <p>Gets a fraction that is the negative (-fraction) of this one.</p> * * <p>The returned fraction is not reduced.</p> * * @return a new fraction instance with the opposite signed numerator */ public Fraction negate() { // the positive range is one smaller than the negative range of an int. if (numerator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: too large to negate"); } return new Fraction(-numerator, denominator); }
/** * <p>Gets a fraction that is the negative (-fraction) of this one.</p> * * <p>The returned fraction is not reduced.</p> * * @return a new fraction instance with the opposite signed numerator */ public Fraction negate() { // the positive range is one smaller than the negative range of an int. if (numerator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: too large to negate"); } return new Fraction(-numerator, denominator); }
/** * <p>Gets a fraction that is the negative (-fraction) of this one.</p> * * <p>The returned fraction is not reduced.</p> * * @return a new fraction instance with the opposite signed numerator */ public Fraction negate() { // the positive range is one smaller than the negative range of an int. if (numerator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: too large to negate"); } return new Fraction(-numerator, denominator); }
/** * <p>Gets a fraction that is the negative (-fraction) of this one.</p> * * <p>The returned fraction is not reduced.</p> * * @return a new fraction instance with the opposite signed numerator */ public Fraction negate() { // the positive range is one smaller than the negative range of an int. if (numerator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: too large to negate"); } return new Fraction(-numerator, denominator); }
/** * <p>Gets a fraction that is the inverse (1/fraction) of this one.</p> * * <p>The returned fraction is not reduced.</p> * * @return a new fraction instance with the numerator and denominator * inverted. * @throws ArithmeticException if the fraction represents zero. */ public Fraction invert() { if (numerator == 0) { throw new ArithmeticException("Unable to invert zero."); } if (numerator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: can't negate numerator"); } if (numerator<0) { return new Fraction(-denominator, -numerator); } else { return new Fraction(denominator, numerator); } }
/** * <p>Gets a fraction that is the inverse (1/fraction) of this one.</p> * * <p>The returned fraction is not reduced.</p> * * @return a new fraction instance with the numerator and denominator * inverted. * @throws ArithmeticException if the fraction represents zero. */ public Fraction invert() { if (numerator == 0) { throw new ArithmeticException("Unable to invert zero."); } if (numerator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: can't negate numerator"); } if (numerator<0) { return new Fraction(-denominator, -numerator); } else { return new Fraction(denominator, numerator); } }
/** * <p>Gets a fraction that is the inverse (1/fraction) of this one.</p> * * <p>The returned fraction is not reduced.</p> * * @return a new fraction instance with the numerator and denominator * inverted. * @throws ArithmeticException if the fraction represents zero. */ public Fraction invert() { if (numerator == 0) { throw new ArithmeticException("Unable to invert zero."); } if (numerator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: can't negate numerator"); } if (numerator<0) { return new Fraction(-denominator, -numerator); } else { return new Fraction(denominator, numerator); } }
/** * <p>Gets a fraction that is the inverse (1/fraction) of this one.</p> * * <p>The returned fraction is not reduced.</p> * * @return a new fraction instance with the numerator and denominator * inverted. * @throws ArithmeticException if the fraction represents zero. */ public Fraction invert() { if (numerator == 0) { throw new ArithmeticException("Unable to invert zero."); } if (numerator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: can't negate numerator"); } if (numerator<0) { return new Fraction(-denominator, -numerator); } else { return new Fraction(denominator, numerator); } }
/** * <p>Gets a fraction that is the inverse (1/fraction) of this one.</p> * * <p>The returned fraction is not reduced.</p> * * @return a new fraction instance with the numerator and denominator * inverted. * @throws ArithmeticException if the fraction represents zero. */ public Fraction invert() { if (numerator == 0) { throw new ArithmeticException("Unable to invert zero."); } if (numerator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: can't negate numerator"); } if (numerator<0) { return new Fraction(-denominator, -numerator); } else { return new Fraction(denominator, numerator); } }
/** * <p>Creates a <code>Fraction</code> instance with the 2 parts * of a fraction Y/Z.</p> * * <p>Any negative signs are resolved to be on the numerator.</p> * * @param numerator the numerator, for example the three in 'three sevenths' * @param denominator the denominator, for example the seven in 'three sevenths' * @return a new fraction instance * @throws ArithmeticException if the denomiator is <code>zero</code> */ public static Fraction getFraction(int numerator, int denominator) { if (denominator == 0) { throw new ArithmeticException("The denominator must not be zero"); } if (denominator < 0) { if (numerator==Integer.MIN_VALUE || denominator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: can't negate"); } numerator = -numerator; denominator = -denominator; } return new Fraction(numerator, denominator); }
/** * <p>Creates a <code>Fraction</code> instance with the 2 parts * of a fraction Y/Z.</p> * * <p>Any negative signs are resolved to be on the numerator.</p> * * @param numerator the numerator, for example the three in 'three sevenths' * @param denominator the denominator, for example the seven in 'three sevenths' * @return a new fraction instance * @throws ArithmeticException if the denomiator is <code>zero</code> */ public static Fraction getFraction(int numerator, int denominator) { if (denominator == 0) { throw new ArithmeticException("The denominator must not be zero"); } if (denominator < 0) { if (numerator==Integer.MIN_VALUE || denominator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: can't negate"); } numerator = -numerator; denominator = -denominator; } return new Fraction(numerator, denominator); }
/** * <p>Creates a <code>Fraction</code> instance with the 2 parts * of a fraction Y/Z.</p> * * <p>Any negative signs are resolved to be on the numerator.</p> * * @param numerator the numerator, for example the three in 'three sevenths' * @param denominator the denominator, for example the seven in 'three sevenths' * @return a new fraction instance * @throws ArithmeticException if the denomiator is <code>zero</code> */ public static Fraction getFraction(int numerator, int denominator) { if (denominator == 0) { throw new ArithmeticException("The denominator must not be zero"); } if (denominator < 0) { if (numerator==Integer.MIN_VALUE || denominator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: can't negate"); } numerator = -numerator; denominator = -denominator; } return new Fraction(numerator, denominator); }
/** * <p>Creates a <code>Fraction</code> instance with the 2 parts * of a fraction Y/Z.</p> * * <p>Any negative signs are resolved to be on the numerator.</p> * * @param numerator the numerator, for example the three in 'three sevenths' * @param denominator the denominator, for example the seven in 'three sevenths' * @return a new fraction instance * @throws ArithmeticException if the denomiator is <code>zero</code> */ public static Fraction getFraction(int numerator, int denominator) { if (denominator == 0) { throw new ArithmeticException("The denominator must not be zero"); } if (denominator < 0) { if (numerator==Integer.MIN_VALUE || denominator==Integer.MIN_VALUE) { throw new ArithmeticException("overflow: can't negate"); } numerator = -numerator; denominator = -denominator; } return new Fraction(numerator, denominator); }