/// <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())); }
/// <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 } }
/// <summary> /// Subtract x from self, return self /// </summary> public abstract SchNum Subtract(SchNum x);
/// <summary> /// Multiply by x , return self /// </summary> public abstract SchNum Multiply(SchNum x);
public override SchNum Subtract(SchNum x) { return(null); }
public override SchNum Multiply(SchNum x) { return(null); }
public override SchNum Add(SchNum x) { return(null); }
/// <summary> /// Add x to self, return self /// </summary> public abstract SchNum Add(SchNum x);
public static int Compare(SchNum x, SchNum y) { return(System.Math.Sign(x.AsDouble() - y.AsDouble())); }
public static SchNum Floor(SchNum x) { return(x); }
public static SchNum Ceiling(SchNum x) { return(x); }