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

New Post: Logical Operators explanation

$
0
0
I assume something like this is possible but I haven't figured out how.

Say I create a textbox where users can type in logical expressions, like, "A and B or (C and D) or E".

Is there a way I can give that logic to NCalc as well as an array of values, say [A, C, F] and have it return true or false if my values are valid according to the given logic? In this case it would be false.

New Post: Operator '+' can't be applied to operands of types 'decimal' and 'double'

$
0
0
A simple formula like

new Expression("Abs(-1) + Cos(2)").Evaluate()
throws the exception

Operator '+' can't be applied to operands of types 'decimal' and 'double'
Why is this?

Is there any workaround?

The only thread i found on the project's website related to this error is quite old and talks about editing the source code. https://ncalc.codeplex.com/discussions/346702

Im using the latest version

Reviewed: NCalc - 1.3.8 (Mar 27, 2015)

$
0
0
Rated 5 Stars (out of 5) - thanks. It's very simple and strongly!

Commented Unassigned: NCalc fails with Antlr versions 3.4.1 and newer [28341]

$
0
0
NCalc fails to compile when a newer version of Antlr is used. This expects 3.3.0.7239.

What is the best way to go about updating NCalc to use Antlr3 version 3.4.1.9004 or newer?

Has anyone re-created the grammar file and got it working with Antlr 3.4+ ?
Comments: Hi, I'm having a similar issue trying to rebuild with version 3.5.0.2. If you have a working version, I'd love to see what changes you had to make (I'm not familiar with Antlr myself).

Commented Unassigned: NCalc fails with Antlr versions 3.4.1 and newer [28341]

$
0
0
NCalc fails to compile when a newer version of Antlr is used. This expects 3.3.0.7239.

What is the best way to go about updating NCalc to use Antlr3 version 3.4.1.9004 or newer?

Has anyone re-created the grammar file and got it working with Antlr 3.4+ ?
Comments: check my 2 github repos. https://github.com/pitermarx/NCalc-Edge -> im using this one and https://github.com/pitermarx/NCalc2

Created Unassigned: Evaluate is rounding automatically [28343]

$
0
0
Hi,

I have the next expression: 47.064038287157*378800.000000000000*1.007900000000

As you can see, each decimal number in the expression has 12 decimal digits.

When I evaluate the expression, the result is the following: 17968697.7790302

I don't know why NCalc is throwing away 5 decimal digits.

Ncalc automatically is rounding to 7 decimal digits and I need my final result with 12 decimal digits.

This is my code:

var expression = new Expression(formula);
object resultadoFinal = expression.Evaluate();

I appreciate any help.

Warm regards,


JUAN GIRALDO

Commented Unassigned: Evaluate is rounding automatically [28343]

$
0
0
Hi,

I have the next expression: 47.064038287157*378800.000000000000*1.007900000000

As you can see, each decimal number in the expression has 12 decimal digits.

When I evaluate the expression, the result is the following: 17968697.7790302

I don't know why NCalc is throwing away 5 decimal digits.

Ncalc automatically is rounding to 7 decimal digits and I need my final result with 12 decimal digits.

This is my code:

var expression = new Expression(formula);
object resultadoFinal = expression.Evaluate();

I appreciate any help.

Warm regards,


JUAN GIRALDO
Comments: NCalc isn't doing any rounding. Your object resultadoFinal is a double that has the exact result, i.e. 17968697,779030155 the way you are showing it is probably givin you that result. see this https://msdn.microsoft.com/en-us/library/kfsatb94.aspx

Edited Unassigned: Evaluate is rounding automatically [28343]

$
0
0
Hi,

I have the next expression: 47.064038287157*378800.000000000000*1.007900000000

As you can see, each decimal number in the expression has 12 decimal digits.

When I evaluate the expression, the result is the following: 17968697.7790302

I don't know why NCalc is throwing away 5 decimal digits.

Ncalc automatically is rounding to 7 decimal digits and I need my final result with 12 decimal digits.

This is my code:

var expression = new Expression(formula);
object resultadoFinal = expression.Evaluate();

I appreciate any help.

Warm regards,


JUAN GIRALDO

New Post: Case insensitivity not working for parameters

$
0
0
I found that if I created a new Dictionary using the StringComparer.OrdinalIgnoreCase and then set the Parameters property for the expression to this dictionary it was case insensitive for the Parameters.

My next problem is how to make the operators case insensitive too, so we could use "OR" or "or" at the moment it is still case sensitive.

Here's my code:
        Dim Vars As New Dictionary(Of String, Object)(StringComparer.OrdinalIgnoreCase)

        For i As Integer = 1 To 5000
            Vars.Add(String.Format("My value.Val{0}", i), Math.Sqrt(i))
        Next

        ce = New Expression(Me.txExpression.Text, EvaluateOptions.IgnoreCase)
        ce.Parameters = Vars
        Dim res = ce.Evaluate
        Me.lblRes.Text = res

Created Unassigned: Expression.Evaluate() gives wrong output [28344]

$
0
0
I have an expression
15617031.48= 15226149.00+166208.36+0.00+224674.12

This expression should give result as "true" but it will give "false" result. Please suggest something.

Thanks

Commented Unassigned: Expression.Evaluate() gives wrong output [28344]

$
0
0
I have an expression
15617031.48= 15226149.00+166208.36+0.00+224674.12

This expression should give result as "true" but it will give "false" result. Please suggest something.

Thanks
Comments: Floating point numbers might not be represented the same way in both sides. You should try to put a breakpoint on the '=' operator evaluation in the source code, and see what is happening.

Commented Unassigned: Expression.Evaluate() gives wrong output [28344]

$
0
0
I have an expression
15617031.48= 15226149.00+166208.36+0.00+224674.12

This expression should give result as "true" but it will give "false" result. Please suggest something.

Thanks
Comments: We have code like ncalcFormula = "[OD1000]=[OD1100]+[OD1200]+[OD1350]+[OD1450]" var expression = new Expression(ncalcFormula); foreach (FormulaParameter fp in parsedParameters) { expression.Parameters[fp.QuestionKey] = fp.Value; } object res = expression.Evaluate(); Original expression :- [OD1000]=[OD1100]+[OD1200]+[OD1350]+[OD1450] After Evaluate called Parsed expression :- {([OD1000])= (((([OD1100])+ ([OD1200])+ ([OD1350])+ ([OD1450])} Tested with adding parameter values as follows 1) 9.33 = 2.25 + 3.25 + 1.5 + 2.33 2) 15617031.48 = 15226149.36 + 166208.00 + 0.00 + 224674.12 After evaluate 1) will return true and 2) will return false though both expression are correct. Please suggest.

Commented Unassigned: Expression.Evaluate() gives wrong output [28344]

$
0
0
I have an expression
15617031.48= 15226149.00+166208.36+0.00+224674.12

This expression should give result as "true" but it will give "false" result. Please suggest something.

Thanks
Comments: if you want exact calculations you should use decimal instead of float. Try casting fp.Value to decimal

Created Unassigned: Change ^ to mean Pow [28345]

$
0
0
It is silly to have ^ to be the XOR operation given that, outside the programming realm, _virtually nobody_ really needs XOR for anything. It is equally silly to type Pow(x,2) when you need x^2. So how about changing the default behavior in order to support ^ as the power operator rather than XOR?

New Post: The '^' character

$
0
0
The version of the dll I currently have (downloaded yesterday) still does not process the '^' character and recognise it as being to the power of.

For example (5*2)^2 = 8 currently but should = 100.

Is this working in a later version or do i need to process and use the pow() function?

Created Unassigned: wrong calculation [28346]

$
0
0
2119283916 + 151200000 = - 663683380 (!) instead of = 3631283916

Created Unassigned: commas are not accepted as decimal separator [28347]

$
0
0
commas are not accepted as decimal separator

Reviewed: NCalc - 1.3.8 (сен 01, 2015)

$
0
0
Rated 1 Stars (out of 5) - disappointing mistakes at calculation period

Created Unassigned: Wrong Calculation [28348]

$
0
0
Wrong Calculation

Is calculated as
(1661643404*8.0)/(1000000*3600) = -19.12773

Version 1.3.8

Commented Unassigned: Wrong Calculation [28348]

$
0
0
Wrong Calculation

Is calculated as
(1661643404*8.0)/(1000000*3600) = -19.12773

Version 1.3.8
Comments: sorry * was missing (1661643404 * 8.0)/(1000000 * 3600) = -19.12773
Viewing all 58 articles
Browse latest View live


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