1.1 --- a/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_Number.js Mon Jan 14 13:21:40 2013 +0100
1.2 +++ b/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_Number.js Fri Jan 25 11:00:52 2013 +0100
1.3 @@ -6,4 +6,66 @@
1.4 };
1.5
1.6 Number.prototype.toInt8 = function() { return (this << 24) >> 24; };
1.7 -Number.prototype.toInt16 = function() { return (this << 16) >> 16; };
1.8 \ No newline at end of file
1.9 +Number.prototype.toInt16 = function() { return (this << 16) >> 16; };
1.10 +
1.11 +var Long = function(low, hi) {
1.12 + this.low = low;
1.13 + this.hi = hi;
1.14 +};
1.15 +
1.16 +function LongFromNumber(x) {
1.17 + return new Long(x % 0xFFFFFFFF, Math.floor(x / 0xFFFFFFFF));
1.18 +};
1.19 +
1.20 +function MakeLong(x) {
1.21 + if ((x.hi == undefined) && (x.low == undefined)) {
1.22 + return LongFromNumber(x);
1.23 + }
1.24 + return x;
1.25 +};
1.26 +
1.27 +Long.prototype.toInt32 = function() { return this.low | 0; };
1.28 +Long.prototype.toFP = function() { return this.hi * 0xFFFFFFFF + this.low; };
1.29 +
1.30 +Long.prototype.toString = function() {
1.31 + return String(this.toFP());
1.32 +};
1.33 +
1.34 +Long.prototype.valueOf = function() {
1.35 + return this.toFP();
1.36 +};
1.37 +
1.38 +Long.prototype.compare64 = function(x) {
1.39 + if (this.hi == x.hi) {
1.40 + return (this.low == x.low) ? 0 : ((this.low < x.low) ? -1 : 1);
1.41 + }
1.42 + return (this.hi < x.hi) ? -1 : 1;
1.43 +};
1.44 +
1.45 +Long.prototype.add64 = function(x) {
1.46 + low = this.low + x.low;
1.47 + carry = 0;
1.48 + if (low > 0xFFFFFFFF) {
1.49 + carry = 1;
1.50 + low -= 0xFFFFFFFF;
1.51 + }
1.52 + hi = (this.hi + x.hi + carry) & 0xFFFFFFFF;
1.53 + return new Long(low, hi);
1.54 +};
1.55 +
1.56 +Long.prototype.div64 = function(x) {
1.57 + return LongFromNumber(Math.floor(this.toFP() / x.toFP()));
1.58 +};
1.59 +
1.60 +Long.prototype.shl64 = function(x) {
1.61 + if (x > 32) {
1.62 + hi = (this.low << (x - 32)) & 0xFFFFFFFF;
1.63 + low = 0;
1.64 + } else {
1.65 + hi = (this.hi << x) & 0xFFFFFFFF;
1.66 + low_reminder = this.low >> x;
1.67 + hi |= low_reminder;
1.68 + low = this.low << x;
1.69 + }
1.70 + return new Long(low, hi);
1.71 +};