nreco / lambdaparser

Runtime parser for string expressions (formulas, method calls). Builds dynamic LINQ expression tree and compiles it to lambda delegate.
http://www.nrecosite.com/
MIT License
309 stars 55 forks source link

Math Operations like power (exponentiate) and to extract a root -possible? #31

Closed tobiasdroessler closed 4 years ago

tobiasdroessler commented 4 years ago

Is it both possible and ready to use ?

Or is there a possibility to register external functions to extent feature set?

ref to dotnet math: (https://docs.microsoft.com/de-de/dotnet/api/system.math.pow?view=netcore-3.1)

VitaliyMF commented 4 years ago

You can easily register any API that you want to expose for expressions in this way:

class MathFunctions {
  public double Pow(double x, double y) => Math.Pow(x,y);
}

varContext["Math"] = new MathFunctions();
Console.WriteLine(lambdaParser.Eval("Math.Pow(2,2)", varContext));
tobiasdroessler commented 4 years ago

ah, thank you .. now I get it !!

Thats nice.