Changeset 15017 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/FloatExpressions.cs
- Timestamp:
- 06/01/17 09:28:34 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/FloatExpressions.cs
r14952 r15017 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 2 using System; 3 using System.Globalization; 4 3 5 using Common; 4 6 … … 30 32 if (double.IsNegativeInfinity(result)) result = double.MinValue; 31 33 32 interpreter.FloatStack. SetTop(result);34 interpreter.FloatStack.Top = result; 33 35 } 34 36 } … … 56 58 if (double.IsNegativeInfinity(result)) result = double.MinValue; 57 59 58 interpreter.FloatStack. SetTop(result);60 interpreter.FloatStack.Top = result; 59 61 } 60 62 } … … 82 84 if (double.IsNegativeInfinity(result)) result = double.MinValue; 83 85 84 interpreter.FloatStack. SetTop(result);86 interpreter.FloatStack.Top = result; 85 87 } 86 88 } … … 109 111 if (double.IsNegativeInfinity(result)) result = double.MinValue; 110 112 111 interpreter.FloatStack. SetTop(result);113 interpreter.FloatStack.Top = result; 112 114 } 113 115 } … … 136 138 var result = second % first; 137 139 138 interpreter.FloatStack. SetTop(result);140 interpreter.FloatStack.Top = result; 139 141 } 140 142 } … … 159 161 var result = Math.Min(second, first); 160 162 161 interpreter.FloatStack. SetTop(result);163 interpreter.FloatStack.Top = result; 162 164 } 163 165 } … … 182 184 var result = Math.Max(second, first); 183 185 184 interpreter.FloatStack. SetTop(result);186 interpreter.FloatStack.Top = result; 185 187 } 186 188 } … … 298 300 public override void Eval(IInternalPushInterpreter interpreter) { 299 301 var result = Math.Sin(interpreter.FloatStack.Top); 300 interpreter.FloatStack. SetTop(result);302 interpreter.FloatStack.Top = result; 301 303 } 302 304 } … … 317 319 public override void Eval(IInternalPushInterpreter interpreter) { 318 320 var result = Math.Cos(interpreter.FloatStack.Top); 319 interpreter.FloatStack. SetTop(result);321 interpreter.FloatStack.Top = result; 320 322 } 321 323 } … … 362 364 } 363 365 } 366 367 /// <summary> 368 /// Pushes the result of truncating the top CHAR. 369 /// </summary> 370 [PushExpression(StackTypes.Float, "FLOAT.FROMCHAR", StackTypes.Char)] 371 [StorableClass] 372 public class FloatFromCharExpression : StatelessExpression { 373 public FloatFromCharExpression() { } 374 [StorableConstructor] 375 protected FloatFromCharExpression(bool deserializing) : base(deserializing) { } 376 377 public override bool IsNoop(IInternalPushInterpreter interpreter) { 378 return interpreter.CharStack.IsEmpty; 379 } 380 381 public override void Eval(IInternalPushInterpreter interpreter) { 382 var value = interpreter.CharStack.Pop(); 383 interpreter.FloatStack.Push(value); 384 } 385 } 386 387 /// <summary> 388 /// Pushes the result of parsing the top STRING. 389 /// </summary> 390 [PushExpression(StackTypes.Float, "FLOAT.FROMSTRING", StackTypes.String)] 391 [StorableClass] 392 public class FloatFromStringExpression : StatelessExpression { 393 public FloatFromStringExpression() { } 394 [StorableConstructor] 395 protected FloatFromStringExpression(bool deserializing) : base(deserializing) { } 396 397 public override bool IsNoop(IInternalPushInterpreter interpreter) { 398 double tmp; 399 return interpreter.StringStack.IsEmpty || 400 interpreter.StringStack.Top.Length == 0 || 401 !double.TryParse(interpreter.StringStack.Top, out tmp); 402 } 403 404 public override void Eval(IInternalPushInterpreter interpreter) { 405 var str = interpreter.StringStack.Pop(); 406 var value = double.Parse(str, CultureInfo.InvariantCulture); 407 408 interpreter.FloatStack.Push(value); 409 } 410 } 411 412 /// <summary> 413 /// Pushes the result of increasing the top INTEGER by 1. 414 /// </summary> 415 [PushExpression(StackTypes.Float, "FLOAT.INC")] 416 [StorableClass] 417 public class FloatIncExpression : StatelessExpression { 418 public FloatIncExpression() { } 419 [StorableConstructor] 420 protected FloatIncExpression(bool deserializing) : base(deserializing) { } 421 422 public override bool IsNoop(IInternalPushInterpreter interpreter) { 423 return interpreter.FloatStack.IsEmpty; 424 } 425 426 public override void Eval(IInternalPushInterpreter interpreter) { 427 interpreter.FloatStack.Top += 1; 428 } 429 } 430 431 /// <summary> 432 /// Pushes the result of decreasing the top INTEGER by 1. 433 /// </summary> 434 [PushExpression(StackTypes.Float, "FLOAT.DEC")] 435 [StorableClass] 436 public class FloatDecExpression : StatelessExpression { 437 public FloatDecExpression() { } 438 [StorableConstructor] 439 protected FloatDecExpression(bool deserializing) : base(deserializing) { } 440 441 public override bool IsNoop(IInternalPushInterpreter interpreter) { 442 return interpreter.FloatStack.IsEmpty; 443 } 444 445 public override void Eval(IInternalPushInterpreter interpreter) { 446 interpreter.FloatStack.Top -= 1; 447 } 448 } 364 449 }
Note: See TracChangeset
for help on using the changeset viewer.