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 abool
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
Install-Package Eval.net
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();
The operators currently supported in order of precedence are -
[
['!'], // Factorial
['**'], // power
['/', '*', '%'],
['+', '-'],
['<<', '>>'], // bit shifts
['<', '<=', '>', '>='],
['==', '=', '!='], // equality comparisons
['&'], ['^'], ['|'], // bitwise operations
['&&'], ['||'] // logical operations
]
- Hi! I am Daniel Cohen Gindi. Or in short- Daniel.
- danielgindi@gmail.com is my email address.
- That's all you need to know.
If you want to buy me a beer, you are very welcome to Thanks :-)
This library is under the Apache License 2.0.
This library is free and can be used in commercial applications without royalty.