2.1.0
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.