Comparing version 1.1.1 to 1.1.2
@@ -60,2 +60,11 @@ /* | ||
/** | ||
* @param {number} part0 | ||
* @param {number} part1 | ||
* @param {number} part2 | ||
* @param {boolean=} unsigned | ||
* @return {!Long} | ||
*/ | ||
Long.from28Bits = function(part0, part1, part2, unsigned) {}; | ||
/** | ||
* @param {string} str | ||
@@ -62,0 +71,0 @@ * @param {(boolean|number)=} unsigned |
46
Long.js
@@ -56,5 +56,6 @@ /* | ||
* @exports Long | ||
* @class A Long class for representing a 64-bit two's-complement integer value. | ||
* @param {number} low The low (signed) 32 bits of the long. | ||
* @param {number} high The high (signed) 32 bits of the long. | ||
* @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). | ||
* @param {boolean=} unsigned Whether unsigned or not. Defaults to `false` (signed). | ||
* @constructor | ||
@@ -111,9 +112,10 @@ */ | ||
Long.fromInt = function(value, unsigned) { | ||
var obj, cachedObj; | ||
if (!unsigned) { | ||
value = value | 0; | ||
if (-128 <= value && value < 128) { | ||
var cachedObj = INT_CACHE[value]; | ||
cachedObj = INT_CACHE[value]; | ||
if (cachedObj) return cachedObj; | ||
} | ||
var obj = new Long(value, value < 0 ? -1 : 0, false); | ||
obj = new Long(value, value < 0 ? -1 : 0, false); | ||
if (-128 <= value && value < 128) { | ||
@@ -126,6 +128,6 @@ INT_CACHE[value] = obj; | ||
if (0 <= value && value < 256) { | ||
var cachedObj = UINT_CACHE[value]; | ||
cachedObj = UINT_CACHE[value]; | ||
if (cachedObj) return cachedObj; | ||
} | ||
var obj = new Long(value, (value | 0) < 0 ? -1 : 0, true); | ||
obj = new Long(value, (value | 0) < 0 ? -1 : 0, true); | ||
if (0 <= value && value < 256) { | ||
@@ -166,6 +168,6 @@ UINT_CACHE[value] = obj; | ||
/** | ||
* Returns a Long representing the 64-bit integer that comes by concatenating | ||
* the given high and low bits. Each is assumed to use 32 bits. | ||
* @param {number} lowBits The low 32-bits. | ||
* @param {number} highBits The high 32-bits. | ||
* Returns a Long representing the 64bit integer that comes by concatenating the given low and high bits. Each is | ||
* assumed to use 32 bits. | ||
* @param {number} lowBits The low 32 bits. | ||
* @param {number} highBits The high 32 bits. | ||
* @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). | ||
@@ -180,2 +182,18 @@ * @return {!Long} The corresponding Long value. | ||
/** | ||
* Returns a Long representing the 64bit integer that comes by concatenating the given low, middle and high bits. | ||
* Each is assumed to use 28 bits. | ||
* @param {number} part0 The low 28 bits | ||
* @param {number} part1 The middle 28 bits | ||
* @param {number} part2 The high 28 (8) bits | ||
* @param {boolean=} unsigned Whether unsigned or not. Defaults to false (signed). | ||
* @return {!Long} | ||
* @expose | ||
*/ | ||
Long.from28Bits = function(part0, part1, part2, unsigned) { | ||
// 00000000000000000000000000001111 11111111111111111111111122222222 2222222222222 | ||
// LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH | ||
return Long.fromBits(part0 | (part1 << 28), (part1 >>> 4) | (part2) << 24, unsigned); | ||
}; | ||
/** | ||
* Returns a Long representation of the given string, written using the given | ||
@@ -193,3 +211,6 @@ * radix. | ||
} | ||
if (typeof unsigned == 'number') { // For goog.math.Long compatibility | ||
if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") { | ||
return Long.ZERO; | ||
} | ||
if (typeof unsigned === 'number') { // For goog.math.Long compatibility | ||
radix = unsigned; | ||
@@ -363,2 +384,3 @@ unsigned = false; | ||
} | ||
var rem; | ||
if (this.isNegative()) { // Unsigned Longs are never negative | ||
@@ -370,3 +392,3 @@ if (this.equals(Long.MIN_SIGNED_VALUE)) { | ||
var div = this.div(radixLong); | ||
var rem = div.multiply(radixLong).subtract(this); | ||
rem = div.multiply(radixLong).subtract(this); | ||
return div.toString(radix) + rem.toInt().toString(radix); | ||
@@ -381,3 +403,3 @@ } else { | ||
var radixToPower = Long.fromNumber(Math.pow(radix, 6)); | ||
var rem = this; | ||
rem = this; | ||
var result = ''; | ||
@@ -384,0 +406,0 @@ while (true) { |
@@ -12,16 +12,16 @@ /* | ||
var p=!1; | ||
(function(r){function b(a,b,d){this.low=a|0;this.high=b|0;this.unsigned=!!d}var s={},t={};b.fromInt=function(a,c){if(c){a>>>=0;if(0<=a&&256>a&&(d=t[a]))return d;d=new b(a,0>(a|0)?-1:0,!0);0<=a&&256>a&&(t[a]=d)}else{a|=0;if(-128<=a&&128>a){var d=s[a];if(d)return d}d=new b(a,0>a?-1:0,p);-128<=a&&128>a&&(s[a]=d)}return d};b.fromNumber=function(a,c){c=!!c;return isNaN(a)||!isFinite(a)?b.ZERO:!c&&a<=-u?b.MIN_SIGNED_VALUE:c&&0>=a?b.MIN_UNSIGNED_VALUE:!c&&a+1>=u?b.MAX_SIGNED_VALUE:c&&a>=v?b.MAX_UNSIGNED_VALUE:0> | ||
a?b.fromNumber(-a,p).negate():new b(a%l|0,a/l|0,c)};b.fromBits=function(a,c,d){return new b(a,c,d)};b.fromString=function(a,c,d){if(0==a.length)throw Error("number format error: empty string");"number"==typeof c&&(d=c,c=p);d=d||10;if(2>d||36<d)throw Error("radix out of range: "+d);if("-"==a.charAt(0))return b.fromString(a.substring(1),c,d).negate();if(0<=a.indexOf("-"))throw Error('number format error: interior "-" character: '+a);c=b.fromNumber(Math.pow(d,8));for(var e=b.ZERO,g=0;g<a.length;g+=8){var f= | ||
Math.min(8,a.length-g),k=parseInt(a.substring(g,g+f),d);8>f?(f=b.fromNumber(Math.pow(d,f)),e=e.multiply(f).add(b.fromNumber(k))):(e=e.multiply(c),e=e.add(b.fromNumber(k)))}return e};var l=4294967296,v=l*l,u=v/2,w=b.fromInt(16777216);b.ZERO=b.fromInt(0);b.ONE=b.fromInt(1);b.NEG_ONE=b.fromInt(-1);b.MAX_SIGNED_VALUE=b.fromBits(-1,2147483647,p);b.MAX_UNSIGNED_VALUE=b.fromBits(-1,-1,!0);b.MAX_VALUE=b.MAX_SIGNED_VALUE;b.MIN_SIGNED_VALUE=b.fromBits(0,-2147483648,p);b.MIN_UNSIGNED_VALUE=b.fromBits(0,0,!0); | ||
b.MIN_VALUE=b.MIN_SIGNED_VALUE;b.prototype.toInt=function(){return this.unsigned?this.low>>>0:this.low};b.prototype.toNumber=function(){return this.unsigned?(this.high>>>0)*l+(this.low>>>0):this.high*l+(this.low>>>0)};b.prototype.toString=function(a){a=a||10;if(2>a||36<a)throw Error("radix out of range: "+a);if(this.isZero())return"0";if(this.isNegative()){if(this.equals(b.MIN_SIGNED_VALUE)){var c=b.fromNumber(a),d=this.div(c),c=d.multiply(c).subtract(this);return d.toString(a)+c.toInt().toString(a)}return"-"+ | ||
this.negate().toString(a)}for(var d=b.fromNumber(Math.pow(a,6)),c=this,e="";;){var g=c.div(d),f=c.subtract(g.multiply(d)).toInt().toString(a),c=g;if(c.isZero())return f+e;for(;6>f.length;)f="0"+f;e=""+f+e}};b.prototype.getHighBits=function(){return this.high};b.prototype.getHighBitsUnsigned=function(){return this.high>>>0};b.prototype.getLowBits=function(){return this.low};b.prototype.getLowBitsUnsigned=function(){return this.low>>>0};b.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.equals(b.MIN_SIGNED_VALUE)? | ||
64:this.negate().getNumBitsAbs();for(var a=0!=this.high?this.high:this.low,c=31;0<c&&0==(a&1<<c);c--);return 0!=this.high?c+33:c+1};b.prototype.isZero=function(){return 0==this.high&&0==this.low};b.prototype.isNegative=function(){return!this.unsigned&&0>this.high};b.prototype.isOdd=function(){return 1==(this.low&1)};b.prototype.equals=function(a){return this.unsigned!=a.unsigned&&this.high>>>31!=a.high>>>31?p:this.high==a.high&&this.low==a.low};b.prototype.notEquals=function(a){return!this.equals(a)}; | ||
b.prototype.lessThan=function(a){return 0>this.compare(a)};b.prototype.lessThanOrEqual=function(a){return 0>=this.compare(a)};b.prototype.greaterThan=function(a){return 0<this.compare(a)};b.prototype.greaterThanOrEqual=function(a){return 0<=this.compare(a)};b.prototype.compare=function(a){if(this.equals(a))return 0;var b=this.isNegative(),d=a.isNegative();return b&&!d?-1:!b&&d?1:this.unsigned?a.high>>>0>this.high>>>0||a.high==this.high&&a.low>>>0>this.low>>>0?-1:1:this.subtract(a).isNegative()?-1: | ||
1};b.prototype.negate=function(){return!this.unsigned&&this.equals(b.MIN_SIGNED_VALUE)?b.MIN_SIGNED_VALUE:this.not().add(b.ONE)};b.prototype.add=function(a){var c=this.high>>>16,d=this.high&65535,e=this.low>>>16,g=a.high>>>16,f=a.high&65535,k=a.low>>>16,q;q=0+((this.low&65535)+(a.low&65535));a=0+(q>>>16);a+=e+k;e=0+(a>>>16);e+=d+f;d=0+(e>>>16);d=d+(c+g)&65535;return b.fromBits((a&65535)<<16|q&65535,d<<16|e&65535,this.unsigned)};b.prototype.subtract=function(a){return this.add(a.negate())};b.prototype.multiply= | ||
function(a){if(this.isZero()||a.isZero())return b.ZERO;if(this.equals(b.MIN_VALUE))return a.isOdd()?b.MIN_VALUE:b.ZERO;if(a.equals(b.MIN_VALUE))return this.isOdd()?b.MIN_VALUE:b.ZERO;if(this.isNegative())return a.isNegative()?this.negate().multiply(a.negate()):this.negate().multiply(a).negate();if(a.isNegative())return this.multiply(a.negate()).negate();if(this.lessThan(w)&&a.lessThan(w))return b.fromNumber(this.toNumber()*a.toNumber(),this.unsigned);var c=this.high>>>16,d=this.high&65535,e=this.low>>> | ||
16,g=this.low&65535,f=a.high>>>16,k=a.high&65535,q=a.low>>>16;a=a.low&65535;var n,h,m,l;l=0+g*a;m=0+(l>>>16);m+=e*a;h=0+(m>>>16);m=(m&65535)+g*q;h+=m>>>16;m&=65535;h+=d*a;n=0+(h>>>16);h=(h&65535)+e*q;n+=h>>>16;h&=65535;h+=g*k;n+=h>>>16;h&=65535;n=n+(c*a+d*q+e*k+g*f)&65535;return b.fromBits(m<<16|l&65535,n<<16|h,this.unsigned)};b.prototype.div=function(a){if(a.isZero())throw Error("division by zero");if(this.isZero())return b.ZERO;if(this.equals(b.MIN_SIGNED_VALUE)){if(a.equals(b.ONE)||a.equals(b.NEG_ONE))return min; | ||
if(a.equals(b.MIN_VALUE))return b.ONE;var c=this.shiftRight(1).div(a).shiftLeft(1);if(c.equals(b.ZERO))return a.isNegative()?b.ONE:b.NEG_ONE;var d=this.subtract(a.multiply(c));return c.add(d.div(a))}if(a.equals(b.MIN_VALUE))return b.ZERO;if(this.isNegative())return a.isNegative()?this.negate().div(a.negate()):this.negate().div(a).negate();if(a.isNegative())return this.div(a.negate()).negate();for(var e=b.ZERO,d=this;d.greaterThanOrEqual(a);){for(var c=Math.max(1,Math.floor(d.toNumber()/a.toNumber())), | ||
g=Math.ceil(Math.log(c)/Math.LN2),g=48>=g?1:Math.pow(2,g-48),f=b.fromNumber(c,this.unsigned),k=f.multiply(a);k.isNegative()||k.greaterThan(d);)c-=g,f=b.fromNumber(c,this.unsigned),k=f.multiply(a);f.isZero()&&(f=b.ONE);e=e.add(f);d=d.subtract(k)}return e};b.prototype.modulo=function(a){return this.subtract(this.div(a).multiply(a))};b.prototype.not=function(){return b.fromBits(~this.low,~this.high,this.unsigned)};b.prototype.and=function(a){return b.fromBits(this.low&a.low,this.high&a.high,this.unsigned)}; | ||
b.prototype.or=function(a){return b.fromBits(this.low|a.low,this.high|a.high,this.unsigned)};b.prototype.xor=function(a){return b.fromBits(this.low^a.low,this.high^a.high,this.unsigned)};b.prototype.shiftLeft=function(a){a&=63;if(0==a)return this;var c=this.low;return 32>a?b.fromBits(c<<a,this.high<<a|c>>>32-a,this.unsigned):b.fromBits(0,c<<a-32,this.unsigned)};b.prototype.shiftRight=function(a){a&=63;if(0==a)return this;var c=this.high;return 32>a?b.fromBits(this.low>>>a|c<<32-a,c>>a,this.unsigned): | ||
b.fromBits(c>>a-32,0<=c?0:-1,this.unsigned)};b.prototype.shiftRightUnsigned=function(a){a&=63;if(0==a)return this;var c=this.high;return 32>a?b.fromBits(this.low>>>a|c<<32-a,c>>>a,this.unsigned):32==a?b.fromBits(c,0,this.unsigned):b.fromBits(c>>>a-32,0,this.unsigned)};b.prototype.toSigned=function(){var a=this.clone();a.unsigned=p;return a};b.prototype.toUnsigned=function(){var a=this.clone();a.unsigned=!0;return a};b.prototype.clone=function(){return new b(this.low,this.high,this.unsigned)};"undefined"!= | ||
typeof module&&module.exports?module.exports=b:"undefined"!=typeof define&&define.amd?define("Math/Long",[],function(){return b}):(r.dcodeIO||(r.dcodeIO={}),r.dcodeIO.Long=b)})(this); | ||
(function(r){function b(a,b,d){this.low=a|0;this.high=b|0;this.unsigned=!!d}var s={},t={};b.fromInt=function(a,c){var d;if(c){a>>>=0;if(0<=a&&256>a&&(d=t[a]))return d;d=new b(a,0>(a|0)?-1:0,!0);0<=a&&256>a&&(t[a]=d)}else{a|=0;if(-128<=a&&128>a&&(d=s[a]))return d;d=new b(a,0>a?-1:0,p);-128<=a&&128>a&&(s[a]=d)}return d};b.fromNumber=function(a,c){c=!!c;return isNaN(a)||!isFinite(a)?b.ZERO:!c&&a<=-u?b.MIN_SIGNED_VALUE:c&&0>=a?b.MIN_UNSIGNED_VALUE:!c&&a+1>=u?b.MAX_SIGNED_VALUE:c&&a>=v?b.MAX_UNSIGNED_VALUE:0> | ||
a?b.fromNumber(-a,p).negate():new b(a%l|0,a/l|0,c)};b.fromBits=function(a,c,d){return new b(a,c,d)};b.from28Bits=function(a,c,d,e){return b.fromBits(a|c<<28,c>>>4|d<<24,e)};b.fromString=function(a,c,d){if(0==a.length)throw Error("number format error: empty string");if("NaN"===a||"Infinity"===a||"+Infinity"===a||"-Infinity"===a)return b.ZERO;"number"===typeof c&&(d=c,c=p);d=d||10;if(2>d||36<d)throw Error("radix out of range: "+d);if("-"==a.charAt(0))return b.fromString(a.substring(1),c,d).negate(); | ||
if(0<=a.indexOf("-"))throw Error('number format error: interior "-" character: '+a);c=b.fromNumber(Math.pow(d,8));for(var e=b.ZERO,g=0;g<a.length;g+=8){var f=Math.min(8,a.length-g),k=parseInt(a.substring(g,g+f),d);8>f?(f=b.fromNumber(Math.pow(d,f)),e=e.multiply(f).add(b.fromNumber(k))):(e=e.multiply(c),e=e.add(b.fromNumber(k)))}return e};var l=4294967296,v=l*l,u=v/2,w=b.fromInt(16777216);b.ZERO=b.fromInt(0);b.ONE=b.fromInt(1);b.NEG_ONE=b.fromInt(-1);b.MAX_SIGNED_VALUE=b.fromBits(-1,2147483647,p); | ||
b.MAX_UNSIGNED_VALUE=b.fromBits(-1,-1,!0);b.MAX_VALUE=b.MAX_SIGNED_VALUE;b.MIN_SIGNED_VALUE=b.fromBits(0,-2147483648,p);b.MIN_UNSIGNED_VALUE=b.fromBits(0,0,!0);b.MIN_VALUE=b.MIN_SIGNED_VALUE;b.prototype.toInt=function(){return this.unsigned?this.low>>>0:this.low};b.prototype.toNumber=function(){return this.unsigned?(this.high>>>0)*l+(this.low>>>0):this.high*l+(this.low>>>0)};b.prototype.toString=function(a){a=a||10;if(2>a||36<a)throw Error("radix out of range: "+a);if(this.isZero())return"0";var c; | ||
if(this.isNegative()){if(this.equals(b.MIN_SIGNED_VALUE)){c=b.fromNumber(a);var d=this.div(c);c=d.multiply(c).subtract(this);return d.toString(a)+c.toInt().toString(a)}return"-"+this.negate().toString(a)}d=b.fromNumber(Math.pow(a,6));c=this;for(var e="";;){var g=c.div(d),f=c.subtract(g.multiply(d)).toInt().toString(a);c=g;if(c.isZero())return f+e;for(;6>f.length;)f="0"+f;e=""+f+e}};b.prototype.getHighBits=function(){return this.high};b.prototype.getHighBitsUnsigned=function(){return this.high>>>0}; | ||
b.prototype.getLowBits=function(){return this.low};b.prototype.getLowBitsUnsigned=function(){return this.low>>>0};b.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.equals(b.MIN_SIGNED_VALUE)?64:this.negate().getNumBitsAbs();for(var a=0!=this.high?this.high:this.low,c=31;0<c&&0==(a&1<<c);c--);return 0!=this.high?c+33:c+1};b.prototype.isZero=function(){return 0==this.high&&0==this.low};b.prototype.isNegative=function(){return!this.unsigned&&0>this.high};b.prototype.isOdd=function(){return 1== | ||
(this.low&1)};b.prototype.equals=function(a){return this.unsigned!=a.unsigned&&this.high>>>31!=a.high>>>31?p:this.high==a.high&&this.low==a.low};b.prototype.notEquals=function(a){return!this.equals(a)};b.prototype.lessThan=function(a){return 0>this.compare(a)};b.prototype.lessThanOrEqual=function(a){return 0>=this.compare(a)};b.prototype.greaterThan=function(a){return 0<this.compare(a)};b.prototype.greaterThanOrEqual=function(a){return 0<=this.compare(a)};b.prototype.compare=function(a){if(this.equals(a))return 0; | ||
var b=this.isNegative(),d=a.isNegative();return b&&!d?-1:!b&&d?1:this.unsigned?a.high>>>0>this.high>>>0||a.high==this.high&&a.low>>>0>this.low>>>0?-1:1:this.subtract(a).isNegative()?-1:1};b.prototype.negate=function(){return!this.unsigned&&this.equals(b.MIN_SIGNED_VALUE)?b.MIN_SIGNED_VALUE:this.not().add(b.ONE)};b.prototype.add=function(a){var c=this.high>>>16,d=this.high&65535,e=this.low>>>16,g=a.high>>>16,f=a.high&65535,k=a.low>>>16,q;q=0+((this.low&65535)+(a.low&65535));a=0+(q>>>16);a+=e+k;e=0+ | ||
(a>>>16);e+=d+f;d=0+(e>>>16);d=d+(c+g)&65535;return b.fromBits((a&65535)<<16|q&65535,d<<16|e&65535,this.unsigned)};b.prototype.subtract=function(a){return this.add(a.negate())};b.prototype.multiply=function(a){if(this.isZero()||a.isZero())return b.ZERO;if(this.equals(b.MIN_VALUE))return a.isOdd()?b.MIN_VALUE:b.ZERO;if(a.equals(b.MIN_VALUE))return this.isOdd()?b.MIN_VALUE:b.ZERO;if(this.isNegative())return a.isNegative()?this.negate().multiply(a.negate()):this.negate().multiply(a).negate();if(a.isNegative())return this.multiply(a.negate()).negate(); | ||
if(this.lessThan(w)&&a.lessThan(w))return b.fromNumber(this.toNumber()*a.toNumber(),this.unsigned);var c=this.high>>>16,d=this.high&65535,e=this.low>>>16,g=this.low&65535,f=a.high>>>16,k=a.high&65535,q=a.low>>>16;a=a.low&65535;var n,h,m,l;l=0+g*a;m=0+(l>>>16);m+=e*a;h=0+(m>>>16);m=(m&65535)+g*q;h+=m>>>16;m&=65535;h+=d*a;n=0+(h>>>16);h=(h&65535)+e*q;n+=h>>>16;h&=65535;h+=g*k;n+=h>>>16;h&=65535;n=n+(c*a+d*q+e*k+g*f)&65535;return b.fromBits(m<<16|l&65535,n<<16|h,this.unsigned)};b.prototype.div=function(a){if(a.isZero())throw Error("division by zero"); | ||
if(this.isZero())return b.ZERO;if(this.equals(b.MIN_SIGNED_VALUE)){if(a.equals(b.ONE)||a.equals(b.NEG_ONE))return min;if(a.equals(b.MIN_VALUE))return b.ONE;var c=this.shiftRight(1).div(a).shiftLeft(1);if(c.equals(b.ZERO))return a.isNegative()?b.ONE:b.NEG_ONE;var d=this.subtract(a.multiply(c));return c.add(d.div(a))}if(a.equals(b.MIN_VALUE))return b.ZERO;if(this.isNegative())return a.isNegative()?this.negate().div(a.negate()):this.negate().div(a).negate();if(a.isNegative())return this.div(a.negate()).negate(); | ||
for(var e=b.ZERO,d=this;d.greaterThanOrEqual(a);){for(var c=Math.max(1,Math.floor(d.toNumber()/a.toNumber())),g=Math.ceil(Math.log(c)/Math.LN2),g=48>=g?1:Math.pow(2,g-48),f=b.fromNumber(c,this.unsigned),k=f.multiply(a);k.isNegative()||k.greaterThan(d);)c-=g,f=b.fromNumber(c,this.unsigned),k=f.multiply(a);f.isZero()&&(f=b.ONE);e=e.add(f);d=d.subtract(k)}return e};b.prototype.modulo=function(a){return this.subtract(this.div(a).multiply(a))};b.prototype.not=function(){return b.fromBits(~this.low,~this.high, | ||
this.unsigned)};b.prototype.and=function(a){return b.fromBits(this.low&a.low,this.high&a.high,this.unsigned)};b.prototype.or=function(a){return b.fromBits(this.low|a.low,this.high|a.high,this.unsigned)};b.prototype.xor=function(a){return b.fromBits(this.low^a.low,this.high^a.high,this.unsigned)};b.prototype.shiftLeft=function(a){a&=63;if(0==a)return this;var c=this.low;return 32>a?b.fromBits(c<<a,this.high<<a|c>>>32-a,this.unsigned):b.fromBits(0,c<<a-32,this.unsigned)};b.prototype.shiftRight=function(a){a&= | ||
63;if(0==a)return this;var c=this.high;return 32>a?b.fromBits(this.low>>>a|c<<32-a,c>>a,this.unsigned):b.fromBits(c>>a-32,0<=c?0:-1,this.unsigned)};b.prototype.shiftRightUnsigned=function(a){a&=63;if(0==a)return this;var c=this.high;return 32>a?b.fromBits(this.low>>>a|c<<32-a,c>>>a,this.unsigned):32==a?b.fromBits(c,0,this.unsigned):b.fromBits(c>>>a-32,0,this.unsigned)};b.prototype.toSigned=function(){var a=this.clone();a.unsigned=p;return a};b.prototype.toUnsigned=function(){var a=this.clone();a.unsigned= | ||
!0;return a};b.prototype.clone=function(){return new b(this.low,this.high,this.unsigned)};"undefined"!=typeof module&&module.exports?module.exports=b:"undefined"!=typeof define&&define.amd?define("Math/Long",[],function(){return b}):(r.dcodeIO||(r.dcodeIO={}),r.dcodeIO.Long=b)})(this); |
{ | ||
"name": "long", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"author": "Daniel Wirtz <dcode@dcode.io>", | ||
"description": "Long.js: A Long class for representing a 64-bit two's-complement integer value derived from the Closure Library extended with unsigned support.", | ||
"description": "A Long class for representing a 64-bit two's-complement integer value.", | ||
"main": "Long.js", | ||
@@ -15,6 +15,6 @@ "repository": { | ||
"devDependencies": { | ||
"nodeunit": ">=0.7", | ||
"closurecompiler": ">=1.1" | ||
"testjs": "latest", | ||
"closurecompiler": "latest" | ||
}, | ||
"license": "Apache License, Version 2.0", | ||
"license": "Apache-2.0", | ||
"engines": { | ||
@@ -26,5 +26,5 @@ "node": ">=0.6" | ||
"compile": "ccjs Long.js --compilation_level=ADVANCED_OPTIMIZATIONS > Long.min.js", | ||
"test": "nodeunit tests/suite.js", | ||
"test": "node node_modules/testjs/bin/testjs tests/suite.js", | ||
"jsdoc": "jsdoc -c jsdoc.json" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
Long.js | ||
![Long.js -A Long class for representing a 64-bit two's-complement integer ](https://raw.github.com/dcodeIO/Long.js/master/long.png) | ||
======= | ||
@@ -9,11 +9,6 @@ A Long class for representing a 64-bit two's-complement integer value derived from the [Closure Library](https://code.google.com/p/closure-library/) | ||
As of the [ECMAScript specification](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), number types have a maximum value | ||
of 2^53. Beyond that, JavaScript falls back to double internally. Furthermore, bitwise operations are always performed | ||
on 32bit numbers. However, in some use cases it is required to be able to perform reliable mathematical and/or bitwise | ||
operations on the full 64bits. This is where Long.js comes into play. | ||
of 2^53. Beyond that, behaviour might be unexpected. Furthermore, bitwise operations can only be performed on 32bit | ||
numbers. However, in some use cases it is required to be able to perform reliable mathematical and/or bitwise operations | ||
on the full 64bits. This is where Long.js comes into play. | ||
Long.js is based on the [goog.math.Long class](http://closure-library.googlecode.com/svn/docs/closure_goog_math_long.js.html) | ||
from the Closure Library. It uses two 32bit integers internally and provides methods for comparison, common tests, math | ||
and bitwise operations on the full 64bits. Additionally, some use cases also require to work with 64bit unsigned values, | ||
so Long.js has been extended with unsigned support while maintaining compatibility to the Closure Library implementation. | ||
Features | ||
@@ -26,26 +21,6 @@ -------- | ||
* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc) | ||
* API-compatible to the Closure Library implementation | ||
* Zero production dependencies | ||
* Small footprint | ||
Long | ||
---- | ||
* Construction from high and low bits as 32bit integers: `new Long(low, high[, unsigned=false])` and | ||
`Long.fromBits(low, high[, unsigned=false])` | ||
* ...from a 32bit integer: `Long.fromInt(value[, unsigned=false])` including a cache for frequently used small numbers | ||
* ...from a number which may internally be a number or double type: `Long.fromNumber(value[, unsigned=false])` | ||
* ...from a string: `Long.fromString(value[, unsigned=false, radix=10])` | ||
* Conversion to a 32bit integer: `Long#toInt()` | ||
* ...to a number: `Long#toNumber()` | ||
* ...to a string: `Long#toString([radix=10])` | ||
* Getters for high and low bits as 32bit integers: `Long#getLowBits()`, `Long#getHighBits()` and | ||
`Long#getLowBitsUnsigned()`, `Long#getHighBitsUnsigned()` | ||
* Comparison: `Long#equals(other)`, `Long#notEquals(other)`, `Long#lessThan(other)`, `Long#lessThanOrEqual(other)`, | ||
`Long#greaterThan(other)`, `Long#greaterThanOrEqual(other)`, `Long#compare(other)` | ||
* Common tests: `Long#isZero()`, `Long#isNegative()`, `Long#isOdd()`, `Long#isEven()` | ||
* Math: `Long#negate()`, `Long#add(other)`, `Long#subtract(other)`, `Long#multiply(other)`, `Long#div(other)`, | ||
`Long#modulo(other)` | ||
* Bitwise operations: `Long#not()`, `Long#and(other)`, `Long#or(other)`, `Long#xor(other)`, `Long#shiftLeft(numBits)`, | ||
`Long#shiftRight(numBits)`, `Long#shiftRightUnsigned(numBits)` | ||
* Conversion between signed and unsinged: `Long.toSigned()`, `Long.toUnsigned()` | ||
Usage | ||
@@ -59,3 +34,3 @@ ----- | ||
```javascript | ||
var Long = require("Long"); | ||
var Long = require("long"); | ||
var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); | ||
@@ -83,3 +58,3 @@ console.log(longVal.toString()); | ||
```html | ||
<script src="//raw.github.com/dcodeIO/Long.js/master/Long.min.js"></script> | ||
<script src="Long.min.js"></script> | ||
``` | ||
@@ -95,3 +70,3 @@ | ||
------------- | ||
* [View documentation](http://htmlpreview.github.com/?http://github.com/dcodeIO/Long.js/master/docs/Long.html) | ||
* [View the API documentation](http://htmlpreview.github.com/?http://github.com/dcodeIO/Long.js/master/docs/Long.html) | ||
@@ -98,0 +73,0 @@ Downloads |
@@ -33,6 +33,20 @@ /* | ||
// So let's focus on my probably not-so-smart unsigned extension: | ||
// So let's focus on my probably not-so-smart extensions: | ||
"from28Bits": function(test) { | ||
var val = Long.from28Bits(0xFFFFFFF, 0xFFFFFFF, 0xFF); | ||
test.equal(val.toString(), "-1"); | ||
test.done(); | ||
}, | ||
"unsigned": { | ||
"min/max": function(test) { | ||
test.equal(Long.MIN_SIGNED_VALUE.toString(), "-9223372036854775808"); | ||
test.equal(Long.MAX_SIGNED_VALUE.toString(), "9223372036854775807"); | ||
test.equal(Long.MIN_UNSIGNED_VALUE.toString(), "0"); | ||
test.equal(Long.MAX_UNSIGNED_VALUE.toString(), "18446744073709551615"); | ||
test.done(); | ||
}, | ||
"construct_negint": function(test) { | ||
@@ -118,2 +132,24 @@ var longVal = Long.fromInt(-1, true); | ||
} | ||
}, | ||
// FIXME: There is no support for NaN or +/-Infinity | ||
// "NaN": function(test) { | ||
// test.ok(isNan(Long.fromNumber(NaN).toNumber()); | ||
// test.strictEqual(Long.fromNumber(+Infinity).toNumber(), +Infinity); | ||
// test.strictEqual(Long.fromNumber(-Infinity).toNumber(), -Infinity); | ||
// test.done(); | ||
// } | ||
// One option could be to store NaN, Infinity etc. in high and set low to 0, while making sure to convert it in a | ||
// proper way as soon as any math is called upon it. This might be as simple as that each of these values always | ||
// "infects" other values, thus remaining untouched respectively changing the base long to its value. | ||
// | ||
// To clarify that, it all becomes zero atm, which usually is good enough but not perfect: | ||
"NaN": function(test) { | ||
test.strictEqual(Long.fromNumber(NaN), Long.ZERO); | ||
test.strictEqual(Long.fromNumber(+Infinity), Long.ZERO); | ||
test.strictEqual(Long.fromNumber(-Infinity), Long.ZERO); | ||
test.strictEqual(Long.fromString(NaN+""), Long.ZERO); | ||
test.strictEqual(Long.fromString(+Infinity+""), Long.ZERO); | ||
test.strictEqual(Long.fromString(-Infinity+""), Long.ZERO); | ||
test.done(); | ||
} | ||
@@ -120,0 +156,0 @@ }; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
169641
22
0
1846
76