/**
 * @see https://github.com/rochars/twos-complement-buffer.
 */
var d="function"==typeof Object.create?Object.create:function(a){function b(){}b.prototype=a;return new b},e;if("function"==typeof Object.setPrototypeOf)e=Object.setPrototypeOf;else{var g;a:{var h={b:!0},k={};try{k.__proto__=h;g=k.b;break a}catch(a){}g=!1}e=g?function(a,b){a.__proto__=b;if(a.__proto__!==b)throw new TypeError(a+" is not extensible");return a}:null}var l=e,exports=n||{};
function p(a){this.bits=a;this.bytes=8>a?1:Math.ceil(a/8);this.max=Math.pow(2,a)-1;this.min=0;a=8-((a-1|7)+1-a);this.c=Math.pow(2,0<a?a:8)-1}p.prototype.pack=function(a,b,c){c=void 0===c?0:c;if(b!==b)throw Error("NaN");q(this,b);a[c]=(0>b?b+Math.pow(2,this.bits):b)&255;c++;for(var f=this.bytes,m=2;m<f;m++)a[c]=Math.floor(b/Math.pow(2,8*(m-1)))&255,c++;8<this.bits&&(a[c]=Math.floor(b/Math.pow(2,8*(this.bytes-1)))&this.c,c++);return c};
p.prototype.unpack=function(a,b){a=this.a(a,void 0===b?0:b);q(this,a);return a};p.prototype.a=function(a,b){for(var c=0,f=0;f<this.bytes;f++)c+=a[b+f]*Math.pow(256,f);return c};function q(a,b){if(b>a.max||b<a.min)throw Error("Overflow");}function n(a){p.call(this,a);this.max=Math.pow(2,this.bits)/2-1;this.min=-this.max-1}n.prototype=d(p.prototype);n.prototype.constructor=n;
if(l)l(n,p);else for(var r in p)if("prototype"!=r)if(Object.defineProperties){var t=Object.getOwnPropertyDescriptor(p,r);t&&Object.defineProperty(n,r,t)}else n[r]=p[r];n.a=p.prototype;n.prototype.pack=function(a,b,c){return p.prototype.pack.call(this,a,b,void 0===c?0:c)};n.prototype.unpack=function(a,b){a=p.prototype.a.call(this,a,void 0===b?0:b);a>this.max&&(a-=2*this.max+2);q(this,a);return a};var TwosComplementBuffer=exports;typeof module!=='undefined'?module.exports=exports :typeof define==='function'&&define.amd?define(['exports'],exports) :typeof global!=='undefined'?global.TwosComplementBuffer=exports:null;
