I encountered with an interesting mis calculation (bug) on Microsoft.JScript expression evaluator.
It calculates the following expression:
"-180.188+38.1-19.05-(57.15)+142.088+19.05+57.15+76.2-19.05-(57.15)"
It returns "-7.105427357601E-15" instead of 0 (Zero)
To Evaluate an expression in a C# class, we need to add Microsoft.JScript and call Eval.JScriptEvaluate method:
using Microsoft.JScript;
...
public static string EvalJScript(string equation)
{
return Eval.JScriptEvaluate(equation, Vsa.VsaEngine.CreateEngine()).ToString();
}
Tuesday, January 6, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment