Possible Duplicate:
Is JavaScript’s Math broken?
I wrote some simple C# code that runs Python code dynamically (already implemented):
string code = @"100 * 2 + 4 / 3";
ScriptEngine engine = Python.CreateEngine();
ScriptSource source = engine.CreateScriptSourceFromString(code, SourceCodeKind.Expression);
int res = source.Execute<int>();
Console.WriteLine(res);
And then I thought about Javascript, and that there are core differences between C# and JS. For example:
In JS:
var t=1.02+1.01 = 2.0300000000000002;
And then I tried this via Jint:
var script = @"
function add( ) {
return 1.02 + 1.01;
};
return add();";
var result = new JintEngine().Run(script);
Console.WriteLine(result);
The result was:
Maybe I don't see the whole picture, but if a programmer on the other side of the world sends me his script file, I (and him) expect the result to be consistent! (Let's ignore the problematic base 2 representation for now, I'm talking about consistency).
If I was mistaken, in what scenario would I use running other code on .Net? (I will have to be very very suspicious for every line of code...)
Am I right ?
another Example :
var script = @"
function show( )
{
return parseInt('123asd'); //in js it's 123
};
return show();";
var result = new JintEngine().Run(script);
Console.WriteLine(result);
result :
How can I trust a script to yield the same expected result ? ( or am I getting this whole situation wrong...?)