Rational(
     Rational copy
     )
 {
     numerator = new Polynomial(copy.numerator);
     denominator = new Polynomial(copy.denominator);
 }
Esempio n. 2
0
 /// <summary>
 /// Stretch a the inverse of a rational with a real number quotient.
 /// </summary>
 public static Rational operator /(
     double n,
     Rational rational)
 {
     Rational ret = new Rational(rational);
     ret.InvertInplace();
     ret.MultiplyInplace(n);
     return ret;
 }
Esempio n. 3
0
 /// <summary>
 /// Negate a rational.
 /// </summary>
 public static Rational operator -(Rational rational)
 {
     Rational ret = new Rational(rational);
     ret.NegateInplace();
     return ret;
 }
Esempio n. 4
0
 /// <summary>
 /// Subtract a real number from a rational.
 /// </summary>
 public static Rational operator -(
     Rational rational,
     double n)
 {
     Rational ret = new Rational(rational);
     ret.SubtractInplace(n);
     return ret;
 }
Esempio n. 5
0
 /// <summary>
 /// Subtract a polynomial from a rational.
 /// </summary>
 public static Rational operator -(
     Rational rational,
     Polynomial polynomial)
 {
     Rational ret = new Rational(rational);
     ret.SubtractInplace(polynomial);
     return ret;
 }
Esempio n. 6
0
 /// <summary>
 /// Add a polynomial to a rational.
 /// </summary>
 public static Rational operator +(
     Rational rational,
     Polynomial polynomial)
 {
     Rational ret = new Rational(rational);
     ret.AddInplace(polynomial);
     return ret;
 }
        CompareTo(
            Rational rational
            )
        {
            int n = numerator.CompareTo(rational.numerator);
            if(n == 0)
            {
                n = denominator.CompareTo(rational.denominator);
            }

            return n;
        }
Esempio n. 8
0
        /// <summary>
        /// Create a new rational as the result of subtracting a rational from this rational.
        /// </summary>
        /// <param name="rational">The rational to subtract.</param>
        public Rational Subtract(Rational rational)
        {
            if(_denominator.Equals(rational._denominator))
            {
                return new Rational(
                    _numerator - rational._numerator,
                    _denominator.Clone());
            }

            Polynomial num = (_numerator * rational._denominator) - (rational._numerator * _denominator);
            Polynomial denom = _denominator * rational._denominator;
            return new Rational(num, denom);
        }
 Rational(Rational copy)
 {
     _numerator   = new Polynomial(copy._numerator);
     _denominator = new Polynomial(copy._denominator);
 }
 Equals(
     Rational rational1,
     Rational rational2)
 {
     return(rational1.Equals(rational2));
 }
 Equals(Rational rational)
 {
     return(_numerator.Equals(rational._numerator) &&
            _denominator.Equals(rational._denominator));
 }
 Divide(Rational rational)
 {
     return(new Rational(
                _numerator * rational._denominator,
                _denominator * rational._numerator));
 }
Esempio n. 13
0
 public static bool Equals(Rational rational1, Rational rational2)
 {
     return(rational1.Equals(rational2));
 }
Esempio n. 14
0
 public bool Equals(Rational rational)
 {
     return(numerator.Equals(rational.numerator) && denominator.Equals(rational.denominator));
 }
Esempio n. 15
0
 /// <summary>Create a new rational by copy</summary>
 /// <param name="copy">A rational to copy from.</param>
 public Rational(Rational copy)
 {
     numerator   = new Polynomial(copy.numerator);
     denominator = new Polynomial(copy.denominator);
 }
Esempio n. 16
0
        /// <summary>
        /// Compare this rational to another rational.
        /// </summary>
        public int CompareTo(Rational rational)
        {
            int n = _numerator.CompareTo(rational._numerator);
            if(n == 0)
            {
                n = _denominator.CompareTo(rational._denominator);
            }

            return n;
        }
Esempio n. 17
0
 /// <summary>
 /// Check whether this rational is equal to another rational.
 /// </summary>
 public bool Equals(Rational rational)
 {
     return _numerator.Equals(rational._numerator)
         && _denominator.Equals(rational._denominator);
 }
Esempio n. 18
0
		public Rational Add(Rational rational)
		{
			if(denominator.Equals(rational.denominator))
				return new Rational(numerator+rational.numerator,denominator.Clone());
			Polynomial num = numerator*rational.denominator + rational.numerator*denominator;
			Polynomial denom = denominator*rational.denominator;
			return new Rational(num,denom);
		}
Esempio n. 19
0
 public Rational Divide(Rational rational)
 {
     return(new Rational(numerator * rational.denominator, denominator * rational.numerator));
 }
Esempio n. 20
0
		public int CompareTo(Rational rational)
		{
			int n = numerator.CompareTo(rational.numerator);
			if(n == 0)
				n = denominator.CompareTo(rational.denominator);
			return n;
		}
Esempio n. 21
0
 /// <summary>
 /// Stretch a rational with a real number factor.
 /// </summary>
 public static Rational operator *(
     Rational rational,
     double n)
 {
     Rational ret = new Rational(rational);
     ret.MultiplyInplace(n);
     return ret;
 }
 operator +(
     Polynomial polynomial,
     Rational rational
     )
 {
     Rational ret = new Rational(rational);
     ret.AddInplace(polynomial);
     return ret;
 }
Esempio n. 23
0
 /// <summary>
 /// Add a real number to a rational.
 /// </summary>
 public static Rational operator +(
     Rational rational,
     double n)
 {
     Rational ret = new Rational(rational);
     ret.AddInplace(n);
     return ret;
 }
 operator +(
     double n,
     Rational rational
     )
 {
     Rational ret = new Rational(rational);
     ret.AddInplace(n);
     return ret;
 }
Esempio n. 25
0
 /// <summary>
 /// Subtract a rational from a polynomial.
 /// </summary>
 public static Rational operator -(
     Polynomial polynomial,
     Rational rational)
 {
     Rational ret = new Rational(rational);
     ret.NegateInplace();
     ret.AddInplace(polynomial);
     return ret;
 }
 operator *(
     double n,
     Rational rational
     )
 {
     Rational ret = new Rational(rational);
     ret.MultiplyInplace(n);
     return ret;
 }
Esempio n. 27
0
 /// <summary>
 /// Subtract a rational from a real number.
 /// </summary>
 public static Rational operator -(
     double n,
     Rational rational)
 {
     Rational ret = new Rational(rational);
     ret.NegateInplace();
     ret.AddInplace(n);
     return ret;
 }
        Subtract(
            Rational rational
            )
        {
            if(denominator.Equals(rational.denominator))
            {
                return new Rational(
                    numerator - rational.numerator,
                    denominator.Clone()
                    );
            }

            Polynomial num = numerator * rational.denominator - rational.numerator * denominator;
            Polynomial denom = denominator * rational.denominator;
            return new Rational(num, denom);
        }
Esempio n. 29
0
 /// <summary>
 /// Stretch a rational with a real number quotient.
 /// </summary>
 public static Rational operator /(
     Rational rational,
     double n)
 {
     Rational ret = new Rational(rational);
     ret.DivideInplace(n);
     return ret;
 }
 Multiply(
     Rational rational
     )
 {
     return new Rational(
         numerator * rational.numerator,
         denominator * rational.denominator
         );
 }
Esempio n. 31
0
 /// <summary>
 /// Check whether two rationals are equal.
 /// </summary>
 public static bool Equals(
     Rational rational1,
     Rational rational2)
 {
     return rational1.Equals(rational2);
 }
 Divide(
     Rational rational
     )
 {
     return new Rational(
         numerator * rational.denominator,
         denominator * rational.numerator
         );
 }
Esempio n. 33
0
 /// <summary>
 /// Create a new rational as the result of dividing a rational from this rational.
 /// </summary>
 /// <param name="rational">The rational to divide with.</param>
 public Rational Divide(Rational rational)
 {
     return new Rational(
         _numerator * rational._denominator,
         _denominator * rational._numerator);
 }
 Equals(
     Rational rational
         )
 {
     return numerator.Equals(rational.numerator)
         && denominator.Equals(rational.denominator);
 }
Esempio n. 35
0
 /// <summary>
 /// Create a new rational as the result of multiplying a rational to this rational.
 /// </summary>
 /// <param name="rational">The rational to multiply with.</param>
 public Rational Multiply(Rational rational)
 {
     return new Rational(
         _numerator * rational._numerator,
         _denominator * rational._denominator);
 }
 Equals(
     Rational rational1,
     Rational rational2
     )
 {
     return rational1.Equals(rational2);
 }
Esempio n. 37
0
 /// <summary>
 /// Initializes a new instance of the Rational class,
 /// by deep-copy from an existing rational.
 /// </summary>
 /// <param name="copy">A rational to copy from.</param>
 public Rational(Rational copy)
 {
     _numerator = new Polynomial(copy._numerator);
     _denominator = new Polynomial(copy._denominator);
 }
Esempio n. 38
0
 public Rational Multiply(Rational rational)
 {
     return(new Rational(numerator * rational.numerator, denominator * rational.denominator));
 }