Quantcast
Channel: NCalc - Mathematical Expressions Evaluator for .NET
Viewing all 58 articles
Browse latest View live

Reviewed: NCalc - 1.3.8 (Nov 07, 2016)

$
0
0
Rated 5 Stars (out of 5) - Had to implement a rapid prototype of charting functionality which relied on custom calculations provided by the end-user. Found this gem and implemented exactly what I needed in a matter of minutes. Very happy with this library. A+, all the way.

Created Unassigned: System.OverflowException [28357]

$
0
0
Whit this expressión:

"0 | 956301312"

The exception raised is:

System.OverflowException - > Value too large or too small for UInt16.


Some solution to avoid this exception???

Created Unassigned: Expression incorrectly evaluated for NaN operands [28358]

$
0
0
For the statements below:
```
string expression = "a > 0 && b < 10";
Expression e2 = new Expression(expression);
e2.Parameters["a"] = 10;
e2.Parameters["b"] = double.NaN;
Console.WriteLine(e2.Evaluate());
```
the result is "True". However, 10 > 0 && double.NaN < 10 should evaluate to false.

If one swaps the values for a and b, the e2's evaluation is correct, i.e. the e2 has value False.

Edited Unassigned: Expression incorrectly evaluated for NaN operands [28358]

$
0
0
For the statements below:
```
string expression = "a > 0 && b < 10";
Expression e2 = new Expression(expression);
e2.Parameters["a"] = 10;
e2.Parameters["b"] = double.NaN;
Console.WriteLine(e2.Evaluate());
```
the result is "True". However, 10 > 0 && double.NaN < 10 should evaluate to false.

If one swaps the values for a and b, the e2's evaluation is correct, i.e. e2 evaluates to False.

Created Unassigned: BigInteger issue [28359]

$
0
0
Hello,
I tried to create a custom function fact() with BigInteger parameters for counting factorial with big numbers.
If I use just the function itself then there is no issue but it is not working when I use this function with another mathematic operation.
E.g. fact(5) ---> result 120 - OK
fact(5)+1----> expression not working
If I change parameters from BigInteger to Int or Decimal then everything is working but I can't calculate factorial for bigger numbers (e.g fact(28) is too large value).

Can someone help me?
Could you please add also BigInteger expression support?

Edited Unassigned: BigInteger issue [28359]

$
0
0
Hello,
I tried to create a custom function fact() with BigInteger parameters for counting factorial with big numbers.
If I use just the function itself then there is no issue but it is not working when I use this function with another mathematic operation.
E.g. fact(5) ---> result 120 - OK
fact(5)+1----> expression not working
If I change parameters from BigInteger to Int or Decimal then everything is working but I can't calculate factorial for bigger numbers (e.g fact(28) is too large value).

OK, easy solution found:
convert result of fact(5) to string and then run expression evaluation :)

Edited Unassigned: BigInteger issue [28359]

$
0
0
Hello,
I tried to create a custom function fact() with BigInteger parameters for counting factorial with big numbers.
If I use just the function itself then there is no issue but it is not working when I use this function with another mathematic operation.
E.g. fact(5) ---> result 120 - OK
fact(5)+1----> expression not working
If I change parameters from BigInteger to Int or Decimal then everything is working but I can't calculate factorial for bigger numbers (e.g fact(28) is too large value).

-----------------------------------------------------------------------------------------------------
OK, easy solution found:
convert result of fact(5) to string and then run expression evaluation :)

Edited Unassigned: BigInteger issue [28359]

$
0
0
Hello,
I tried to create a custom function fact() with BigInteger parameters for counting factorial with big numbers.
If I use just the function itself then there is no issue but it is not working when I use this function with another mathematic operation.
E.g. fact(5) ---> result 120 - OK
fact(5)+1----> expression not working
If I change parameters from BigInteger to Int or Decimal then everything is working but I can't calculate factorial for bigger numbers (e.g fact(28) is too large value).

-----------------------------------------------------------------------------------------------------
OK, easy solution found:
convert result of fact(5) to string and then run expression evaluation :)

Edited Unassigned: BigInteger issue [28359]

$
0
0
Hello,
I tried to create a custom function fact() with BigInteger parameters for counting factorial with big numbers.
If I use just the function itself then there is no issue but it is not working when I use this function with another mathematic operation.
E.g. fact(5) ---> result 120 - OK
fact(5)+1----> expression not working

If I change parameters from BigInteger to Int or Decimal then everything is working but I can't calculate factorial for bigger numbers (e.g fact(28) is too large value).

-----------------------------------------------------------------------------------------------------
OK, easy solution found:
convert result of fact(5) to string and then run expression evaluation :)

Edited Unassigned: BigInteger issue [28359]

$
0
0
Hello,
I tried to create a custom function fact() with BigInteger parameters for counting factorial with big numbers.
If I use just the function itself then there is no issue but it is not working when I use this function with another mathematic operation.
E.g. fact(5) ---> result 120 - OK
fact(5)+1----> expression not working

If I change parameters from BigInteger to Int or Decimal then everything is working but I can't calculate factorial for bigger numbers (e.g fact(28) is too large value).

SOLUTION:
__OK, easy solution found:
convert result of fact(5) to string and then run expression evaluation :)__

Edited Unassigned: BigInteger issue [28359]

$
0
0
Hello,
I tried to create a custom function fact() with BigInteger parameters for counting factorial with big numbers.
If I use just the function itself then there is no issue but it is not working when I use this function with another mathematic operation.
E.g. fact(5) ---> result 120 - OK
fact(5)+1----> expression not working

If I change parameters from BigInteger to Int or Decimal then everything is working but I can't calculate factorial for bigger numbers (e.g fact(28) is too large value).

__Please add biginteger support!__

Reviewed: NCalc - 1.3.8 (Mar 03, 2017)

$
0
0
Rated 5 Stars (out of 5) - Bella funzionalità ! Complimenti

New Post: Strange behavior of Evaluate function

$
0
0
Hi,
I'm using NCalc in my application and I have a "casting" problem.
This is my input value: [P]=[FFFF;HEX]
This is my expression : (([P]AND[01;HEX])LS_4)=[10;HEX]

This works fine.
If I set input value: [P]=[1FFFF;HEX]

I have following exception: Value was either too large or too small for a UInt16.

Thanks in advance.

Updated Wiki: Home

$
0
0

IMPORTANT INFORMATION

This repository is no longer maintained. The source code has been moved to Github by James Cane and will provide support. https://github.com/sheetsync/NCalc
Alternatively you can use Jint which I still maintain and might be more adapted to your needs: https://github.com/sebastienros/jint

Project Description

NCalc is a mathematical expressions evaluator in .NET. NCalc can parse any expression and evaluate the result, including static or dynamic parameters and custom functions.

For additional information on the technique we used to create this framework please read this article: http://www.codeproject.com/KB/recipes/sota_expression_evaluator.aspx.

For documentation here is the table of content:
  • description : overall concepts, usage and extensibility points
  • operators : available standard operators and structures
  • values : authorized values like types, functions, ...
  • functions : list of already implemented functions
  • parameters : on how to use parameters expressions

Functionnalities

Simple expressions

  Expression e = new Expression("2 + 3 * 5");
  Debug.Assert(17 == e.Evaluate());

Evaluates .NET data types

  Debug.Assert(123456 == new Expression("123456").Evaluate()); // integers
  Debug.Assert(new DateTime(2001, 01, 01) == new Expression("#01/01/2001#").Evaluate()); // date and times
  Debug.Assert(123.456 == new Expression("123.456").Evaluate()); // floating point numbers
  Debug.Assert(true == new Expression("true").Evaluate()); // booleans
  Debug.Assert("azerty" == new Expression("'azerty'").Evaluate()); // strings

Handles mathematical functional from System.Math

  Debug.Assert(0 == new Expression("Sin(0)").Evaluate());
  Debug.Assert(2 == new Expression("Sqrt(4)").Evaluate());
  Debug.Assert(0 == new Expression("Tan(0)").Evaluate());

Evaluates custom functions

  Expression e = new Expression("SecretOperation(3, 6)");
  e.EvaluateFunction += delegate(string name, FunctionArgs args)
      {
          if (name == "SecretOperation")
              args.Result = (int)args.Parameters[0].Evaluate() + (int)args.Parameters[1].Evaluate();
      };
  
  Debug.Assert(9 == e.Evaluate());

Handles unicode characters

  Debug.Assert("経済協力開発機構" == new Expression("'経済協力開発機構'").Evaluate());
  Debug.Assert("Hello" == new Expression(@"'\u0048\u0065\u006C\u006C\u006F'").Evaluate());
  Debug.Assert("だ" == new Expression(@"'\u3060'").Evaluate());
  Debug.Assert("\u0100" == new Expression(@"'\u0100'").Evaluate());

Define parameters, even dynamic or expressions

  Expression e = new Expression("Round(Pow([Pi], 2) + Pow([Pi2], 2) + [X], 2)");

  e.Parameters["Pi2"] = new Expression("Pi * [Pi]");
  e.Parameters["X"] = 10;

  e.EvaluateParameter += delegate(string name, ParameterArgs args)
    {
      if (name == "Pi")
      args.Result = 3.14;
    };

  Debug.Assert(117.07 == e.Evaluate());

Updated Wiki: Home

$
0
0

IMPORTANT INFORMATION

This repository is no longer maintained. The source code has been moved to Github by James Cane and will provide support. https://github.com/sheetsync/NCalc
Alternatively you can use Jint which I still maintain and might be more adapted to your needs: https://github.com/sebastienros/jint

Project Description

NCalc is a mathematical expressions evaluator in .NET. NCalc can parse any expression and evaluate the result, including static or dynamic parameters and custom functions.

For additional information on the technique we used to create this framework please read this article: http://www.codeproject.com/KB/recipes/sota_expression_evaluator.aspx.

For documentation here is the table of content:
  • description : overall concepts, usage and extensibility points
  • operators : available standard operators and structures
  • values : authorized values like types, functions, ...
  • functions : list of already implemented functions
  • parameters : on how to use parameters expressions

Functionnalities

Simple expressions

  Expression e = new Expression("2 + 3 * 5");
  Debug.Assert(17 == e.Evaluate());

Evaluates .NET data types

  Debug.Assert(123456 == new Expression("123456").Evaluate()); // integers
  Debug.Assert(new DateTime(2001, 01, 01) == new Expression("#01/01/2001#").Evaluate()); // date and times
  Debug.Assert(123.456 == new Expression("123.456").Evaluate()); // floating point numbers
  Debug.Assert(true == new Expression("true").Evaluate()); // booleans
  Debug.Assert("azerty" == new Expression("'azerty'").Evaluate()); // strings

Handles mathematical functional from System.Math

  Debug.Assert(0 == new Expression("Sin(0)").Evaluate());
  Debug.Assert(2 == new Expression("Sqrt(4)").Evaluate());
  Debug.Assert(0 == new Expression("Tan(0)").Evaluate());

Evaluates custom functions

  Expression e = new Expression("SecretOperation(3, 6)");
  e.EvaluateFunction += delegate(string name, FunctionArgs args)
      {
          if (name == "SecretOperation")
              args.Result = (int)args.Parameters[0].Evaluate() + (int)args.Parameters[1].Evaluate();
      };
  
  Debug.Assert(9 == e.Evaluate());

Handles unicode characters

  Debug.Assert("経済協力開発機構" == new Expression("'経済協力開発機構'").Evaluate());
  Debug.Assert("Hello" == new Expression(@"'\u0048\u0065\u006C\u006C\u006F'").Evaluate());
  Debug.Assert("だ" == new Expression(@"'\u3060'").Evaluate());
  Debug.Assert("\u0100" == new Expression(@"'\u0100'").Evaluate());

Define parameters, even dynamic or expressions

  Expression e = new Expression("Round(Pow([Pi], 2) + Pow([Pi2], 2) + [X], 2)");

  e.Parameters["Pi2"] = new Expression("Pi * [Pi]");
  e.Parameters["X"] = 10;

  e.EvaluateParameter += delegate(string name, ParameterArgs args)
    {
      if (name == "Pi")
      args.Result = 3.14;
    };

  Debug.Assert(117.07 == e.Evaluate());

Created Unassigned: simulate Looping using NCalc [28360]

$
0
0

I am using NCalc (Codeplex library) to evaluate expressions from a text file. I want to simulate a loop like this :

int i = 0;
do {
Console.WriteLine("Value of I is :: {0}", i);
i++;
} while (i<5);
The issue is I am not sure how we can increment and continue looping. Can anyone let me know how we can achieve looping using NCalc ?

New Post: Decimal separator

$
0
0
Hi,
Is there any way to change decimal separator? I noticed when using for instance comma rather than dot in Region settings of decimal separator i get error of decimal when using formula comming from string. Is this completly embded within Ncalc that dot is defauilt or could it be taken from region settings? From what i see it just use dot and not lok at region settings.

Created Unassigned: Array compare [HELP] [28361]

$
0
0
Hello guys,

I'm trying to compare a array of elements to one value, is there any way to do that using ncalc?

Example:

new Expression(ruleExpression.Replace(" [1,2,3] > 1 and 2 < 3 and 2 == 2").Evaluate();

The result that I want is FALSE to ([1,2,3] > 1 ), because not all elements respect the rule.




Viewing all 58 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>