Beispiel #1
0
 public int CompareTo(BigNum that)
 {
     if (this.val == that.val)
     {
         return(0);
     }
     if (this.val < that.val)
     {
         return(-1);
     }
     return(1);
 }
Beispiel #2
0
 public static bool TryParse(string v, out BigNum res)
 {
     try
     {
         res = BigNum.FromString(v);
         return(true);
     }
     catch (FormatException)
     {
         res = ZERO;
         return(false);
     }
 }
Beispiel #3
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (!(obj is BigNum))
            {
                return(false);
            }

            BigNum other = (BigNum)obj;

            return(this.val == other.val);
        }
Beispiel #4
0
 public BigNum Max(BigNum that)
 {
     return(new BigNum(this.val >= that.val ? this.val : that.val));
 }
Beispiel #5
0
 public BigNum Min(BigNum that)
 {
     return(new BigNum(this.val <= that.val ? this.val : that.val));
 }
Beispiel #6
0
 public static Rational FromInts(int num, int den)
 {
     return(FromBignums(BigNum.FromInt(num), BigNum.FromInt(den)));
 }
Beispiel #7
0
 public static Rational FromBignum(BigNum n)
 {
     return(new Rational(n, BigNum.ONE));
 }
Beispiel #8
0
        //    int numerator;
        //    int denominator;


        // invariant: 0 < denominator || (numerator == 0 && denominator == 0);
        // invariant: numerator != 0 ==> gcd(abs(numerator),denominator) == 1;
        // invariant: numerator == 0 ==> denominator == 1 || denominator == 0;

        public static Rational FromInt(int x)
        {
            return(FromBignum(BigNum.FromInt(x)));
        }