danielgindi / Eval.net

Evaluate basic expressions (math,constants,logic,functions) in .NET runtime

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Eval.net

Easily evaluate simple expressions on the go...

This is a port of the BigEval.js library

Features:

  • Evaluate basic math operators (5 * (4 / 3))
  • Use constants (x * 27 / 4)
  • Support for pre-defined function calls (30 * pow(24, 6) / cos(20))
  • Support for custom function calls
  • Support for logic operators (26 * 3 < 100 - returns a bool value)
  • Support for bitwise operators ((1 << 2) == 4)
  • Support for string values ("test" + 5 == "test5")
  • Customize the type that is used for numeric values in the expression.
  • Customize the code behind the execution of any of the operators.
  • Support for compiling an expression and running multiple times while supplying different constants

Nuget

Install-Package Eval.net

Usage

using Eval.net;

var result1 = (double)Evaluator.Execute("12+45*10", EvalConfiguration.DoubleConfiguration);
var result2 = (double)Evaluator.Execute("30 * pow(24, 6) / cos(20)", EvalConfiguration.DoubleConfiguration);

var compiled = Evaluator.Compile("5 * n", EvalConfiguration.DoubleConfiguration.Clone());

compiled.SetConstant("n", 8);
var result3 = (double)compiled.Execute();

compiled.SetConstant("n", 9);
var result4 = (double)compiled.Execute();

Operators

The operators currently supported in order of precedence are -

[
	['!'],  // Factorial
	['**'],  // power
	['/', '*', '%'],
	['+', '-'],
	['<<', '>>'],  // bit shifts
	['<', '<=', '>', '>='],
	['==', '=', '!='],   // equality comparisons
	['&'], ['^'], ['|'],   // bitwise operations
	['&&'], ['||']   // logical operations
]

Me

  • Hi! I am Daniel Cohen Gindi. Or in short- Daniel.
  • danielgindi@gmail.com is my email address.
  • That's all you need to know.

Help

If you want to buy me a beer, you are very welcome to Donate Thanks :-)

License

This library is under the Apache License 2.0.

This library is free and can be used in commercial applications without royalty.

About

Evaluate basic expressions (math,constants,logic,functions) in .NET runtime

License:Apache License 2.0


Languages

Language:C# 100.0%