Exemple #1
0
 protected static LispNumber Add(LispInteger a, LispInteger b)
 {
     try
     {
         var sum = checked(a.Value + b.Value);
         return MakeNumber(sum);
     }
     catch (OverflowException)
     {
         return new LispBigInteger((BigInteger)a.Value + b.Value);
     }
 }
Exemple #2
0
Fichier : Add.cs Projet : nja/keel
        public override LispObject Apply(Cons argumentsValues, LispEnvironment env)
        {
            LispNumber sum = new LispInteger(0);

            foreach (var addend in argumentsValues)
            {
                var num = addend.As<LispNumber>();
                sum = sum.Add(num);
            }

            return sum;
        }
Exemple #3
0
 protected static LispNumber Multiply(LispInteger a, LispInteger b)
 {
     try
     {
         int product = checked(a.Value * b.Value);
         return MakeNumber(product);
     }
     catch (OverflowException)
     {
         BigInteger product = (BigInteger)a.Value * b.Value;
         return MakeNumber(product);
     }
 }
Exemple #4
0
        protected static LispNumber Divide(LispInteger dividend, LispInteger divisor)
        {
            try
            {
                checked
                {
                    int remainder;
                    int quotient = Math.DivRem(dividend.Value, divisor.Value, out remainder);

                    if (remainder != 0)
                    {
                        return Divide((LispDouble)dividend, (LispDouble)divisor);
                    }

                    return MakeNumber(quotient);
                }
            }
            catch (OverflowException)
            {
                return Divide((LispBigInteger)dividend, (LispBigInteger)divisor);
            }
        }
Exemple #5
0
 public override bool NumberEquals(LispInteger number)
 {
     return Value == number.Value;
 }
Exemple #6
0
 public abstract LispNumber Multiply(LispInteger factor);
Exemple #7
0
 public abstract LispNumber DivideBy(LispInteger divisor);
Exemple #8
0
 public abstract LispNumber Add(LispInteger addend);
Exemple #9
0
 public override LispNumber Add(LispInteger addend)
 {
     return new LispBigInteger(addend).Add(this);
 }
Exemple #10
0
 public LispBigInteger(LispInteger value)
 {
     this.Value = value.Value;
 }
Exemple #11
0
 public override bool NumberEquals(LispInteger number)
 {
     return NumberEquals(number, this);
 }
Exemple #12
0
 public override LispNumber Multiply(LispInteger factor)
 {
     return Multiply(this, (LispBigInteger)factor);
 }
Exemple #13
0
 public override int CompareTo(LispInteger number)
 {
     return Value.CompareTo(number.Value);
 }
Exemple #14
0
 public override LispNumber Add(LispInteger addend)
 {
     return Add(this, addend);
 }
Exemple #15
0
 protected static bool NumberEquals(LispInteger a, LispBigInteger b)
 {
     return (BigInteger)a.Value == b.Value;
 }
Exemple #16
0
 protected static bool NumberEquals(LispInteger a, LispDouble b)
 {
     return a.Value == b.Value;
 }
Exemple #17
0
 public override int CompareTo(LispInteger number)
 {
     return -Compare(number, this);
 }
Exemple #18
0
 public abstract int CompareTo(LispInteger number);
Exemple #19
0
 public override LispNumber DivideBy(LispInteger divisor)
 {
     return Divide(this, (LispBigInteger)divisor);
 }
Exemple #20
0
 public abstract LispNumber DivideInto(LispInteger dividend);
Exemple #21
0
 public override LispNumber DivideInto(LispInteger dividend)
 {
     return Divide((LispBigInteger)dividend, this);
 }
Exemple #22
0
 public abstract bool NumberEquals(LispInteger number);
Exemple #23
0
 protected static int Compare(LispInteger a, LispDouble b)
 {
     return ((double)a.Value).CompareTo(b.Value);
 }
Exemple #24
0
 protected static int Compare(LispInteger a, LispBigInteger b)
 {
     return ((BigInteger)a.Value).CompareTo(b.Value);
 }
Exemple #25
0
 public LispDouble(LispInteger integer)
 {
     this.Value = integer.Value;
 }