コード例 #1
0
 /// <summary>
 /// The method add two field togther.
 /// - Only Exact rationals are supported.
 /// </summary>
 /// <param name="f"></param>
 /// <returns></returns>
 public override OrderedField Add(OrderedField f)
 {
     if (f is ExactRational)
     {
         ExactRational that = f as ExactRational;
         BigInteger    thisn = n, thisd = d, thatn = that.n, thatd = that.d;
         var           commonnumerator = thisn * thatn;
         thisn *= thatd;
         thatn *= thisd;
         return(ConstructExactRational(thisn + thatn, commonnumerator));
     }
     throw new NotImplementedException();
 }
コード例 #2
0
 public override int CompareTo(OrderedField other)
 {
     if (other is ExactRational)
     {
         ExactRational that       = other as ExactRational;
         var           difference = this - that;
         if (difference.IsZero())
         {
             return(0);
         }
         return(difference.IsPositive() ? 1 : -1);
     }
     throw new NotImplementedException();
 }
コード例 #3
0
 public override OrderedField Multiply(OrderedField f)
 {
     if (f is OrderedField)
     {
         ExactRational b     = f as ExactRational;
         var           thisn = this.n;
         var           thisd = this.d;
         var           thatn = b.n;
         var           thatd = b.d;
         var           c1    = GCD(thisn, thatd);
         var           c2    = GCD(thatn, thisd);
         thisn /= c1;
         thatd /= c1;
         thatn /= c2;
         thisd /= c2;
         return(ConstructExactRational(thisn * thatn, thatd * thisd));
     }
     throw new NotImplementedException();
 }