You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Asking for two things here, I'm trying to debug some funky results in an expression which is using formulas, ie the string expression: "Ability('Mass') * 1000000 * TechData('8557acb9-c764-44e7-8ee4-db2c2cebf0bc')"
This is giving me a funky result when the "Ability('Mass') is 8000.
First off, I want to know if I'm able to break the string expression up and display the results of the functions within the whole expression ie: Ability('Mass') = 8000 TechData('8557acb9-c764-44e7-8ee4-db2c2cebf0bc') = 1
I did see taht I could cast the ParsedExpression into a binary expression and see the Left and Right expressions, but that wasn't quite what I was after, and didn't seem to see a way to get the evaluated results from that. can I get something like that as a list?
Second, any ideas on what might be going wrong with the above expression?
The text was updated successfully, but these errors were encountered:
So yeah, the problem here seems to be integer overflow.
Mass in this case is a long, the 10000000 could be changed to 1000000.0, but that is really prone to not always happening, and while it makes for an easy quick fix in this particular case, it's not a long term solution.
tried casting Mass to a double where I thought ncalc would care but that didn't seem to fix the problem.
Expresson.Options has an OverflowProtection flag, but that didn't seem to make a difference here either.
I'd say just do all of the calculations in double, if the latter expressions are in double anyway. (There are of course things to consider with the precision of floating point numbers if you're actually building a real rocket engine based on these calculations, but I never took that course at uni so I can't advice on that 😃)
To play around with expressions, without just breaking them up into string parts and evaluating them directly, you can create a an EvaluationVisitor (https://github.com/ncalc/ncalc/blob/master/src/NCalc/Domain/EvaluationVisitor.cs) and pass it to the Visit() method of the left/right expressions you've identified above, and then access the Result property in the visitor. This is what NCalc is doing when you call the Evaluate method.
Asking for two things here, I'm trying to debug some funky results in an expression which is using formulas, ie the string expression:
"Ability('Mass') * 1000000 * TechData('8557acb9-c764-44e7-8ee4-db2c2cebf0bc')"
This is giving me a funky result when the
"Ability('Mass')
is 8000.First off, I want to know if I'm able to break the string expression up and display the results of the functions within the whole expression ie:
Ability('Mass') = 8000
TechData('8557acb9-c764-44e7-8ee4-db2c2cebf0bc') = 1
I did see taht I could cast the ParsedExpression into a binary expression and see the Left and Right expressions, but that wasn't quite what I was after, and didn't seem to see a way to get the evaluated results from that. can I get something like that as a list?
Second, any ideas on what might be going wrong with the above expression?
The text was updated successfully, but these errors were encountered: