Files
esengine/demo/libs/long/long.min.js
2020-06-17 23:19:25 +08:00

1 line
11 KiB
JavaScript

"use strict";function Long(t,o,i){this.low=0|t,this.high=0|o,this.unsigned=!!i}function isLong(t){return!0===(t&&t.__isLong__)}function fromInt(t,o){var i,n,r;return o?(t>>>=0,(r=0<=t&&t<256)&&(n=UINT_CACHE[t])?n:(i=fromBits(t,(0|t)<0?-1:0,!0),r&&(UINT_CACHE[t]=i),i)):(t|=0,(r=-128<=t&&t<128)&&(n=INT_CACHE[t])?n:(i=fromBits(t,t<0?-1:0,!1),r&&(INT_CACHE[t]=i),i))}function fromNumber(t,o){if(isNaN(t))return o?UZERO:ZERO;if(o){if(t<0)return UZERO;if(t>=TWO_PWR_64_DBL)return MAX_UNSIGNED_VALUE}else{if(t<=-TWO_PWR_63_DBL)return MIN_VALUE;if(t+1>=TWO_PWR_63_DBL)return MAX_VALUE}return t<0?fromNumber(-t,o).neg():fromBits(t%TWO_PWR_32_DBL|0,t/TWO_PWR_32_DBL|0,o)}function fromBits(t,o,i){return new Long(t,o,i)}function fromString(t,o,i){if(0===t.length)throw Error("empty string");if("NaN"===t||"Infinity"===t||"+Infinity"===t||"-Infinity"===t)return ZERO;if("number"==typeof o?(i=o,o=!1):o=!!o,(i=i||10)<2||36<i)throw RangeError("radix");var n;if((n=t.indexOf("-"))>0)throw Error("interior hyphen");if(0===n)return fromString(t.substring(1),o,i).neg();for(var r=fromNumber(pow_dbl(i,8)),e=ZERO,s=0;s<t.length;s+=8){var h=Math.min(8,t.length-s),g=parseInt(t.substring(s,s+h),i);if(h<8){var u=fromNumber(pow_dbl(i,h));e=e.mul(u).add(fromNumber(g))}else e=e.mul(r),e=e.add(fromNumber(g))}return e.unsigned=o,e}function fromValue(t,o){return"number"==typeof t?fromNumber(t,o):"string"==typeof t?fromString(t,o):fromBits(t.low,t.high,"boolean"==typeof o?o:t.unsigned)}var wasm=null;Long.prototype.__isLong__,Object.defineProperty(Long.prototype,"__isLong__",{value:!0}),Long.isLong=isLong;var INT_CACHE={},UINT_CACHE={};Long.fromInt=fromInt,Long.fromNumber=fromNumber,Long.fromBits=fromBits;var pow_dbl=Math.pow;Long.fromString=fromString,Long.fromValue=fromValue;var TWO_PWR_16_DBL=65536,TWO_PWR_24_DBL=1<<24,TWO_PWR_32_DBL=TWO_PWR_16_DBL*TWO_PWR_16_DBL,TWO_PWR_64_DBL=TWO_PWR_32_DBL*TWO_PWR_32_DBL,TWO_PWR_63_DBL=TWO_PWR_64_DBL/2,TWO_PWR_24=fromInt(TWO_PWR_24_DBL),ZERO=fromInt(0);Long.ZERO=ZERO;var UZERO=fromInt(0,!0);Long.UZERO=UZERO;var ONE=fromInt(1);Long.ONE=ONE;var UONE=fromInt(1,!0);Long.UONE=UONE;var NEG_ONE=fromInt(-1);Long.NEG_ONE=NEG_ONE;var MAX_VALUE=fromBits(-1,2147483647,!1);Long.MAX_VALUE=MAX_VALUE;var MAX_UNSIGNED_VALUE=fromBits(-1,-1,!0);Long.MAX_UNSIGNED_VALUE=MAX_UNSIGNED_VALUE;var MIN_VALUE=fromBits(0,-2147483648,!1);Long.MIN_VALUE=MIN_VALUE;var LongPrototype=Long.prototype;LongPrototype.toInt=function(){return this.unsigned?this.low>>>0:this.low},LongPrototype.toNumber=function(){return this.unsigned?(this.high>>>0)*TWO_PWR_32_DBL+(this.low>>>0):this.high*TWO_PWR_32_DBL+(this.low>>>0)},LongPrototype.toString=function(t){if((t=t||10)<2||36<t)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(MIN_VALUE)){var o=fromNumber(t),i=this.div(o),n=i.mul(o).sub(this);return i.toString(t)+n.toInt().toString(t)}return"-"+this.neg().toString(t)}for(var r=fromNumber(pow_dbl(t,6),this.unsigned),e=this,s="";;){var h=e.div(r),g=e.sub(h.mul(r)).toInt()>>>0,u=g.toString(t);if(e=h,e.isZero())return u+s;for(;u.length<6;)u="0"+u;s=""+u+s}},LongPrototype.getHighBits=function(){return this.high},LongPrototype.getHighBitsUnsigned=function(){return this.high>>>0},LongPrototype.getLowBits=function(){return this.low},LongPrototype.getLowBitsUnsigned=function(){return this.low>>>0},LongPrototype.getNumBitsAbs=function(){if(this.isNegative())return this.eq(MIN_VALUE)?64:this.neg().getNumBitsAbs();for(var t=0!=this.high?this.high:this.low,o=31;o>0&&0==(t&1<<o);o--);return 0!=this.high?o+33:o+1},LongPrototype.isZero=function(){return 0===this.high&&0===this.low},LongPrototype.eqz=LongPrototype.isZero,LongPrototype.isNegative=function(){return!this.unsigned&&this.high<0},LongPrototype.isPositive=function(){return this.unsigned||this.high>=0},LongPrototype.isOdd=function(){return 1==(1&this.low)},LongPrototype.isEven=function(){return 0==(1&this.low)},LongPrototype.equals=function(t){return isLong(t)||(t=fromValue(t)),(this.unsigned===t.unsigned||this.high>>>31!=1||t.high>>>31!=1)&&(this.high===t.high&&this.low===t.low)},LongPrototype.eq=LongPrototype.equals,LongPrototype.notEquals=function(t){return!this.eq(t)},LongPrototype.neq=LongPrototype.notEquals,LongPrototype.ne=LongPrototype.notEquals,LongPrototype.lessThan=function(t){return this.comp(t)<0},LongPrototype.lt=LongPrototype.lessThan,LongPrototype.lessThanOrEqual=function(t){return this.comp(t)<=0},LongPrototype.lte=LongPrototype.lessThanOrEqual,LongPrototype.le=LongPrototype.lessThanOrEqual,LongPrototype.greaterThan=function(t){return this.comp(t)>0},LongPrototype.gt=LongPrototype.greaterThan,LongPrototype.greaterThanOrEqual=function(t){return this.comp(t)>=0},LongPrototype.gte=LongPrototype.greaterThanOrEqual,LongPrototype.ge=LongPrototype.greaterThanOrEqual,LongPrototype.compare=function(t){if(isLong(t)||(t=fromValue(t)),this.eq(t))return 0;var o=this.isNegative(),i=t.isNegative();return o&&!i?-1:!o&&i?1:this.unsigned?t.high>>>0>this.high>>>0||t.high===this.high&&t.low>>>0>this.low>>>0?-1:1:this.sub(t).isNegative()?-1:1},LongPrototype.comp=LongPrototype.compare,LongPrototype.negate=function(){return!this.unsigned&&this.eq(MIN_VALUE)?MIN_VALUE:this.not().add(ONE)},LongPrototype.neg=LongPrototype.negate,LongPrototype.add=function(t){isLong(t)||(t=fromValue(t));var o=this.high>>>16,i=65535&this.high,n=this.low>>>16,r=65535&this.low,e=t.high>>>16,s=65535&t.high,h=t.low>>>16,g=65535&t.low,u=0,f=0,L=0,m=0;return m+=r+g,L+=m>>>16,m&=65535,L+=n+h,f+=L>>>16,L&=65535,f+=i+s,u+=f>>>16,f&=65535,u+=o+e,u&=65535,fromBits(L<<16|m,u<<16|f,this.unsigned)},LongPrototype.subtract=function(t){return isLong(t)||(t=fromValue(t)),this.add(t.neg())},LongPrototype.sub=LongPrototype.subtract,LongPrototype.multiply=function(t){if(this.isZero())return ZERO;if(isLong(t)||(t=fromValue(t)),wasm){return fromBits(wasm.mul(this.low,this.high,t.low,t.high),wasm.get_high(),this.unsigned)}if(t.isZero())return ZERO;if(this.eq(MIN_VALUE))return t.isOdd()?MIN_VALUE:ZERO;if(t.eq(MIN_VALUE))return this.isOdd()?MIN_VALUE:ZERO;if(this.isNegative())return t.isNegative()?this.neg().mul(t.neg()):this.neg().mul(t).neg();if(t.isNegative())return this.mul(t.neg()).neg();if(this.lt(TWO_PWR_24)&&t.lt(TWO_PWR_24))return fromNumber(this.toNumber()*t.toNumber(),this.unsigned);var o=this.high>>>16,i=65535&this.high,n=this.low>>>16,r=65535&this.low,e=t.high>>>16,s=65535&t.high,h=t.low>>>16,g=65535&t.low,u=0,f=0,L=0,m=0;return m+=r*g,L+=m>>>16,m&=65535,L+=n*g,f+=L>>>16,L&=65535,L+=r*h,f+=L>>>16,L&=65535,f+=i*g,u+=f>>>16,f&=65535,f+=n*h,u+=f>>>16,f&=65535,f+=r*s,u+=f>>>16,f&=65535,u+=o*g+i*h+n*s+r*e,u&=65535,fromBits(L<<16|m,u<<16|f,this.unsigned)},LongPrototype.mul=LongPrototype.multiply,LongPrototype.divide=function(t){if(isLong(t)||(t=fromValue(t)),t.isZero())throw Error("division by zero");if(wasm){if(!this.unsigned&&-2147483648===this.high&&-1===t.low&&-1===t.high)return this;return fromBits((this.unsigned?wasm.div_u:wasm.div_s)(this.low,this.high,t.low,t.high),wasm.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?UZERO:ZERO;var o,i,n;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return UZERO;if(t.gt(this.shru(1)))return UONE;n=UZERO}else{if(this.eq(MIN_VALUE)){if(t.eq(ONE)||t.eq(NEG_ONE))return MIN_VALUE;if(t.eq(MIN_VALUE))return ONE;return o=this.shr(1).div(t).shl(1),o.eq(ZERO)?t.isNegative()?ONE:NEG_ONE:(i=this.sub(t.mul(o)),n=o.add(i.div(t)))}if(t.eq(MIN_VALUE))return this.unsigned?UZERO:ZERO;if(this.isNegative())return t.isNegative()?this.neg().div(t.neg()):this.neg().div(t).neg();if(t.isNegative())return this.div(t.neg()).neg();n=ZERO}for(i=this;i.gte(t);){o=Math.max(1,Math.floor(i.toNumber()/t.toNumber()));for(var r=Math.ceil(Math.log(o)/Math.LN2),e=r<=48?1:pow_dbl(2,r-48),s=fromNumber(o),h=s.mul(t);h.isNegative()||h.gt(i);)o-=e,s=fromNumber(o,this.unsigned),h=s.mul(t);s.isZero()&&(s=ONE),n=n.add(s),i=i.sub(h)}return n},LongPrototype.div=LongPrototype.divide,LongPrototype.modulo=function(t){if(isLong(t)||(t=fromValue(t)),wasm){return fromBits((this.unsigned?wasm.rem_u:wasm.rem_s)(this.low,this.high,t.low,t.high),wasm.get_high(),this.unsigned)}return this.sub(this.div(t).mul(t))},LongPrototype.mod=LongPrototype.modulo,LongPrototype.rem=LongPrototype.modulo,LongPrototype.not=function(){return fromBits(~this.low,~this.high,this.unsigned)},LongPrototype.and=function(t){return isLong(t)||(t=fromValue(t)),fromBits(this.low&t.low,this.high&t.high,this.unsigned)},LongPrototype.or=function(t){return isLong(t)||(t=fromValue(t)),fromBits(this.low|t.low,this.high|t.high,this.unsigned)},LongPrototype.xor=function(t){return isLong(t)||(t=fromValue(t)),fromBits(this.low^t.low,this.high^t.high,this.unsigned)},LongPrototype.shiftLeft=function(t){return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?fromBits(this.low<<t,this.high<<t|this.low>>>32-t,this.unsigned):fromBits(0,this.low<<t-32,this.unsigned)},LongPrototype.shl=LongPrototype.shiftLeft,LongPrototype.shiftRight=function(t){return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?fromBits(this.low>>>t|this.high<<32-t,this.high>>t,this.unsigned):fromBits(this.high>>t-32,this.high>=0?0:-1,this.unsigned)},LongPrototype.shr=LongPrototype.shiftRight,LongPrototype.shiftRightUnsigned=function(t){return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?fromBits(this.low>>>t|this.high<<32-t,this.high>>>t,this.unsigned):32===t?fromBits(this.high,0,this.unsigned):fromBits(this.high>>>t-32,0,this.unsigned)},LongPrototype.shru=LongPrototype.shiftRightUnsigned,LongPrototype.shr_u=LongPrototype.shiftRightUnsigned,LongPrototype.rotateLeft=function(t){var o;return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:32===t?fromBits(this.high,this.low,this.unsigned):t<32?(o=32-t,fromBits(this.low<<t|this.high>>>o,this.high<<t|this.low>>>o,this.unsigned)):(t-=32,o=32-t,fromBits(this.high<<t|this.low>>>o,this.low<<t|this.high>>>o,this.unsigned))},LongPrototype.rotl=LongPrototype.rotateLeft,LongPrototype.rotateRight=function(t){var o;return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:32===t?fromBits(this.high,this.low,this.unsigned):t<32?(o=32-t,fromBits(this.high<<o|this.low>>>t,this.low<<o|this.high>>>t,this.unsigned)):(t-=32,o=32-t,fromBits(this.low<<o|this.high>>>t,this.high<<o|this.low>>>t,this.unsigned))},LongPrototype.rotr=LongPrototype.rotateRight,LongPrototype.toSigned=function(){return this.unsigned?fromBits(this.low,this.high,!1):this},LongPrototype.toUnsigned=function(){return this.unsigned?this:fromBits(this.low,this.high,!0)},LongPrototype.toBytes=function(t){return t?this.toBytesLE():this.toBytesBE()},LongPrototype.toBytesLE=function(){var t=this.high,o=this.low;return[255&o,o>>>8&255,o>>>16&255,o>>>24,255&t,t>>>8&255,t>>>16&255,t>>>24]},LongPrototype.toBytesBE=function(){var t=this.high,o=this.low;return[t>>>24,t>>>16&255,t>>>8&255,255&t,o>>>24,o>>>16&255,o>>>8&255,255&o]},Long.fromBytes=function(t,o,i){return i?Long.fromBytesLE(t,o):Long.fromBytesBE(t,o)},Long.fromBytesLE=function(t,o){return new Long(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,o)},Long.fromBytesBE=function(t,o){return new Long(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],o)},window.long=Long;