diff options
Diffstat (limited to 'js/src/Ice/Long.js')
-rw-r--r-- | js/src/Ice/Long.js | 143 |
1 files changed, 70 insertions, 73 deletions
diff --git a/js/src/Ice/Long.js b/js/src/Ice/Long.js index 1445b4098e9..73ecbc976d9 100644 --- a/js/src/Ice/Long.js +++ b/js/src/Ice/Long.js @@ -7,94 +7,91 @@ // // ********************************************************************** -(function(global){ - require("Ice/Class"); +var Ice = require("../Ice/Class").Ice; - // - // The Long type represents a signed 64-bit integer as two 32-bit values - // corresponding to the high and low words. - // - var Ice = global.Ice || {}; +// +// The Long type represents a signed 64-bit integer as two 32-bit values +// corresponding to the high and low words. +// - var Long = Ice.Class({ - __init__: function(high, low) +var Long = Ice.Class({ + __init__: function(high, low) + { + this.high = high; + this.low = low; + }, + hashCode: function() + { + return this.low; + }, + equals: function(rhs) + { + if(this === rhs) { - this.high = high; - this.low = low; - }, - hashCode: function() + return true; + } + if(!(rhs instanceof Long)) { - return this.low; - }, - equals: function(rhs) + return false; + } + return this.high === rhs.high && this.low === rhs.low; + }, + toString: function() + { + return this.high + ":" + this.low; + }, + toNumber: function() + { + if((this.high & Long.SIGN_MASK) !== 0) { - if(this === rhs) - { - return true; - } - if(!(rhs instanceof Long)) + var low = ~this.low; + var high = ~this.high; + if(low < 0xFFFFFFFF) { - return false; + low += 1; } - return this.high === rhs.high && this.low === rhs.low; - }, - toString: function() - { - return this.high + ":" + this.low; - }, - toNumber: function() - { - if((this.high & Long.SIGN_MASK) != 0) + else { - var low = ~this.low; - var high = ~this.high; - if(low < 0xFFFFFFFF) - { - low += 1; - } - else + low = 0; + high += 1; + if(high > Long.HIGH_MAX) { - low = 0; - high += 1; - if(high > Long.HIGH_MAX) - { - return Number.NEGATIVE_INFINITY; - } + return Number.NEGATIVE_INFINITY; } - return -1 * (high * Long.HIGH_MASK) + low; } - else + return -1 * (high * Long.HIGH_MASK) + low; + } + else + { + if(this.high > Long.HIGH_MAX) { - if(this.high > Long.HIGH_MAX) - { - return Number.POSITIVE_INFINITY; - } - return (this.high * Long.HIGH_MASK) + this.low; + return Number.POSITIVE_INFINITY; } + return (this.high * Long.HIGH_MASK) + this.low; } - }); + } +}); - // - // (high & SIGN_MASK) != 0 denotes a negative number; - // that is, the most significant bit is set. - // - Long.SIGN_MASK = 0x80000000; +// +// (high & SIGN_MASK) != 0 denotes a negative number; +// that is, the most significant bit is set. +// +Long.SIGN_MASK = 0x80000000; - // - // When converting to a JavaScript Number we left shift the - // high word by 32 bits. As that isn't possible using JavaScript's - // left shift operator, we multiply the value by 2^32 which will - // produce the same result. - // - Long.HIGH_MASK = 0x100000000; +// +// When converting to a JavaScript Number we left shift the +// high word by 32 bits. As that isn't possible using JavaScript's +// left shift operator, we multiply the value by 2^32 which will +// produce the same result. +// +Long.HIGH_MASK = 0x100000000; - // - // The maximum value for the high word when coverting to - // a JavaScript Number is 2^21 - 1, in which case all - // 53 bits are used. - // - Long.HIGH_MAX = 0x1FFFFF; +// +// The maximum value for the high word when coverting to +// a JavaScript Number is 2^21 - 1, in which case all +// 53 bits are used. +// +Long.HIGH_MAX = 0x1FFFFF; - Ice.Long = Long; - global.Ice = Ice; -}(typeof (global) === "undefined" ? window : global)); +Ice.Long = Long; +module.exports.Ice = Ice; |