Exemple #1
0
        /// <summary>
        ///   Divide by x, return self
        /// </summary>
        // public abstract LispNumber Divide(LispNumber x);

        // public abstract int Compare(LispNumber x);

        public static SchNum Add(SchNum x, SchNum y)
        {
            if (object.ReferenceEquals(y, null) || y.isZero)
            {
                return(x);
            }
            var xType = x.valueType;
            var yType = y.valueType;

            if (ValueType.Double == xType || ValueType.Double == yType)
            {
                return(new SchDouble(x.AsDouble() + y.AsDouble()));
            }
            else if (ValueType.Single == xType || ValueType.Single == yType)
            {
                return(new SchFloat(x.AsFloat() + y.AsFloat()));
            }
            else if (ValueType.UInt64 == xType || ValueType.UInt64 == yType)
            {
                return(new SchUInt64(x.AsULong() + y.AsULong()));
            }
            else if (ValueType.Int64 == xType || ValueType.Int64 == yType)
            {
                return(new SchInt64(x.AsLong() + y.AsLong()));
            }
            else if (ValueType.UInt32 == xType || ValueType.UInt32 == yType)
            {
                return(new SchUInt(x.AsUInt() + y.AsUInt()));
            }
            return(new SchInt(x.AsInt() + y.AsInt()));
        }
Exemple #2
0
 /// <summary>
 ///   Numbers become numbers; #t and #f are booleans; "..." string; otherwise Symbol.
 /// </summary>
 private object ParseAtom(string token)
 {
     if (token == "#t")
     {
         // Do we really need boolean?
         // return new SchBool(true);
         return(new SchInt(1));
     }
     else if (token == "#f")
     {
         // return new SchBool(false);
         return(new SchInt(0));
     }
     else if (token[0] == '"')
     {
         return(token.Substring(1, token.Length - 2));
     }
     else if (SchNum.TryParse(token, out SchObj num))
     {
         return(num);
     }
     else
     {
         return(Intern(token)); // a symbol
     }
 }
Exemple #3
0
 /// <summary>
 ///   Subtract x from self, return self
 /// </summary>
 public abstract SchNum Subtract(SchNum x);
Exemple #4
0
 /// <summary>
 ///   Multiply by x , return self
 /// </summary>
 public abstract SchNum Multiply(SchNum x);
Exemple #5
0
 public override SchNum Subtract(SchNum x)
 {
     return(null);
 }
Exemple #6
0
 public override SchNum Multiply(SchNum x)
 {
     return(null);
 }
Exemple #7
0
 public override SchNum Add(SchNum x)
 {
     return(null);
 }
Exemple #8
0
 /// <summary>
 ///   Add x to self, return self
 /// </summary>
 public abstract SchNum Add(SchNum x);
Exemple #9
0
 public static int Compare(SchNum x, SchNum y)
 {
     return(System.Math.Sign(x.AsDouble() - y.AsDouble()));
 }
Exemple #10
0
 public static SchNum Floor(SchNum x)
 {
     return(x);
 }
Exemple #11
0
 public static SchNum Ceiling(SchNum x)
 {
     return(x);
 }