0
I’m using the Ncalc lib
A simple formula such as "Abs(-1) + Cos(2)" gives the following exception:
Operator '+' can’t be Applied to operands of types 'decimal' and 'double'
Why? How to solve?
The calculation is to be executed as follows:
new Expression("Abs(-1) + Cos(2)").Evaluate()
The only related discussion on the project website is a bit old and talks about editing the source code https://ncalc.codeplex.com/discussions/346702
Your answer is not constructive. You just translated the exception text. My question is that Math.Abs(-1)+Math.Cos(2) works in C# but not in the Ncalc library. If you’ve never used or know the library or should be commenting here.
– pitermarx
OK, no problem.
– PauloHDSousa
@Omni and all. Please do not throw suggestions into the air. If you have never used NCALC you will not understand my question. 1º I cannot pass -1m and 2m because they are not valid numbers. 2º It is not the Abs and Cos parameters that have the problem. It is the sum of the result of Abs and Cos
– pitermarx
One of the functions,
Abs
orCos
, is returning a valuedecimal
and another is returning onedouble
. I believe that if you have access to the lib source it would be better to change the return type of one of the functions to avoid the error or use some type conversion feature if it has.– Richard Dias
@Richarddias, lib is open source. I have already asked the question on codeplex I don’t have enough knowledge to try to figure out if it’s a code problem or if I’m doing something wrong on my side.
– pitermarx
I believe it is lib or a misuse of it on your part. You pass a
string
for the class constructorExpression
and this string is evaluated and transformed into a correct formula?– Richard Dias
I think you already have the answer in your question: https://ncalc.codeplex.com/discussions/346702 Now put your hands in the dough and change the source code to fix this problem
– Richard Dias
I don’t understand NCALC, but its expression is in double quotes, so I understand that it would be a concatenation and not a sum, not an arithmetic expression.
– pnet