Exemplo n.º 1
0
 public int CompareTo(BigNum that)
 {
     if (this.val == that.val)
     {
         return(0);
     }
     if (this.val < that.val)
     {
         return(-1);
     }
     return(1);
 }
Exemplo n.º 2
0
 public static bool TryParse(string v, out BigNum res)
 {
     try
     {
         res = BigNum.FromString(v);
         return(true);
     }
     catch (FormatException)
     {
         res = ZERO;
         return(false);
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
 public BigNum Max(BigNum that)
 {
     return(new BigNum(this.val >= that.val ? this.val : that.val));
 }
Exemplo n.º 5
0
 public BigNum Min(BigNum that)
 {
     return(new BigNum(this.val <= that.val ? this.val : that.val));
 }
Exemplo n.º 6
0
 public static Rational FromInts(int num, int den)
 {
     return(FromBignums(BigNum.FromInt(num), BigNum.FromInt(den)));
 }
Exemplo n.º 7
0
 public static Rational FromBignum(BigNum n)
 {
     return(new Rational(n, BigNum.ONE));
 }
Exemplo n.º 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)));
        }