sq / JSIL

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

The external method 'System.Decimal Round(System.Decimal)' of type 'System.Math' has not been implemented. #942

Open ghost opened 8 years ago

ghost commented 8 years ago

Loading data ... failed. Unhandled exception at http://localhost/devbox/jsil/thhd/JSIL/lib/IgnoredBCL/JSIL.Bootstrap.js line 1515: Uncaught TypeError: Cannot read property 'valueOf' of undefined

The JSIL:

var decimalToNumber = function (decimal) { return decimal.valueOf(); };

kg commented 8 years ago

Need a stack trace, at the very least.

ghost commented 8 years ago

The external method 'System.Decimal Round(System.Decimal)' of type 'System.Math' has not been implemented. at Object.JSIL.Host.warning (http://localhost/devbox/jsil/thhd/JSIL/lib/JSIL.Host.js:153:15) at Object.JSIL.WarningFormat (http://localhost/devbox/jsil/thhd/JSIL/lib/JSIL.Core.js:10666:13) at Object.ExternalMemberStub as Round$215=215 at Object.PreInitMethod_Invoke (http://localhost/devbox/jsil/thhd/JSIL/lib/JSIL.Core.js:766:21) at MethodSignature_CallStatic$0$1$inlineCache1 (jsil://closure/MethodSignature.CallStatic$0$1$inlineCache1:10:35) at Object.Thunderhead_Initialize (http://localhost/devbox/jsil/thhd/Thunderhead,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null.js:1512:69) at Object.Game_Run (http://localhost/devbox/jsil/thhd/JSIL/lib/XNA/XNA4.js:1371:10) at runMain (http://localhost/devbox/jsil/thhd/:58:14) at browserFinishedLoadingCallback (http://localhost/devbox/jsil/thhd/JSIL/lib/JSIL.Browser.js:1139:9

ghost commented 8 years ago

Oh i see you haven't implemented it; what alternative should I use?

kg commented 8 years ago

Decimal arithmetic isn't implemented, there's just a basic shim in there so simple things will work. If you use 'double', Round will work. Naturally, the precision is not good. If you need arbitrary-precision arithmetic right now the best choice would be to lift an off-the-shelf JS library for it (i'm not aware of one off the top of my head).

Decimal is tricky to implement because it's not written in C#, so we can't cross-compile it from Mono or the MS CLR. It'll have to be implemented manually at some point.

ghost commented 8 years ago

thank you. should i close the issue?

kg commented 8 years ago

It doesn't work, so leave it open :-)

iskiselev commented 8 years ago

As now decimal is just proxy for int, this method could easily be implemented or replaced through JSReplace (but it still be nothing more than a wrapper on double).

There is open decimal implementation in C++ in coreclr. It is not very hard to rewrite it back to C#, but there are a lot of code, so it will take a lot of time (I've started it some time ago, spend half of day and stopped that work).