Rational( Rational copy ) { numerator = new Polynomial(copy.numerator); denominator = new Polynomial(copy.denominator); }
/// <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; }
/// <summary> /// Negate a rational. /// </summary> public static Rational operator -(Rational rational) { Rational ret = new Rational(rational); ret.NegateInplace(); return ret; }
/// <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; }
/// <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; }
/// <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; }
/// <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)); }
public static bool Equals(Rational rational1, Rational rational2) { return(rational1.Equals(rational2)); }
public bool Equals(Rational rational) { return(numerator.Equals(rational.numerator) && denominator.Equals(rational.denominator)); }
/// <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); }
/// <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; }
/// <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); }
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); }
public Rational Divide(Rational rational) { return(new Rational(numerator * rational.denominator, denominator * rational.numerator)); }
public int CompareTo(Rational rational) { int n = numerator.CompareTo(rational.numerator); if(n == 0) n = denominator.CompareTo(rational.denominator); return n; }
/// <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; }
/// <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; }
/// <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; }
/// <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); }
/// <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 ); }
/// <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 ); }
/// <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); }
/// <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); }
/// <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); }
public Rational Multiply(Rational rational) { return(new Rational(numerator * rational.numerator, denominator * rational.denominator)); }