Skip to content

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

License

Notifications You must be signed in to change notification settings

danielgindi/Eval.net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages