emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js
1 // empty line needed here
2 Number.prototype.add32 = function(x) { return (this + x) | 0; };
3 Number.prototype.sub32 = function(x) { return (this - x) | 0; };
4 Number.prototype.mul32 = function(x) {
5 return (((this * (x >> 16)) << 16) + this * (x & 0xFFFF)) | 0;
8 Number.prototype.toInt8 = function() { return (this << 24) >> 24; };
9 Number.prototype.toInt16 = function() { return (this << 16) >> 16; };
11 Number.prototype.next32 = function(low) {
15 var l = new Number(low);
20 Number.prototype.high32 = function() {
21 return this.hi ? this.hi : (Math.floor(this / 0xFFFFFFFF)) | 0;
23 Number.prototype.toInt32 = function() { return this | 0; };
24 Number.prototype.toFP = function() {
25 return this.hi ? this.hi * 0xFFFFFFFF + this : this;
27 Number.prototype.toLong = function() {
28 var hi = (this > 0xFFFFFFFF) ? (Math.floor(this / 0xFFFFFFFF)) | 0 : 0;
29 return hi.next32(this % 0xFFFFFFFF);
32 Number.prototype.add64 = function(x) {
35 if (low > 0xFFFFFFFF) {
37 low -= 0xFFFFFFFF; // should not here be also -1?
39 var hi = (this.high32() + x.high32() + carry) & 0xFFFFFFFF;
40 return hi.next32(low);
43 Number.prototype.div64 = function(x) {
44 var low = Math.floor(this.toFP() / x.toFP()); // TODO: not exact enough
45 if (low > 0xFFFFFFFF) {
46 var hi = Math.floor(low / 0xFFFFFFFF) | 0;
47 return hi.next32(low % 0xFFFFFFFF);
52 Number.prototype.shl64 = function(x) {
54 var hi = (this << (x - 32)) & 0xFFFFFFFF;
57 var hi = (this.high32() << x) & 0xFFFFFFFF;
58 var low_reminder = this >> x;
61 return hi.next32(low);
65 Number.prototype.compare64 = function(x) {
66 if (this.hi == x.hi) {
67 return (this == x) ? 0 : ((this < x) ? -1 : 1);
69 return (this.hi < x.hi) ? -1 : 1;