Пример #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()));
        }
Пример #2
0
 public static int Compare(SchNum x, SchNum y)
 {
     return(System.Math.Sign(x.AsDouble() - y.AsDouble()));
 }