Skip to content

2.1.0

Compare
Choose a tag to compare
@AntonovAnton AntonovAnton released this 01 Oct 15:11
· 8 commits to main since this release
bf283fe

Improves:
Added the Evaluating event. #67

By using this event, you can debug or log the steps of a math expression's evaluation. This event is triggered at each step during the evaluation process. The following code demonstrates how to use to this event:

using var expression = new MathExpression("-3^4sin(-PI/2)", new ScientificMathContext());
expression.Evaluating += (object? sender, EvaluatingEventArgs args) =>
{
    Console.WriteLine("{0}: {1} = {2};{3}",
        args.Step,
        args.MathString[args.Start..(args.End + 1)],
        args.Value,
        args.IsCompleted ? " //completed" : string.Empty);
};
  
var value = expression.Evaluate();

Output:

1: 3^4 = 81;
2: PI = 3.141592653589793;
3: PI/2 = 1.5707963267948966;
4: -PI/2 = -1.5707963267948966;
5: sin(-PI/2) = -1;
6: 3^4sin(-PI/2) = -81;
7: -3^4sin(-PI/2) = 81; //completed

NOTE: The Evaluating event is cleaned up in the Dispose method. So I recommend using the using statement to ensure proper disposal.