sq / JSIL

CIL to Javascript Compiler
http://jsil.org/
Other
1.73k stars 241 forks source link

ulong math is incorrect #1047

Closed ghent360 closed 7 years ago

ghent360 commented 7 years ago

Sample code, entered in try.jsil.com

using System; public static class Program { public static void Main () { ulong x64 = 2 << 47; ulong y64 = x64 << 5; Console.WriteLine("Hello JSIL World!"); Console.WriteLine("{0}, {1}", x64, y64); } }

Generated code: ... (function Program$Members () { var $, $thisType; var $T00 = function () { return ($T00 = JSIL.Memoize($asm01.System.Console)) (); }; var $T01 = function () { return ($T01 = JSIL.Memoize($asm01.System.UInt64)) (); };

function Program_Main () { $T00().WriteLine("Hello JSIL World!"); $T00().WriteLine( "{0}, {1}", $T01().Create(65536, 0, 0), $T01().op_LeftShift($T01().Create(65536, 0, 0), 5) ); };

JSIL.MakeStaticClass("Program", true, [], function ($interfaceBuilder) { $ = $interfaceBuilder;

$.Method({Static:true , Public:true }, "Main", 
  JSIL.MethodSignature.Void, 
  Program_Main
);

return function (newThisType) { $thisType = newThisType; }; 

});

})();

Output: Hello JSIL World! 65536, 2097152

Expected: Hello JSIL World! 140737488355328, 4503599627370496

markusjohnsson commented 7 years ago

Your example program produces the same output on JSIL and .NET 4.5 (try for example dotnetfiddle.net). Where did you run it to get the expected output?

ghent360 commented 7 years ago

Sorry, my mistake. Should have been 1L << 47; It works fine when I fix the code.