long
Advanced tools
Comparing version 3.1.0 to 3.2.0
{ | ||
"name": "long", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"author": "Daniel Wirtz <dcode@dcode.io>", | ||
@@ -5,0 +5,0 @@ "description": "A Long class for representing a 64 bit two's-complement integer value.", |
134
dist/long.js
@@ -50,3 +50,2 @@ /* | ||
* @type {number} | ||
* @expose | ||
*/ | ||
@@ -58,3 +57,2 @@ this.low = low | 0; | ||
* @type {number} | ||
* @expose | ||
*/ | ||
@@ -66,3 +64,2 @@ this.high = high | 0; | ||
* @type {boolean} | ||
* @expose | ||
*/ | ||
@@ -93,6 +90,5 @@ this.unsigned = !!unsigned; | ||
* @const | ||
* @expose | ||
* @private | ||
*/ | ||
Long.__isLong__; | ||
Long.prototype.__isLong__; | ||
@@ -120,3 +116,2 @@ Object.defineProperty(Long.prototype, "__isLong__", { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -178,3 +173,2 @@ Long.isLong = isLong; | ||
* @returns {!Long} The corresponding Long value | ||
* @expose | ||
*/ | ||
@@ -214,3 +208,2 @@ Long.fromInt = fromInt; | ||
* @returns {!Long} The corresponding Long value | ||
* @expose | ||
*/ | ||
@@ -238,3 +231,2 @@ Long.fromNumber = fromNumber; | ||
* @returns {!Long} The corresponding Long value | ||
* @expose | ||
*/ | ||
@@ -309,3 +301,2 @@ Long.fromBits = fromBits; | ||
* @returns {!Long} The corresponding Long value | ||
* @expose | ||
*/ | ||
@@ -336,3 +327,2 @@ Long.fromString = fromString; | ||
* @returns {!Long} | ||
* @expose | ||
*/ | ||
@@ -395,3 +385,2 @@ Long.fromValue = fromValue; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -409,3 +398,2 @@ Long.ZERO = ZERO; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -423,3 +411,2 @@ Long.UZERO = UZERO; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -437,3 +424,2 @@ Long.ONE = ONE; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -451,3 +437,2 @@ Long.UONE = UONE; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -465,3 +450,2 @@ Long.NEG_ONE = NEG_ONE; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -479,3 +463,2 @@ Long.MAX_VALUE = MAX_VALUE; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -493,3 +476,2 @@ Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -507,3 +489,2 @@ Long.MIN_VALUE = MIN_VALUE; | ||
* @returns {number} | ||
* @expose | ||
*/ | ||
@@ -517,3 +498,2 @@ LongPrototype.toInt = function toInt() { | ||
* @returns {number} | ||
* @expose | ||
*/ | ||
@@ -532,3 +512,2 @@ LongPrototype.toNumber = function toNumber() { | ||
* @throws {RangeError} If `radix` is out of range | ||
* @expose | ||
*/ | ||
@@ -576,3 +555,2 @@ LongPrototype.toString = function toString(radix) { | ||
* @returns {number} Signed high bits | ||
* @expose | ||
*/ | ||
@@ -586,3 +564,2 @@ LongPrototype.getHighBits = function getHighBits() { | ||
* @returns {number} Unsigned high bits | ||
* @expose | ||
*/ | ||
@@ -596,3 +573,2 @@ LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() { | ||
* @returns {number} Signed low bits | ||
* @expose | ||
*/ | ||
@@ -606,3 +582,2 @@ LongPrototype.getLowBits = function getLowBits() { | ||
* @returns {number} Unsigned low bits | ||
* @expose | ||
*/ | ||
@@ -616,3 +591,2 @@ LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() { | ||
* @returns {number} | ||
* @expose | ||
*/ | ||
@@ -632,3 +606,2 @@ LongPrototype.getNumBitsAbs = function getNumBitsAbs() { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -642,3 +615,2 @@ LongPrototype.isZero = function isZero() { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -652,3 +624,2 @@ LongPrototype.isNegative = function isNegative() { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -662,3 +633,2 @@ LongPrototype.isPositive = function isPositive() { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -672,3 +642,2 @@ LongPrototype.isOdd = function isOdd() { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -683,3 +652,2 @@ LongPrototype.isEven = function isEven() { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -699,3 +667,2 @@ LongPrototype.equals = function equals(other) { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -708,3 +675,2 @@ LongPrototype.eq = LongPrototype.equals; | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -720,3 +686,2 @@ LongPrototype.notEquals = function notEquals(other) { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -729,3 +694,2 @@ LongPrototype.neq = LongPrototype.notEquals; | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -741,3 +705,2 @@ LongPrototype.lessThan = function lessThan(other) { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -750,3 +713,2 @@ LongPrototype.lt = LongPrototype.lessThan; | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -762,3 +724,2 @@ LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -771,3 +732,2 @@ LongPrototype.lte = LongPrototype.lessThanOrEqual; | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -783,3 +743,2 @@ LongPrototype.greaterThan = function greaterThan(other) { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -792,3 +751,2 @@ LongPrototype.gt = LongPrototype.greaterThan; | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -804,3 +762,2 @@ LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -814,3 +771,2 @@ LongPrototype.gte = LongPrototype.greaterThanOrEqual; | ||
* if the given one is greater | ||
* @expose | ||
*/ | ||
@@ -841,3 +797,2 @@ LongPrototype.compare = function compare(other) { | ||
* if the given one is greater | ||
* @expose | ||
*/ | ||
@@ -849,3 +804,2 @@ LongPrototype.comp = LongPrototype.compare; | ||
* @returns {!Long} Negated Long | ||
* @expose | ||
*/ | ||
@@ -862,3 +816,2 @@ LongPrototype.negate = function negate() { | ||
* @returns {!Long} Negated Long | ||
* @expose | ||
*/ | ||
@@ -871,3 +824,2 @@ LongPrototype.neg = LongPrototype.negate; | ||
* @returns {!Long} Sum | ||
* @expose | ||
*/ | ||
@@ -909,3 +861,2 @@ LongPrototype.add = function add(addend) { | ||
* @returns {!Long} Difference | ||
* @expose | ||
*/ | ||
@@ -923,3 +874,2 @@ LongPrototype.subtract = function subtract(subtrahend) { | ||
* @returns {!Long} Difference | ||
* @expose | ||
*/ | ||
@@ -932,3 +882,2 @@ LongPrototype.sub = LongPrototype.subtract; | ||
* @returns {!Long} Product | ||
* @expose | ||
*/ | ||
@@ -1001,3 +950,2 @@ LongPrototype.multiply = function multiply(multiplier) { | ||
* @returns {!Long} Product | ||
* @expose | ||
*/ | ||
@@ -1011,3 +959,2 @@ LongPrototype.mul = LongPrototype.multiply; | ||
* @returns {!Long} Quotient | ||
* @expose | ||
*/ | ||
@@ -1023,2 +970,4 @@ LongPrototype.divide = function divide(divisor) { | ||
if (!this.unsigned) { | ||
// This section is only relevant for signed longs and is derived from the | ||
// closure library as a whole. | ||
if (this.eq(MIN_VALUE)) { | ||
@@ -1049,8 +998,8 @@ if (divisor.eq(ONE) || divisor.eq(NEG_ONE)) | ||
return this.div(divisor.neg()).neg(); | ||
} else if (!divisor.unsigned) | ||
divisor = divisor.toUnsigned(); | ||
// The algorithm below has not been made for unsigned longs. It's therefore | ||
// required to take special care of the MSB prior to running it. | ||
if (this.unsigned) { | ||
res = ZERO; | ||
} else { | ||
// The algorithm below has not been made for unsigned longs. It's therefore | ||
// required to take special care of the MSB prior to running it. | ||
if (!divisor.unsigned) | ||
divisor = divisor.toUnsigned(); | ||
if (divisor.gt(this)) | ||
@@ -1061,4 +1010,3 @@ return UZERO; | ||
res = UZERO; | ||
} else | ||
res = ZERO; | ||
} | ||
@@ -1107,3 +1055,2 @@ // Repeat the following until the remainder is less than other: find a | ||
* @returns {!Long} Quotient | ||
* @expose | ||
*/ | ||
@@ -1116,3 +1063,2 @@ LongPrototype.div = LongPrototype.divide; | ||
* @returns {!Long} Remainder | ||
* @expose | ||
*/ | ||
@@ -1130,3 +1076,2 @@ LongPrototype.modulo = function modulo(divisor) { | ||
* @returns {!Long} Remainder | ||
* @expose | ||
*/ | ||
@@ -1138,3 +1083,2 @@ LongPrototype.mod = LongPrototype.modulo; | ||
* @returns {!Long} | ||
* @expose | ||
*/ | ||
@@ -1149,3 +1093,2 @@ LongPrototype.not = function not() { | ||
* @returns {!Long} | ||
* @expose | ||
*/ | ||
@@ -1162,3 +1105,2 @@ LongPrototype.and = function and(other) { | ||
* @returns {!Long} | ||
* @expose | ||
*/ | ||
@@ -1175,3 +1117,2 @@ LongPrototype.or = function or(other) { | ||
* @returns {!Long} | ||
* @expose | ||
*/ | ||
@@ -1188,3 +1129,2 @@ LongPrototype.xor = function xor(other) { | ||
* @returns {!Long} Shifted Long | ||
* @expose | ||
*/ | ||
@@ -1207,3 +1147,2 @@ LongPrototype.shiftLeft = function shiftLeft(numBits) { | ||
* @returns {!Long} Shifted Long | ||
* @expose | ||
*/ | ||
@@ -1216,3 +1155,2 @@ LongPrototype.shl = LongPrototype.shiftLeft; | ||
* @returns {!Long} Shifted Long | ||
* @expose | ||
*/ | ||
@@ -1235,3 +1173,2 @@ LongPrototype.shiftRight = function shiftRight(numBits) { | ||
* @returns {!Long} Shifted Long | ||
* @expose | ||
*/ | ||
@@ -1244,3 +1181,2 @@ LongPrototype.shr = LongPrototype.shiftRight; | ||
* @returns {!Long} Shifted Long | ||
* @expose | ||
*/ | ||
@@ -1270,3 +1206,2 @@ LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) { | ||
* @returns {!Long} Shifted Long | ||
* @expose | ||
*/ | ||
@@ -1278,3 +1213,2 @@ LongPrototype.shru = LongPrototype.shiftRightUnsigned; | ||
* @returns {!Long} Signed long | ||
* @expose | ||
*/ | ||
@@ -1290,3 +1224,2 @@ LongPrototype.toSigned = function toSigned() { | ||
* @returns {!Long} Unsigned long | ||
* @expose | ||
*/ | ||
@@ -1299,3 +1232,50 @@ LongPrototype.toUnsigned = function toUnsigned() { | ||
/** | ||
* Converts this Long to its byte representation. | ||
* @param {boolean=} le Whether little or big endian, defaults to big endian | ||
* @returns {!Array.<number>} Byte representation | ||
*/ | ||
LongPrototype.toBytes = function(le) { | ||
return le ? this.toBytesLE() : this.toBytesBE(); | ||
} | ||
/** | ||
* Converts this Long to its little endian byte representation. | ||
* @returns {!Array.<number>} Little endian byte representation | ||
*/ | ||
LongPrototype.toBytesLE = function() { | ||
var hi = this.high, | ||
lo = this.low; | ||
return [ | ||
lo & 0xff, | ||
(lo >>> 8) & 0xff, | ||
(lo >>> 16) & 0xff, | ||
(lo >>> 24) & 0xff, | ||
hi & 0xff, | ||
(hi >>> 8) & 0xff, | ||
(hi >>> 16) & 0xff, | ||
(hi >>> 24) & 0xff | ||
]; | ||
} | ||
/** | ||
* Converts this Long to its big endian byte representation. | ||
* @returns {!Array.<number>} Big endian byte representation | ||
*/ | ||
LongPrototype.toBytesBE = function() { | ||
var hi = this.high, | ||
lo = this.low; | ||
return [ | ||
(hi >>> 24) & 0xff, | ||
(hi >>> 16) & 0xff, | ||
(hi >>> 8) & 0xff, | ||
hi & 0xff, | ||
(lo >>> 24) & 0xff, | ||
(lo >>> 16) & 0xff, | ||
(lo >>> 8) & 0xff, | ||
lo & 0xff | ||
]; | ||
} | ||
return Long; | ||
}); |
@@ -16,6 +16,6 @@ /* | ||
this.neg().mul(a.neg()):this.neg().mul(a).neg();if(a.isNegative())return this.mul(a.neg()).neg();if(this.lt(F)&&a.lt(F))return n(this.toNumber()*a.toNumber(),this.unsigned);var b=this.high>>>16,c=this.high&65535,d=this.low>>>16,w=this.low&65535,f=a.high>>>16,m=a.high&65535,p=a.low>>>16;a=a.low&65535;var u,h,s,r;r=0+w*a;s=0+(r>>>16);s+=d*a;h=0+(s>>>16);s=(s&65535)+w*p;h+=s>>>16;s&=65535;h+=c*a;u=0+(h>>>16);h=(h&65535)+d*p;u+=h>>>16;h&=65535;h+=w*m;u+=h>>>16;h&=65535;u=u+(b*a+c*p+d*m+w*f)&65535;return e(s<< | ||
16|r&65535,u<<16|h,this.unsigned)};b.mul=b.multiply;b.divide=function(a){g(a)||(a=q(a));if(a.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?p:k;var b,c,d;if(this.unsigned)a.unsigned||(a=a.toUnsigned());else{if(this.eq(l)){if(a.eq(r)||a.eq(y))return l;if(a.eq(l))return r;b=this.shr(1).div(a).shl(1);if(b.eq(k))return a.isNegative()?r:y;c=this.sub(a.mul(b));return d=b.add(c.div(a))}if(a.eq(l))return this.unsigned?p:k;if(this.isNegative())return a.isNegative()?this.neg().div(a.neg()): | ||
this.neg().div(a).neg();if(a.isNegative())return this.div(a.neg()).neg()}if(this.unsigned){if(a.gt(this))return p;if(a.gt(this.shru(1)))return G;d=p}else d=k;for(c=this;c.gte(a);){b=Math.max(1,Math.floor(c.toNumber()/a.toNumber()));for(var e=Math.ceil(Math.log(b)/Math.LN2),e=48>=e?1:v(2,e-48),f=n(b),m=f.mul(a);m.isNegative()||m.gt(c);)b-=e,f=n(b,this.unsigned),m=f.mul(a);f.isZero()&&(f=r);d=d.add(f);c=c.sub(m)}return d};b.div=b.divide;b.modulo=function(a){g(a)||(a=q(a));return this.sub(this.div(a).mul(a))}; | ||
16|r&65535,u<<16|h,this.unsigned)};b.mul=b.multiply;b.divide=function(a){g(a)||(a=q(a));if(a.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?p:k;var b,c,d;if(this.unsigned){a.unsigned||(a=a.toUnsigned());if(a.gt(this))return p;if(a.gt(this.shru(1)))return G;d=p}else{if(this.eq(l)){if(a.eq(r)||a.eq(y))return l;if(a.eq(l))return r;b=this.shr(1).div(a).shl(1);if(b.eq(k))return a.isNegative()?r:y;c=this.sub(a.mul(b));return d=b.add(c.div(a))}if(a.eq(l))return this.unsigned? | ||
p:k;if(this.isNegative())return a.isNegative()?this.neg().div(a.neg()):this.neg().div(a).neg();if(a.isNegative())return this.div(a.neg()).neg();d=k}for(c=this;c.gte(a);){b=Math.max(1,Math.floor(c.toNumber()/a.toNumber()));for(var e=Math.ceil(Math.log(b)/Math.LN2),e=48>=e?1:v(2,e-48),f=n(b),m=f.mul(a);m.isNegative()||m.gt(c);)b-=e,f=n(b,this.unsigned),m=f.mul(a);f.isZero()&&(f=r);d=d.add(f);c=c.sub(m)}return d};b.div=b.divide;b.modulo=function(a){g(a)||(a=q(a));return this.sub(this.div(a).mul(a))}; | ||
b.mod=b.modulo;b.not=function(){return e(~this.low,~this.high,this.unsigned)};b.and=function(a){g(a)||(a=q(a));return e(this.low&a.low,this.high&a.high,this.unsigned)};b.or=function(a){g(a)||(a=q(a));return e(this.low|a.low,this.high|a.high,this.unsigned)};b.xor=function(a){g(a)||(a=q(a));return e(this.low^a.low,this.high^a.high,this.unsigned)};b.shiftLeft=function(a){g(a)&&(a=a.toInt());return 0===(a&=63)?this:32>a?e(this.low<<a,this.high<<a|this.low>>>32-a,this.unsigned):e(0,this.low<<a-32,this.unsigned)}; | ||
b.shl=b.shiftLeft;b.shiftRight=function(a){g(a)&&(a=a.toInt());return 0===(a&=63)?this:32>a?e(this.low>>>a|this.high<<32-a,this.high>>a,this.unsigned):e(this.high>>a-32,0<=this.high?0:-1,this.unsigned)};b.shr=b.shiftRight;b.shiftRightUnsigned=function(a){g(a)&&(a=a.toInt());a&=63;if(0===a)return this;var b=this.high;return 32>a?e(this.low>>>a|b<<32-a,b>>>a,this.unsigned):32===a?e(b,0,this.unsigned):e(b>>>a-32,0,this.unsigned)};b.shru=b.shiftRightUnsigned;b.toSigned=function(){return this.unsigned? | ||
e(this.low,this.high,!1):this};b.toUnsigned=function(){return this.unsigned?this:e(this.low,this.high,!0)};return d}); | ||
e(this.low,this.high,!1):this};b.toUnsigned=function(){return this.unsigned?this:e(this.low,this.high,!0)};b.toBytes=function(a){return a?this.toBytesLE():this.toBytesBE()};b.toBytesLE=function(){var a=this.high,b=this.low;return[b&255,b>>>8&255,b>>>16&255,b>>>24&255,a&255,a>>>8&255,a>>>16&255,a>>>24&255]};b.toBytesBE=function(){var a=this.high,b=this.low;return[a>>>24&255,a>>>16&255,a>>>8&255,a&255,b>>>24&255,b>>>16&255,b>>>8&255,b&255]};return d}); |
{ | ||
"name": "long", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"author": "Daniel Wirtz <dcode@dcode.io>", | ||
@@ -19,3 +19,3 @@ "description": "A Long class for representing a 64-bit two's-complement integer value.", | ||
"testjs": "latest", | ||
"closurecompiler": "latest", | ||
"closurecompiler": "^1.6", | ||
"metascript": "~0" | ||
@@ -22,0 +22,0 @@ }, |
132
src/long.js
@@ -16,3 +16,2 @@ /** | ||
* @type {number} | ||
* @expose | ||
*/ | ||
@@ -24,3 +23,2 @@ this.low = low | 0; | ||
* @type {number} | ||
* @expose | ||
*/ | ||
@@ -32,3 +30,2 @@ this.high = high | 0; | ||
* @type {boolean} | ||
* @expose | ||
*/ | ||
@@ -59,3 +56,2 @@ this.unsigned = !!unsigned; | ||
* @const | ||
* @expose | ||
* @private | ||
@@ -86,3 +82,2 @@ */ | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -144,3 +139,2 @@ Long.isLong = isLong; | ||
* @returns {!Long} The corresponding Long value | ||
* @expose | ||
*/ | ||
@@ -180,3 +174,2 @@ Long.fromInt = fromInt; | ||
* @returns {!Long} The corresponding Long value | ||
* @expose | ||
*/ | ||
@@ -204,3 +197,2 @@ Long.fromNumber = fromNumber; | ||
* @returns {!Long} The corresponding Long value | ||
* @expose | ||
*/ | ||
@@ -275,3 +267,2 @@ Long.fromBits = fromBits; | ||
* @returns {!Long} The corresponding Long value | ||
* @expose | ||
*/ | ||
@@ -302,3 +293,2 @@ Long.fromString = fromString; | ||
* @returns {!Long} | ||
* @expose | ||
*/ | ||
@@ -361,3 +351,2 @@ Long.fromValue = fromValue; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -375,3 +364,2 @@ Long.ZERO = ZERO; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -389,3 +377,2 @@ Long.UZERO = UZERO; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -403,3 +390,2 @@ Long.ONE = ONE; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -417,3 +403,2 @@ Long.UONE = UONE; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -431,3 +416,2 @@ Long.NEG_ONE = NEG_ONE; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -445,3 +429,2 @@ Long.MAX_VALUE = MAX_VALUE; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -459,3 +442,2 @@ Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE; | ||
* @type {!Long} | ||
* @expose | ||
*/ | ||
@@ -473,3 +455,2 @@ Long.MIN_VALUE = MIN_VALUE; | ||
* @returns {number} | ||
* @expose | ||
*/ | ||
@@ -483,3 +464,2 @@ LongPrototype.toInt = function toInt() { | ||
* @returns {number} | ||
* @expose | ||
*/ | ||
@@ -498,3 +478,2 @@ LongPrototype.toNumber = function toNumber() { | ||
* @throws {RangeError} If `radix` is out of range | ||
* @expose | ||
*/ | ||
@@ -542,3 +521,2 @@ LongPrototype.toString = function toString(radix) { | ||
* @returns {number} Signed high bits | ||
* @expose | ||
*/ | ||
@@ -552,3 +530,2 @@ LongPrototype.getHighBits = function getHighBits() { | ||
* @returns {number} Unsigned high bits | ||
* @expose | ||
*/ | ||
@@ -562,3 +539,2 @@ LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() { | ||
* @returns {number} Signed low bits | ||
* @expose | ||
*/ | ||
@@ -572,3 +548,2 @@ LongPrototype.getLowBits = function getLowBits() { | ||
* @returns {number} Unsigned low bits | ||
* @expose | ||
*/ | ||
@@ -582,3 +557,2 @@ LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() { | ||
* @returns {number} | ||
* @expose | ||
*/ | ||
@@ -598,3 +572,2 @@ LongPrototype.getNumBitsAbs = function getNumBitsAbs() { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -608,3 +581,2 @@ LongPrototype.isZero = function isZero() { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -618,3 +590,2 @@ LongPrototype.isNegative = function isNegative() { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -628,3 +599,2 @@ LongPrototype.isPositive = function isPositive() { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -638,3 +608,2 @@ LongPrototype.isOdd = function isOdd() { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -649,3 +618,2 @@ LongPrototype.isEven = function isEven() { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -665,3 +633,2 @@ LongPrototype.equals = function equals(other) { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -674,3 +641,2 @@ LongPrototype.eq = LongPrototype.equals; | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -686,3 +652,2 @@ LongPrototype.notEquals = function notEquals(other) { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -695,3 +660,2 @@ LongPrototype.neq = LongPrototype.notEquals; | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -707,3 +671,2 @@ LongPrototype.lessThan = function lessThan(other) { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -716,3 +679,2 @@ LongPrototype.lt = LongPrototype.lessThan; | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -728,3 +690,2 @@ LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -737,3 +698,2 @@ LongPrototype.lte = LongPrototype.lessThanOrEqual; | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -749,3 +709,2 @@ LongPrototype.greaterThan = function greaterThan(other) { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -758,3 +717,2 @@ LongPrototype.gt = LongPrototype.greaterThan; | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -770,3 +728,2 @@ LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) { | ||
* @returns {boolean} | ||
* @expose | ||
*/ | ||
@@ -780,3 +737,2 @@ LongPrototype.gte = LongPrototype.greaterThanOrEqual; | ||
* if the given one is greater | ||
* @expose | ||
*/ | ||
@@ -807,3 +763,2 @@ LongPrototype.compare = function compare(other) { | ||
* if the given one is greater | ||
* @expose | ||
*/ | ||
@@ -815,3 +770,2 @@ LongPrototype.comp = LongPrototype.compare; | ||
* @returns {!Long} Negated Long | ||
* @expose | ||
*/ | ||
@@ -828,3 +782,2 @@ LongPrototype.negate = function negate() { | ||
* @returns {!Long} Negated Long | ||
* @expose | ||
*/ | ||
@@ -837,3 +790,2 @@ LongPrototype.neg = LongPrototype.negate; | ||
* @returns {!Long} Sum | ||
* @expose | ||
*/ | ||
@@ -875,3 +827,2 @@ LongPrototype.add = function add(addend) { | ||
* @returns {!Long} Difference | ||
* @expose | ||
*/ | ||
@@ -889,3 +840,2 @@ LongPrototype.subtract = function subtract(subtrahend) { | ||
* @returns {!Long} Difference | ||
* @expose | ||
*/ | ||
@@ -898,3 +848,2 @@ LongPrototype.sub = LongPrototype.subtract; | ||
* @returns {!Long} Product | ||
* @expose | ||
*/ | ||
@@ -967,3 +916,2 @@ LongPrototype.multiply = function multiply(multiplier) { | ||
* @returns {!Long} Product | ||
* @expose | ||
*/ | ||
@@ -977,3 +925,2 @@ LongPrototype.mul = LongPrototype.multiply; | ||
* @returns {!Long} Quotient | ||
* @expose | ||
*/ | ||
@@ -989,2 +936,4 @@ LongPrototype.divide = function divide(divisor) { | ||
if (!this.unsigned) { | ||
// This section is only relevant for signed longs and is derived from the | ||
// closure library as a whole. | ||
if (this.eq(MIN_VALUE)) { | ||
@@ -1015,8 +964,8 @@ if (divisor.eq(ONE) || divisor.eq(NEG_ONE)) | ||
return this.div(divisor.neg()).neg(); | ||
} else if (!divisor.unsigned) | ||
divisor = divisor.toUnsigned(); | ||
// The algorithm below has not been made for unsigned longs. It's therefore | ||
// required to take special care of the MSB prior to running it. | ||
if (this.unsigned) { | ||
res = ZERO; | ||
} else { | ||
// The algorithm below has not been made for unsigned longs. It's therefore | ||
// required to take special care of the MSB prior to running it. | ||
if (!divisor.unsigned) | ||
divisor = divisor.toUnsigned(); | ||
if (divisor.gt(this)) | ||
@@ -1027,4 +976,3 @@ return UZERO; | ||
res = UZERO; | ||
} else | ||
res = ZERO; | ||
} | ||
@@ -1073,3 +1021,2 @@ // Repeat the following until the remainder is less than other: find a | ||
* @returns {!Long} Quotient | ||
* @expose | ||
*/ | ||
@@ -1082,3 +1029,2 @@ LongPrototype.div = LongPrototype.divide; | ||
* @returns {!Long} Remainder | ||
* @expose | ||
*/ | ||
@@ -1096,3 +1042,2 @@ LongPrototype.modulo = function modulo(divisor) { | ||
* @returns {!Long} Remainder | ||
* @expose | ||
*/ | ||
@@ -1104,3 +1049,2 @@ LongPrototype.mod = LongPrototype.modulo; | ||
* @returns {!Long} | ||
* @expose | ||
*/ | ||
@@ -1115,3 +1059,2 @@ LongPrototype.not = function not() { | ||
* @returns {!Long} | ||
* @expose | ||
*/ | ||
@@ -1128,3 +1071,2 @@ LongPrototype.and = function and(other) { | ||
* @returns {!Long} | ||
* @expose | ||
*/ | ||
@@ -1141,3 +1083,2 @@ LongPrototype.or = function or(other) { | ||
* @returns {!Long} | ||
* @expose | ||
*/ | ||
@@ -1154,3 +1095,2 @@ LongPrototype.xor = function xor(other) { | ||
* @returns {!Long} Shifted Long | ||
* @expose | ||
*/ | ||
@@ -1173,3 +1113,2 @@ LongPrototype.shiftLeft = function shiftLeft(numBits) { | ||
* @returns {!Long} Shifted Long | ||
* @expose | ||
*/ | ||
@@ -1182,3 +1121,2 @@ LongPrototype.shl = LongPrototype.shiftLeft; | ||
* @returns {!Long} Shifted Long | ||
* @expose | ||
*/ | ||
@@ -1201,3 +1139,2 @@ LongPrototype.shiftRight = function shiftRight(numBits) { | ||
* @returns {!Long} Shifted Long | ||
* @expose | ||
*/ | ||
@@ -1210,3 +1147,2 @@ LongPrototype.shr = LongPrototype.shiftRight; | ||
* @returns {!Long} Shifted Long | ||
* @expose | ||
*/ | ||
@@ -1236,3 +1172,2 @@ LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) { | ||
* @returns {!Long} Shifted Long | ||
* @expose | ||
*/ | ||
@@ -1244,3 +1179,2 @@ LongPrototype.shru = LongPrototype.shiftRightUnsigned; | ||
* @returns {!Long} Signed long | ||
* @expose | ||
*/ | ||
@@ -1256,3 +1190,2 @@ LongPrototype.toSigned = function toSigned() { | ||
* @returns {!Long} Unsigned long | ||
* @expose | ||
*/ | ||
@@ -1264,1 +1197,48 @@ LongPrototype.toUnsigned = function toUnsigned() { | ||
}; | ||
/** | ||
* Converts this Long to its byte representation. | ||
* @param {boolean=} le Whether little or big endian, defaults to big endian | ||
* @returns {!Array.<number>} Byte representation | ||
*/ | ||
LongPrototype.toBytes = function(le) { | ||
return le ? this.toBytesLE() : this.toBytesBE(); | ||
} | ||
/** | ||
* Converts this Long to its little endian byte representation. | ||
* @returns {!Array.<number>} Little endian byte representation | ||
*/ | ||
LongPrototype.toBytesLE = function() { | ||
var hi = this.high, | ||
lo = this.low; | ||
return [ | ||
lo & 0xff, | ||
(lo >>> 8) & 0xff, | ||
(lo >>> 16) & 0xff, | ||
(lo >>> 24) & 0xff, | ||
hi & 0xff, | ||
(hi >>> 8) & 0xff, | ||
(hi >>> 16) & 0xff, | ||
(hi >>> 24) & 0xff | ||
]; | ||
} | ||
/** | ||
* Converts this Long to its big endian byte representation. | ||
* @returns {!Array.<number>} Big endian byte representation | ||
*/ | ||
LongPrototype.toBytesBE = function() { | ||
var hi = this.high, | ||
lo = this.low; | ||
return [ | ||
(hi >>> 24) & 0xff, | ||
(hi >>> 16) & 0xff, | ||
(hi >>> 8) & 0xff, | ||
hi & 0xff, | ||
(lo >>> 24) & 0xff, | ||
(lo >>> 16) & 0xff, | ||
(lo >>> 8) & 0xff, | ||
lo & 0xff | ||
]; | ||
} |
@@ -54,2 +54,15 @@ /* | ||
}, | ||
"toBytes": function(test) { | ||
var longVal = Long.fromBits(0x01234567, 0x12345678); | ||
test.deepEqual(longVal.toBytesBE(), [ | ||
0x12, 0x34, 0x56, 0x78, | ||
0x01, 0x23, 0x45, 0x67 | ||
]); | ||
test.deepEqual(longVal.toBytesLE(), [ | ||
0x67, 0x45, 0x23, 0x01, | ||
0x78, 0x56, 0x34, 0x12 | ||
]); | ||
test.done(); | ||
}, | ||
@@ -56,0 +69,0 @@ "unsigned": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
196662
3444