Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cuint

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cuint - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

17

build/uint32.js

@@ -8,12 +8,3 @@ /**

var maxLog = Math.log(2147483647)
// Local cache for typical radices
// Math.log(2147483647) / Math.log(radix)
var radixSizeCache = {
36: 5
, 16: 7
, 10: 9
, 2: 30
}
var radixPowerCache = {

@@ -90,3 +81,8 @@ 36: UINT32( Math.pow(36, 5) )

function fromString (s, radix) {
return this.fromNumber( parseInt(s, radix || 10) )
var value = parseInt(s, radix || 10)
this._low = value & 0xFFFF
this._high = value >>> 16
return this
}

@@ -153,2 +149,3 @@ UINT32.prototype.fromString = fromString

UINT32.prototype.subtract = function (other) {
//TODO inline
return this.add( other.clone().negate() )

@@ -155,0 +152,0 @@ }

@@ -1,1 +0,1 @@

!function(t){function h(t,s){return this instanceof h?(this.remainder=null,"undefined"==typeof s?o.call(this,t):"string"==typeof t?r.call(this,t,s):(i.call(this,t,s),void 0)):new h(t,s)}function i(t,h){return this._low=0|t,this._high=0|h,this}function o(t){return this._low=65535&t,this._high=t>>>16,this}function r(t,h){return this.fromNumber(parseInt(t,h||10))}var s=(Math.log(2147483647),{36:h(Math.pow(36,5)),16:h(Math.pow(16,7)),10:h(Math.pow(10,9)),2:h(Math.pow(2,30))},{36:h(36),16:h(16),10:h(10),2:h(2)});h.prototype.fromBits=i,h.prototype.fromNumber=o,h.prototype.fromString=r,h.prototype.toNumber=function(){return this._high<<16|this._low},h.prototype.toString=function(t){t=t||10;var i=s[t]||new h(t);if(!this.gt(i))return this.toNumber().toString(t);for(var o=this.clone(),r=new Array(32),e=31;e>=0&&(o.div(i),r[e]=o.remainder.toNumber().toString(t),o.gt(i));e--);return r[e-1]=o.toNumber().toString(t),r.join("")},h.prototype.add=function(t){var h=this._low+t._low,i=h>>>16;return i+=this._high+t._high,this._low=65535&h,this._high=65535&i,this},h.prototype.subtract=function(t){return this.add(t.clone().negate())},h.prototype.multiply=function(t){var h,i,o=this._high,r=this._low,s=t._high,e=t._low;return i=r*e,h=i>>>16,h+=o*e,h&=65535,h+=r*s,this._low=65535&i,this._high=65535&h,this},h.prototype.div=function(t){if(0==t._low&&0==t._high)throw Error("division by zero");if(0==t._high&&1==t._low)return this;if(t.gt(this))return this._low=0,this._high=0,this;if(this.eq(t))return this._low=1,this._high=0,this;for(var h=t.clone(),i=-1;!this.lt(h);)h.shiftLeft(1,!0),i++;for(this.remainder=this.clone(),this._low=0,this._high=0;i>=0;i--)h.shiftRight(1),this.remainder.lt(h)||(this.remainder.subtract(h),i>16?this._high|=1<<i-16:this._low|=1<<i);return this},h.prototype.negate=h.prototype.not=function(){var t=(65535&~this._low)+1;return this._low=65535&t,this._high=~this._high+(t>>>16)&65535,this},h.prototype.equals=h.prototype.eq=function(t){return this._low==t._low&&this._high==t._high},h.prototype.greaterThan=h.prototype.gt=function(t){return this._high>t._high?!0:this._high<t._high?!1:this._low>t._low},h.prototype.lessThan=h.prototype.lt=function(t){return this._high<t._high?!0:this._high>t._high?!1:this._low<t._low},h.prototype.or=function(t){return this._low|=t._low,this._high|=t._high,this},h.prototype.and=function(t){return this._low&=t._low,this._high&=t._high,this},h.prototype.xor=function(t){return this._low^=t._low,this._high^=t._high,this},h.prototype.shiftRight=h.prototype.shiftr=function(t){return t>16?(this._low=this._high>>>t-16,this._high=0):16==t?(this._low=this._high,this._high=0):(this._low=this._low>>>t|this._high<<16-t&65535,this._high=this._high>>t),this},h.prototype.shiftLeft=h.prototype.shiftl=function(t,h){return t>16?(this._high=this._low<<t-16,this._low=0,h||(this._high&=65535)):16==t?(this._high=this._low,this._low=0):(this._high=this._high<<t|this._low>>>16-t,this._low=this._low<<t&65535,h||(this._high&=65535)),this},h.prototype.rotateLeft=h.prototype.rotl=function(t){var h=this._high<<16|this._low;return h=h<<t|h>>>32-t,this._low=65535&h,this._high=h>>>16,this},h.prototype.rotateRight=h.prototype.rotr=function(t){var h=this._high<<16|this._low;return h=h>>>t|h<<32-t,this._low=65535&h,this._high=h>>>16,this},h.prototype.clone=function(){return new h(this._low,this._high)},"undefined"!=typeof define&&define.amd?define([],function(){return h}):"undefined"!=typeof module&&module.exports?module.exports=h:t.UINT32=h}(this);
!function(t){function h(t,s){return this instanceof h?(this.remainder=null,"undefined"==typeof s?o.call(this,t):"string"==typeof t?r.call(this,t,s):(i.call(this,t,s),void 0)):new h(t,s)}function i(t,h){return this._low=0|t,this._high=0|h,this}function o(t){return this._low=65535&t,this._high=t>>>16,this}function r(t,h){var i=parseInt(t,h||10);return this._low=65535&i,this._high=i>>>16,this}var s=({36:h(Math.pow(36,5)),16:h(Math.pow(16,7)),10:h(Math.pow(10,9)),2:h(Math.pow(2,30))},{36:h(36),16:h(16),10:h(10),2:h(2)});h.prototype.fromBits=i,h.prototype.fromNumber=o,h.prototype.fromString=r,h.prototype.toNumber=function(){return this._high<<16|this._low},h.prototype.toString=function(t){t=t||10;var i=s[t]||new h(t);if(!this.gt(i))return this.toNumber().toString(t);for(var o=this.clone(),r=new Array(32),e=31;e>=0&&(o.div(i),r[e]=o.remainder.toNumber().toString(t),o.gt(i));e--);return r[e-1]=o.toNumber().toString(t),r.join("")},h.prototype.add=function(t){var h=this._low+t._low,i=h>>>16;return i+=this._high+t._high,this._low=65535&h,this._high=65535&i,this},h.prototype.subtract=function(t){return this.add(t.clone().negate())},h.prototype.multiply=function(t){var h,i,o=this._high,r=this._low,s=t._high,e=t._low;return i=r*e,h=i>>>16,h+=o*e,h&=65535,h+=r*s,this._low=65535&i,this._high=65535&h,this},h.prototype.div=function(t){if(0==t._low&&0==t._high)throw Error("division by zero");if(0==t._high&&1==t._low)return this;if(t.gt(this))return this._low=0,this._high=0,this;if(this.eq(t))return this._low=1,this._high=0,this;for(var h=t.clone(),i=-1;!this.lt(h);)h.shiftLeft(1,!0),i++;for(this.remainder=this.clone(),this._low=0,this._high=0;i>=0;i--)h.shiftRight(1),this.remainder.lt(h)||(this.remainder.subtract(h),i>16?this._high|=1<<i-16:this._low|=1<<i);return this},h.prototype.negate=h.prototype.not=function(){var t=(65535&~this._low)+1;return this._low=65535&t,this._high=~this._high+(t>>>16)&65535,this},h.prototype.equals=h.prototype.eq=function(t){return this._low==t._low&&this._high==t._high},h.prototype.greaterThan=h.prototype.gt=function(t){return this._high>t._high?!0:this._high<t._high?!1:this._low>t._low},h.prototype.lessThan=h.prototype.lt=function(t){return this._high<t._high?!0:this._high>t._high?!1:this._low<t._low},h.prototype.or=function(t){return this._low|=t._low,this._high|=t._high,this},h.prototype.and=function(t){return this._low&=t._low,this._high&=t._high,this},h.prototype.xor=function(t){return this._low^=t._low,this._high^=t._high,this},h.prototype.shiftRight=h.prototype.shiftr=function(t){return t>16?(this._low=this._high>>>t-16,this._high=0):16==t?(this._low=this._high,this._high=0):(this._low=this._low>>>t|this._high<<16-t&65535,this._high=this._high>>t),this},h.prototype.shiftLeft=h.prototype.shiftl=function(t,h){return t>16?(this._high=this._low<<t-16,this._low=0,h||(this._high&=65535)):16==t?(this._high=this._low,this._low=0):(this._high=this._high<<t|this._low>>>16-t,this._low=this._low<<t&65535,h||(this._high&=65535)),this},h.prototype.rotateLeft=h.prototype.rotl=function(t){var h=this._high<<16|this._low;return h=h<<t|h>>>32-t,this._low=65535&h,this._high=h>>>16,this},h.prototype.rotateRight=h.prototype.rotr=function(t){var h=this._high<<16|this._low;return h=h>>>t|h<<32-t,this._low=65535&h,this._high=h>>>16,this},h.prototype.clone=function(){return new h(this._low,this._high)},"undefined"!=typeof define&&define.amd?define([],function(){return h}):"undefined"!=typeof module&&module.exports?module.exports=h:t.UINT32=h}(this);

@@ -10,5 +10,5 @@ /**

var radixPowerCache = {
16: UINT64( Math.pow(16, 6) )
, 10: UINT64( Math.pow(10, 6) )
, 2: UINT64( Math.pow(2, 6) )
16: UINT64( Math.pow(16, 5) )
, 10: UINT64( Math.pow(10, 5) )
, 2: UINT64( Math.pow(2, 5) )
}

@@ -117,18 +117,18 @@ var radixCache = {

The radix maximum value is 36 (as per ECMA specs) (26 letters + 10 digits)
maximum input value is m = 32bits as 1
= UINT64( Array(33).join('1'), 2 ).toString(10)
= 4294967295
maximum input value is m = 32bits as 1 = 2^32 - 1
So the maximum substring length n is:
36^n = m
n = ln(m)/ln(36)
n = Math.log( 4294967295 ) / Math.log( 36 ) = 6.189644915687692
n = 6
36^(n+1) - 1 = 2^32 - 1
36^(n+1) = 2^32
(n+1)ln(36) = 32ln(2)
n = 32ln(2)/ln(36) - 1
n = 5.189644915687692
n = 5
*/
var radixUint = radixPowerCache[radix] || new UINT64( Math.pow(radix, 6) )
var radixUint = radixPowerCache[radix] || new UINT64( Math.pow(radix, 5) )
for (var i = 0, len = s.length; i < len; i += 6) {
var size = Math.min(6, len - i)
for (var i = 0, len = s.length; i < len; i += 5) {
var size = Math.min(5, len - i)
var value = parseInt( s.slice(i, i + size), radix )
this.multiply(
size < 6
size < 5
? new UINT64( Math.pow(radix, size) )

@@ -135,0 +135,0 @@ : radixUint

@@ -1,1 +0,1 @@

!function(t){function i(t,_,r,e){return this instanceof i?(this.remainder=null,"string"==typeof t?h.call(this,t,_):"undefined"==typeof _?s.call(this,t):(a.apply(this,arguments),void 0)):new i(t,_,r,e)}function a(t,i,a,s){return"undefined"==typeof a?(this._a00=65535&t,this._a16=t>>>16,this._a32=65535&i,this._a48=i>>>16,this):(this._a00=0|t,this._a16=0|i,this._a32=0|a,this._a48=0|s,this)}function s(t){return this._a00=65535&t,this._a16=t>>>16,this._a32=0,this._a48=0,this}function h(t,a){a=a||10,this._a00=0,this._a16=0,this._a32=0,this._a48=0;for(var s=_[a]||new i(Math.pow(a,6)),h=0,r=t.length;r>h;h+=6){var e=Math.min(6,r-h),o=parseInt(t.slice(h,h+e),a);this.multiply(6>e?new i(Math.pow(a,e)):s).add(new i(o))}return this}var _={16:i(Math.pow(16,6)),10:i(Math.pow(10,6)),2:i(Math.pow(2,6))},r={16:i(16),10:i(10),2:i(2)};i.prototype.fromBits=a,i.prototype.fromNumber=s,i.prototype.fromString=h,i.prototype.toNumber=function(){return this._a16<<16|this._a00},i.prototype.toString=function(t){t=t||10;var a=r[t]||new i(t);if(!this.gt(a))return this.toNumber().toString(t);for(var s=this.clone(),h=new Array(64),_=63;_>=0&&(s.div(a),h[_]=s.remainder.toNumber().toString(t),s.gt(a));_--);return h[_-1]=s.toNumber().toString(t),h.join("")},i.prototype.add=function(t){var i=this._a00+t._a00,a=i>>>16;a+=this._a16+t._a16;var s=a>>>16;s+=this._a32+t._a32;var h=s>>>16;return h+=this._a48+t._a48,this._a00=65535&i,this._a16=65535&a,this._a32=65535&s,this._a48=65535&h,this},i.prototype.subtract=function(t){return this.add(t.clone().negate())},i.prototype.multiply=function(t){var i=this._a00,a=this._a16,s=this._a32,h=this._a48,_=t._a00,r=t._a16,e=t._a32,o=t._a48,n=i*_,p=n>>>16;p+=i*r;var u=p>>>16;p&=65535,p+=a*_,u+=p>>>16,u+=i*e;var f=u>>>16;return u&=65535,u+=a*r,f+=u>>>16,u&=65535,u+=s*_,f+=u>>>16,f+=i*o,f&=65535,f+=a*e,f&=65535,f+=s*r,f&=65535,f+=h*_,this._a00=65535&n,this._a16=65535&p,this._a32=65535&u,this._a48=65535&f,this},i.prototype.div=function(t){if(0==t._a16&&0==t._a32&&0==t._a48){if(0==t._a00)throw Error("division by zero");if(1==t._a00)return this}if(t.gt(this))return this._a00=0,this._a16=0,this._a32=0,this._a48=0,this;if(this.eq(t))return this._a00=1,this._a16=0,this._a32=0,this._a48=0,this;for(var i=t.clone(),a=-1;!this.lt(i);)i.shiftLeft(1,!0),a++;for(this.remainder=this.clone(),this._a00=0,this._a16=0,this._a32=0,this._a48=0;a>=0;a--)i.shiftRight(1),this.remainder.lt(i)||(this.remainder.subtract(i),a>=48?this._a48|=1<<a-48:a>=32?this._a32|=1<<a-32:a>=16?this._a16|=1<<a-16:this._a00|=1<<a);return this},i.prototype.negate=i.prototype.not=function(){var t=(65535&~this._a00)+1;return this._a00=65535&t,t=(65535&~this._a16)+(t>>>16),this._a16=65535&t,t=(65535&~this._a32)+(t>>>16),this._a32=65535&t,this._a48=~this._a48+(t>>>16)&65535,this},i.prototype.equals=i.prototype.eq=function(t){return this._a48==t._a48&&this._a00==t._a00&&this._a32==t._a32&&this._a16==t._a16},i.prototype.greaterThan=i.prototype.gt=function(t){return this._a48>t._a48?!0:this._a48<t._a48?!1:this._a32>t._a32?!0:this._a32<t._a32?!1:this._a16>t._a16?!0:this._a16<t._a16?!1:this._a00>t._a00},i.prototype.lessThan=i.prototype.lt=function(t){return this._a48<t._a48?!0:this._a48>t._a48?!1:this._a32<t._a32?!0:this._a32>t._a32?!1:this._a16<t._a16?!0:this._a16>t._a16?!1:this._a00<t._a00},i.prototype.or=function(t){return this._a00|=t._a00,this._a16|=t._a16,this._a32|=t._a32,this._a48|=t._a48,this},i.prototype.and=function(t){return this._a00&=t._a00,this._a16&=t._a16,this._a32&=t._a32,this._a48&=t._a48,this},i.prototype.xor=function(t){return this._a00^=t._a00,this._a16^=t._a16,this._a32^=t._a32,this._a48^=t._a48,this},i.prototype.shiftRight=i.prototype.shiftr=function(t){return t%=64,t>=48?(this._a00=this._a48>>>t-48,this._a16=0,this._a32=0,this._a48=0):t>=32?(t-=32,this._a00=65535&(this._a32>>>t|this._a48<<16-t),this._a16=this._a48>>t&65535,this._a32=0,this._a48=0):t>=16?(t-=16,this._a00=65535&(this._a16>>>t|this._a32<<16-t),this._a16=65535&(this._a32>>>t|this._a48<<16-t),this._a32=this._a48>>t&65535,this._a48=0):(this._a00=65535&(this._a00>>>t|this._a16<<16-t),this._a16=65535&(this._a16>>>t|this._a32<<16-t),this._a32=65535&(this._a32>>>t|this._a48<<16-t),this._a48=this._a48>>t&65535),this},i.prototype.shiftLeft=i.prototype.shiftl=function(t,i){return t%=64,t>=48?(this._a48=this._a00<<t-48,this._a32=0,this._a16=0,this._a00=0):t>=32?(t-=32,this._a48=this._a16<<t|this._a00>>>16-t,this._a32=this._a00<<t&65535,this._a16=0,this._a00=0):t>=16?(t-=16,this._a48=this._a32<<t|this._a16>>>16-t,this._a32=65535&(this._a16<<t|this._a00>>>16-t),this._a16=this._a00<<t&65535,this._a00=0):(this._a48=this._a48<<t|this._a32>>>16-t,this._a32=65535&(this._a32<<t|this._a16>>>16-t),this._a16=65535&(this._a16<<t|this._a00>>>16-t),this._a00=this._a00<<t&65535),i||(this._a48&=65535),this},i.prototype.rotateLeft=i.prototype.rotl=function(t){if(t%=64,0==t)return this;if(t>=32){var i=this._a00;if(this._a00=this._a32,this._a32=i,i=this._a48,this._a48=this._a16,this._a16=i,32==t)return this;t-=32}var a=this._a48<<16|this._a32,s=this._a16<<16|this._a00,h=a<<t|s>>>32-t,_=s<<t|a>>>32-t;return this._a00=65535&_,this._a16=_>>>16,this._a32=65535&h,this._a48=h>>>16,this},i.prototype.rotateRight=i.prototype.rotr=function(t){if(t%=64,0==t)return this;if(t>=32){var i=this._a00;if(this._a00=this._a32,this._a32=i,i=this._a48,this._a48=this._a16,this._a16=i,32==t)return this;t-=32}var a=this._a48<<16|this._a32,s=this._a16<<16|this._a00,h=a>>>t|s<<32-t,_=s>>>t|a<<32-t;return this._a00=65535&_,this._a16=_>>>16,this._a32=65535&h,this._a48=h>>>16,this},i.prototype.clone=function(){return new i(this._a00,this._a16,this._a32,this._a48)},"undefined"!=typeof define&&define.amd?define([],function(){return i}):"undefined"!=typeof module&&module.exports?module.exports=i:t.UINT64=i}(this);
!function(t){function i(t,_,r,e){return this instanceof i?(this.remainder=null,"string"==typeof t?h.call(this,t,_):"undefined"==typeof _?s.call(this,t):(a.apply(this,arguments),void 0)):new i(t,_,r,e)}function a(t,i,a,s){return"undefined"==typeof a?(this._a00=65535&t,this._a16=t>>>16,this._a32=65535&i,this._a48=i>>>16,this):(this._a00=0|t,this._a16=0|i,this._a32=0|a,this._a48=0|s,this)}function s(t){return this._a00=65535&t,this._a16=t>>>16,this._a32=0,this._a48=0,this}function h(t,a){a=a||10,this._a00=0,this._a16=0,this._a32=0,this._a48=0;for(var s=_[a]||new i(Math.pow(a,5)),h=0,r=t.length;r>h;h+=5){var e=Math.min(5,r-h),o=parseInt(t.slice(h,h+e),a);this.multiply(5>e?new i(Math.pow(a,e)):s).add(new i(o))}return this}var _={16:i(Math.pow(16,5)),10:i(Math.pow(10,5)),2:i(Math.pow(2,5))},r={16:i(16),10:i(10),2:i(2)};i.prototype.fromBits=a,i.prototype.fromNumber=s,i.prototype.fromString=h,i.prototype.toNumber=function(){return this._a16<<16|this._a00},i.prototype.toString=function(t){t=t||10;var a=r[t]||new i(t);if(!this.gt(a))return this.toNumber().toString(t);for(var s=this.clone(),h=new Array(64),_=63;_>=0&&(s.div(a),h[_]=s.remainder.toNumber().toString(t),s.gt(a));_--);return h[_-1]=s.toNumber().toString(t),h.join("")},i.prototype.add=function(t){var i=this._a00+t._a00,a=i>>>16;a+=this._a16+t._a16;var s=a>>>16;s+=this._a32+t._a32;var h=s>>>16;return h+=this._a48+t._a48,this._a00=65535&i,this._a16=65535&a,this._a32=65535&s,this._a48=65535&h,this},i.prototype.subtract=function(t){return this.add(t.clone().negate())},i.prototype.multiply=function(t){var i=this._a00,a=this._a16,s=this._a32,h=this._a48,_=t._a00,r=t._a16,e=t._a32,o=t._a48,n=i*_,p=n>>>16;p+=i*r;var u=p>>>16;p&=65535,p+=a*_,u+=p>>>16,u+=i*e;var f=u>>>16;return u&=65535,u+=a*r,f+=u>>>16,u&=65535,u+=s*_,f+=u>>>16,f+=i*o,f&=65535,f+=a*e,f&=65535,f+=s*r,f&=65535,f+=h*_,this._a00=65535&n,this._a16=65535&p,this._a32=65535&u,this._a48=65535&f,this},i.prototype.div=function(t){if(0==t._a16&&0==t._a32&&0==t._a48){if(0==t._a00)throw Error("division by zero");if(1==t._a00)return this}if(t.gt(this))return this._a00=0,this._a16=0,this._a32=0,this._a48=0,this;if(this.eq(t))return this._a00=1,this._a16=0,this._a32=0,this._a48=0,this;for(var i=t.clone(),a=-1;!this.lt(i);)i.shiftLeft(1,!0),a++;for(this.remainder=this.clone(),this._a00=0,this._a16=0,this._a32=0,this._a48=0;a>=0;a--)i.shiftRight(1),this.remainder.lt(i)||(this.remainder.subtract(i),a>=48?this._a48|=1<<a-48:a>=32?this._a32|=1<<a-32:a>=16?this._a16|=1<<a-16:this._a00|=1<<a);return this},i.prototype.negate=i.prototype.not=function(){var t=(65535&~this._a00)+1;return this._a00=65535&t,t=(65535&~this._a16)+(t>>>16),this._a16=65535&t,t=(65535&~this._a32)+(t>>>16),this._a32=65535&t,this._a48=~this._a48+(t>>>16)&65535,this},i.prototype.equals=i.prototype.eq=function(t){return this._a48==t._a48&&this._a00==t._a00&&this._a32==t._a32&&this._a16==t._a16},i.prototype.greaterThan=i.prototype.gt=function(t){return this._a48>t._a48?!0:this._a48<t._a48?!1:this._a32>t._a32?!0:this._a32<t._a32?!1:this._a16>t._a16?!0:this._a16<t._a16?!1:this._a00>t._a00},i.prototype.lessThan=i.prototype.lt=function(t){return this._a48<t._a48?!0:this._a48>t._a48?!1:this._a32<t._a32?!0:this._a32>t._a32?!1:this._a16<t._a16?!0:this._a16>t._a16?!1:this._a00<t._a00},i.prototype.or=function(t){return this._a00|=t._a00,this._a16|=t._a16,this._a32|=t._a32,this._a48|=t._a48,this},i.prototype.and=function(t){return this._a00&=t._a00,this._a16&=t._a16,this._a32&=t._a32,this._a48&=t._a48,this},i.prototype.xor=function(t){return this._a00^=t._a00,this._a16^=t._a16,this._a32^=t._a32,this._a48^=t._a48,this},i.prototype.shiftRight=i.prototype.shiftr=function(t){return t%=64,t>=48?(this._a00=this._a48>>>t-48,this._a16=0,this._a32=0,this._a48=0):t>=32?(t-=32,this._a00=65535&(this._a32>>>t|this._a48<<16-t),this._a16=this._a48>>t&65535,this._a32=0,this._a48=0):t>=16?(t-=16,this._a00=65535&(this._a16>>>t|this._a32<<16-t),this._a16=65535&(this._a32>>>t|this._a48<<16-t),this._a32=this._a48>>t&65535,this._a48=0):(this._a00=65535&(this._a00>>>t|this._a16<<16-t),this._a16=65535&(this._a16>>>t|this._a32<<16-t),this._a32=65535&(this._a32>>>t|this._a48<<16-t),this._a48=this._a48>>t&65535),this},i.prototype.shiftLeft=i.prototype.shiftl=function(t,i){return t%=64,t>=48?(this._a48=this._a00<<t-48,this._a32=0,this._a16=0,this._a00=0):t>=32?(t-=32,this._a48=this._a16<<t|this._a00>>>16-t,this._a32=this._a00<<t&65535,this._a16=0,this._a00=0):t>=16?(t-=16,this._a48=this._a32<<t|this._a16>>>16-t,this._a32=65535&(this._a16<<t|this._a00>>>16-t),this._a16=this._a00<<t&65535,this._a00=0):(this._a48=this._a48<<t|this._a32>>>16-t,this._a32=65535&(this._a32<<t|this._a16>>>16-t),this._a16=65535&(this._a16<<t|this._a00>>>16-t),this._a00=this._a00<<t&65535),i||(this._a48&=65535),this},i.prototype.rotateLeft=i.prototype.rotl=function(t){if(t%=64,0==t)return this;if(t>=32){var i=this._a00;if(this._a00=this._a32,this._a32=i,i=this._a48,this._a48=this._a16,this._a16=i,32==t)return this;t-=32}var a=this._a48<<16|this._a32,s=this._a16<<16|this._a00,h=a<<t|s>>>32-t,_=s<<t|a>>>32-t;return this._a00=65535&_,this._a16=_>>>16,this._a32=65535&h,this._a48=h>>>16,this},i.prototype.rotateRight=i.prototype.rotr=function(t){if(t%=64,0==t)return this;if(t>=32){var i=this._a00;if(this._a00=this._a32,this._a32=i,i=this._a48,this._a48=this._a16,this._a16=i,32==t)return this;t-=32}var a=this._a48<<16|this._a32,s=this._a16<<16|this._a00,h=a>>>t|s<<32-t,_=s>>>t|a<<32-t;return this._a00=65535&_,this._a16=_>>>16,this._a32=65535&h,this._a48=h>>>16,this},i.prototype.clone=function(){return new i(this._a00,this._a16,this._a32,this._a48)},"undefined"!=typeof define&&define.amd?define([],function(){return i}):"undefined"!=typeof module&&module.exports?module.exports=i:t.UINT64=i}(this);

@@ -0,1 +1,6 @@

0.1.2 / 2014-01-17
==================
* fix for uint64.fromString(36) substring param
0.1.1 / 2014-01-04

@@ -2,0 +7,0 @@ ==================

@@ -8,12 +8,3 @@ /**

var maxLog = Math.log(2147483647)
// Local cache for typical radices
// Math.log(2147483647) / Math.log(radix)
var radixSizeCache = {
36: 5
, 16: 7
, 10: 9
, 2: 30
}
var radixPowerCache = {

@@ -90,3 +81,8 @@ 36: UINT32( Math.pow(36, 5) )

function fromString (s, radix) {
return this.fromNumber( parseInt(s, radix || 10) )
var value = parseInt(s, radix || 10)
this._low = value & 0xFFFF
this._high = value >>> 16
return this
}

@@ -153,2 +149,3 @@ UINT32.prototype.fromString = fromString

UINT32.prototype.subtract = function (other) {
//TODO inline
return this.add( other.clone().negate() )

@@ -155,0 +152,0 @@ }

@@ -10,5 +10,5 @@ /**

var radixPowerCache = {
16: UINT64( Math.pow(16, 6) )
, 10: UINT64( Math.pow(10, 6) )
, 2: UINT64( Math.pow(2, 6) )
16: UINT64( Math.pow(16, 5) )
, 10: UINT64( Math.pow(10, 5) )
, 2: UINT64( Math.pow(2, 5) )
}

@@ -117,18 +117,18 @@ var radixCache = {

The radix maximum value is 36 (as per ECMA specs) (26 letters + 10 digits)
maximum input value is m = 32bits as 1
= UINT64( Array(33).join('1'), 2 ).toString(10)
= 4294967295
maximum input value is m = 32bits as 1 = 2^32 - 1
So the maximum substring length n is:
36^n = m
n = ln(m)/ln(36)
n = Math.log( 4294967295 ) / Math.log( 36 ) = 6.189644915687692
n = 6
36^(n+1) - 1 = 2^32 - 1
36^(n+1) = 2^32
(n+1)ln(36) = 32ln(2)
n = 32ln(2)/ln(36) - 1
n = 5.189644915687692
n = 5
*/
var radixUint = radixPowerCache[radix] || new UINT64( Math.pow(radix, 6) )
var radixUint = radixPowerCache[radix] || new UINT64( Math.pow(radix, 5) )
for (var i = 0, len = s.length; i < len; i += 6) {
var size = Math.min(6, len - i)
for (var i = 0, len = s.length; i < len; i += 5) {
var size = Math.min(5, len - i)
var value = parseInt( s.slice(i, i + size), radix )
this.multiply(
size < 6
size < 5
? new UINT64( Math.pow(radix, size) )

@@ -135,0 +135,0 @@ : radixUint

{
"name": "cuint",
"version": "0.1.1",
"version": "0.1.2",
"description": "Unsigned integers for Javascript",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -198,4 +198,24 @@ var assert = require('assert')

describe('maximum unsigned 32 bits value in base 2', function () {
it('should properly initialize', function (done) {
var u = UINT32( Array(33).join('1'), 2 )
assert.equal( u._low, 65535 )
assert.equal( u._high, 65535 )
done()
})
})
describe('maximum unsigned 32 bits value in base 16', function () {
it('should properly initialize', function (done) {
var u = UINT32( Array(9).join('F'), 16 )
assert.equal( u._low, 65535 )
assert.equal( u._high, 65535 )
done()
})
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc