You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running the following throws and exception, that the variable "pi" was not found:
CalculationEngine engine = new CalculationEngine(CultureInfo.InvariantCulture, ExecutionMode.Interpreted);
Func<Dictionary<string, double>, double> formula = engine.Build("pi");
Dictionary<string, double> variables = new Dictionary<string, double>();
double result = formula(variables);
However, when running this with ExecutionMode.Compiled it works as expected.
The difference is, that Interpreter that is used in ExecutionMode.Interpreted does not check for constants as DynamicCompiler does that is used in ExecutionMode.Compiled:
private static class PrecompiledMethods
{
public static double GetVariableValueOrThrow(string variableName, FormulaContext context)
{
if (context.Variables.TryGetValue(variableName, out double result))
return result;
else if (context.ConstantRegistry.IsConstantName(variableName))
return context.ConstantRegistry.GetConstantInfo(variableName).Value;
else
throw new VariableNotDefinedException($"The variable \"{variableName}\" used is not defined.");
}
}
I will create a pull request where this check of the ConstantRegistry is added to the Interpreter.
The text was updated successfully, but these errors were encountered:
Running the following throws and exception, that the variable "pi" was not found:
However, when running this with
ExecutionMode.Compiled
it works as expected.The difference is, that
Interpreter
that is used inExecutionMode.Interpreted
does not check for constants asDynamicCompiler
does that is used inExecutionMode.Compiled
:I will create a pull request where this check of the ConstantRegistry is added to the
Interpreter
.The text was updated successfully, but these errors were encountered: