public static double EvaluateString(string expr) { expr = "0+" + expr.Replace(" ", ""); while (expr.Contains("+-") || expr.Contains("-+") || expr.Contains("++") || expr.Contains("--")) { expr = expr.Replace("()", "0").Replace(")(", ")*(").Replace("+-", "-").Replace("-+", "-").Replace("++", "+").Replace("--", "+"); } string[] sa = MiMFa_StringService.GetAllWordsBetween(expr, "(", ")", true).ToArray(); if (sa.Length > 0) { string[] sanew = new string[sa.Length]; for (int i = 0; i < sa.Length; i++) { sanew[i] = EvaluateString(sa[i].Replace("(", "").Replace(")", "")).ToString(); } expr = MiMFa_StringService.ReplaceWithAllByOrder(expr, sa, sanew); } expr = expr.Trim(); expr = LikeLapSignE(expr, "√"); expr = LikeLapSignE(expr, "^"); expr = LikeLapSignE(expr, "%"); expr = LikeLapSignE(expr, "×", "*", "÷", "\\"); expr = LikeLapSignE(expr, "+", "-"); return(MiMFa_Convert.ForceToDouble(expr)); }
public override object EXECUTE(params object[] po) { if (po == null) { return(Null); } return(Math.Log(MiMFa_Convert.ForceToDouble(po[0]), Math.E)); }
public override object EXECUTE(params object[] po) { if (po != null && po.Length > 0) { List <double> ld = new List <double>(); for (int i = 0; i < po.Length; i++) { ld.Add(MiMFa_Convert.ForceToDouble(po[i])); } return(ld.Sum()); } return(Null); }
public override object EXECUTE(params object[] po) { if (po != null && po.Length > 0) { Double max = MiMFa_Convert.ForceToDouble(po[0]); for (int i = 1; i < po.Length; i++) { max = Math.Max(max, MiMFa_Convert.ForceToDouble(po[i])); } return(max); } return(Null); }
public override object EXECUTE(params object[] po) { if (po == null) { return(Null); } if (po.Length == 1) { return(MiMFa_Convert.ForceToDouble(po[0]) % 2); } if (po.Length == 2) { return(MiMFa_Convert.ForceToDouble(po[0]) % MiMFa_Convert.ForceToDouble(po[1])); } return(MiMFa_Math.ModOfPowerElement(Convert.ToInt32(po[0]), Convert.ToInt32(po[1]), Convert.ToInt32(po[2]))); }
public static dynamic EvaluateString(object op1, string sign, object op2) { Func <object, double> normal = (o) => { if (!string.IsNullOrEmpty(o + "")) { return(Convert.ToDouble(o)); } return(1); }; double d1 = MiMFa_Convert.ForceToDouble(normal(op1)); double d2 = MiMFa_Convert.ForceToDouble(normal(op2)); switch (sign) { case "^": return(Math.Pow(d1, d2)); case "√": return(d1 * Math.Sqrt(d2)); case "%": return(d1 % d2); case "×": return(d1 * d2); case "*": return(d1 * d2); case "÷": return(d1 / d2); case "\\": return(d1 / d2); case "+": return(d1 + d2); case "-": return(d1 - d2); } DataTable dt = new DataTable(); return(MiMFa_Convert.ForceToDouble(dt.Compute(op1 + sign + op2, ""))); }
public override object EXECUTE(params object[] po) { if (po != null && po.Length > 0) { List <double> ld = new List <double>(); for (int i = 0; i < po.Length; i++) { ld.Add(MiMFa_Convert.ForceToDouble(po[i])); } if (_reverse || r) { return((from v in ld orderby v descending select v).ToArray()); } return((from v in ld orderby v ascending select v).ToArray()); } return(Null); }
public override object EXECUTE(params object[] po) { if (po != null && po.Length > 0) { List <double> ld = new List <double>(); for (int i = 0; i < po.Length; i++) { ld.Add(MiMFa_Convert.ForceToDouble(po[i])); } int dn = ld.Count / 2; if (ld.Count % 2 == 0) { return(ld.GetRange(dn - 1, 2)); } return(ld.GetRange(dn, 1).First()); } return(Null); }
private static string LikeLapSignE(string expr, params string[] signs) { while (expr.Contains("+-") || expr.Contains("-+") || expr.Contains("++") || expr.Contains("--")) { expr = expr.Replace("()", "0").Replace(")(", ")*(").Replace("+-", "-").Replace("-+", "-").Replace("++", "+").Replace("--", "+"); } string[] ca1 = { "√", "^", "%", "×", "*", "÷", "\\", "+", "-" }; Func <string, string> func = (sign) => { string[] sa = expr.Split(new string[] { sign }, StringSplitOptions.None); if (sa.Length <= 1) { return(expr); } string[] arr = sa[0].Split(ca1, StringSplitOptions.None); string op1 = arr[arr.Length - 1]; string op2 = sa[1]; double dop2 = 0; if (op2.StartsWith("+")) { arr = sa[1].Split(ca1, StringSplitOptions.None); op2 = "+" + arr[1]; dop2 = Convert.ToDouble(arr[1]); } else if (op2.StartsWith("-")) { arr = sa[1].Split(ca1, StringSplitOptions.None); op2 = "-" + arr[1]; dop2 = -1 * Convert.ToDouble(arr[1]); } else { arr = sa[1].Split(ca1, StringSplitOptions.None); op2 = arr[0]; dop2 = Convert.ToDouble(arr[0]); } string result = EvaluateString(op1, sign, dop2).ToString(); expr = expr.Replace(op1 + sign + op2, MiMFa_Convert.ForceToDouble(result).ToString()); return(expr); }; if (expr.Split(signs, StringSplitOptions.None).Length > 1) { do { Dictionary <int, string> collection = new Dictionary <int, string>(); for (int i = 0; i < expr.Length; i++) { foreach (var item in signs) { if (expr[i].ToString() == item) { collection.Add(i, item); break; } } } collection = MiMFa_CollectionService.Sort(collection, (d1, d2) => d1.Key < d2.Key); foreach (var item in collection) { expr = func(item.Value); } }while (expr.Split(signs, StringSplitOptions.RemoveEmptyEntries).Length > 1); } return(expr); }
public static bool CompareString(object op1, string sign, object op2) { try { Func <object, object> normal = (o) => { if (!string.IsNullOrEmpty(o.ToString())) { return(o); } return(true); }; op1 = normal(op1); op2 = normal(op2); double d1; double d2; bool b1; bool b2; switch (sign) { case "===": return(op1.Equals(op2)); case "!==": return(!op1.Equals(op2)); case "==": return(op1.ToString() == op2.ToString()); case "!=": return(op1.ToString() != op2.ToString()); case "~==": return(op1.GetType() == op2.GetType() && MiMFa_StringService.ComparePerCent(op1.ToString(), op2.ToString()) > 70); case "~=": return(MiMFa_StringService.ComparePerCent(op1.ToString(), op2.ToString()) > 70); case ">": d1 = MiMFa_Convert.ForceToDouble(op1); d2 = MiMFa_Convert.ForceToDouble(op2); return(d1 > d2); case "<": d1 = MiMFa_Convert.ForceToDouble(op1); d2 = MiMFa_Convert.ForceToDouble(op2); return(d1 < d2); case ">=": d1 = MiMFa_Convert.ForceToDouble(op1); d2 = MiMFa_Convert.ForceToDouble(op2); return(d1 >= d2); case "<=": d1 = MiMFa_Convert.ForceToDouble(op1); d2 = MiMFa_Convert.ForceToDouble(op2); return(d1 <= d2); case "&&": b1 = MiMFa_Convert.ToBoolean(op1); b2 = MiMFa_Convert.ToBoolean(op2); return(b1 && b2); case "||": b1 = MiMFa_Convert.ToBoolean(op1); b2 = MiMFa_Convert.ToBoolean(op2); return(b1 || b2); case "is": return(op1.GetType() == op2.GetType()); } DataTable dt = new DataTable(); return(Convert.ToBoolean(dt.Compute(op1 + sign + op2, "")));; } catch { throw new Exception("Invalid character."); } }
public override object execute(object obj, int index, int length) { return(Math.Sqrt(MiMFa_Convert.ForceToDouble(obj))); }