Changeset 12091
- Timestamp:
- 02/27/15 10:42:46 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/RunCollectionModification/Calculator.cs
r12012 r12091 90 90 } 91 91 } 92 } 93 catch (Exception x) { 92 } catch (Exception x) { 94 93 throw new Exception(string.Format( 95 94 "Calculation of '{1}'{0}failed at token #{2}: {3} {0}current stack is: {0}{4}", Environment.NewLine, … … 104 103 var result = stack.Pop(); 105 104 if (result is string) return new StringValue((string)result); 105 if (result is int) return new IntValue((int)result); 106 106 if (result is double) return new DoubleValue((double)result); 107 107 if (result is bool) return new BoolValue((bool)result); … … 139 139 break; 140 140 141 case "log": Apply(stack, x => Math.Log((double)x)); break; 142 case "+": Apply(stack, (x, y) => (double)x + (double)y); break; 143 case "-": Apply(stack, (x, y) => (double)x - (double)y); break; 144 case "*": Apply(stack, (x, y) => (double)x * (double)y); break; 145 case "/": Apply(stack, (x, y) => (double)x / (double)y); break; 146 case "^": Apply(stack, (x, y) => Math.Pow((double)x, (double)y)); break; 147 case "<": Apply(stack, (x, y) => (double)x < (double)y); break; 148 case ">": Apply(stack, (x, y) => (double)x > (double)y); break; 141 case "log": Apply(stack, x => Math.Log(Convert.ToDouble(x))); break; 142 case "+": Apply(stack, (x, y) => Convert.ToDouble(x) + Convert.ToDouble(y)); break; 143 case "-": Apply(stack, (x, y) => Convert.ToDouble(x) - Convert.ToDouble(y)); break; 144 case "*": Apply(stack, (x, y) => Convert.ToDouble(x) * Convert.ToDouble(y)); break; 145 case "/": Apply(stack, (x, y) => Convert.ToDouble(x) / Convert.ToDouble(y)); break; 146 case "^": Apply(stack, (x, y) => Math.Pow(Convert.ToDouble(x), Convert.ToDouble(y))); break; 147 case "<": Apply(stack, (x, y) => Convert.ToDouble(x) < Convert.ToDouble(y)); break; 148 case ">": Apply(stack, (x, y) => Convert.ToDouble(x) > Convert.ToDouble(y)); break; 149 150 case "toint": Apply(stack, x => Convert.ToInt32(x)); break; 151 case "todouble": Apply(stack, x => Convert.ToDouble(x)); break; 149 152 150 153 case "==": Apply(stack, (x, y) => Equal(x, y)); break; 151 case "not": Apply(stack, x => ! (bool)x); break;154 case "not": Apply(stack, x => !Convert.ToBoolean(x)); break; 152 155 case "isnull": Apply(stack, x => x == null); break; 153 case "if": Apply(stack, (then, else_, cond) => (bool)cond? then : else_); break;154 155 case "ismatch": Apply(stack, (s, p) => new Regex( (string)p).IsMatch((string)s)); break;156 case "rename": Apply(stack, (s, p, r) => new Regex( (string)p).Replace((string)s, (string)r)); break;156 case "if": Apply(stack, (then, else_, cond) => Convert.ToBoolean(cond) ? then : else_); break; 157 158 case "ismatch": Apply(stack, (s, p) => new Regex(Convert.ToString(p)).IsMatch(Convert.ToString(s))); break; 159 case "rename": Apply(stack, (s, p, r) => new Regex(Convert.ToString(p)).Replace(Convert.ToString(s), Convert.ToString(r))); break; 157 160 158 161 default: stack.Push(GetVariableValue(variables, token)); break; … … 208 211 try { 209 212 stack.Push(func(a)); 210 } 211 catch (Exception) { 213 } catch (Exception) { 212 214 stack.Push(a); 213 215 throw; … … 222 224 try { 223 225 stack.Push(func(a, b)); 224 } 225 catch (Exception) { 226 } catch (Exception) { 226 227 stack.Push(b); 227 228 stack.Push(a); … … 238 239 try { 239 240 stack.Push(func(a, b, c)); 240 } 241 catch (Exception) { 241 } catch (Exception) { 242 242 stack.Push(a); 243 243 stack.Push(b);
Note: See TracChangeset
for help on using the changeset viewer.