This commit is contained in:
YHH
2020-06-17 22:40:49 +08:00
parent ccf8c4e107
commit e6d6c4199f
8 changed files with 33 additions and 35 deletions

View File

@@ -559,11 +559,11 @@ declare interface Long {
divide(divisor: any): Long; divide(divisor: any): Long;
equals(other: any): any; equals(other: any): any;
not(): any; not(): any;
toString(radix: any): string; toString(radix?: any): string;
isZero(): any; isZero(): any;
isNegative(): any; isNegative(): any;
multiply(multiplier: any): Long; multiply(multiplier: any): Long;
shiftRight(numBits: any): any; shiftRight(numBits: any): Long;
shiftRightUnsigned(numBits: any): any; shiftRightUnsigned(numBits: any): any;
subtract(subtrahend: any): Long; subtract(subtrahend: any): Long;
greaterThan(other: any): any; greaterThan(other: any): any;
@@ -593,7 +593,7 @@ declare class Long {
static max_value: Long; static max_value: Long;
static one: Long; static one: Long;
static neg_one: Long; static neg_one: Long;
constructor(low: number, high: number, unsigned?: boolean); constructor(low: number, high: number, unsigned: boolean);
shiftLeft(numBits: number | Long): Long; shiftLeft(numBits: number | Long): Long;
static fromBits(lowBits: any, highBits: any, unsigned: any): Long; static fromBits(lowBits: any, highBits: any, unsigned: any): Long;
static fromValue(val: number | string | { static fromValue(val: number | string | {

View File

@@ -2613,7 +2613,6 @@ var Flags = (function () {
}()); }());
var Long = (function () { var Long = (function () {
function Long(low, high, unsigned) { function Long(low, high, unsigned) {
if (unsigned === void 0) { unsigned = true; }
this.low = low | 0; this.low = low | 0;
this.high = high | 0; this.high = high | 0;
this.unsigned = !!unsigned; this.unsigned = !!unsigned;
@@ -2841,8 +2840,8 @@ Long.prototype.divide = function (divisor) {
return Long.one; return Long.one;
else { else {
var halfThis = i.shiftRight(1); var halfThis = i.shiftRight(1);
approx = halfThis.div(divisor).shl(1); approx = halfThis.divide(divisor).shiftLeft(1);
if (approx.eq(Long.zero)) { if (approx.equals(Long.zero)) {
return divisor.isNegative() ? Long.one : Long.neg_one; return divisor.isNegative() ? Long.one : Long.neg_one;
} }
else { else {
@@ -2860,7 +2859,7 @@ Long.prototype.divide = function (divisor) {
return i.negate().divide(divisor).negate(); return i.negate().divide(divisor).negate();
} }
else if (divisor.isNegative()) else if (divisor.isNegative())
return this.div(divisor.negate()).neg(); return i.divide(divisor.negate()).negate();
res = Long.zero; res = Long.zero;
} }
else { else {
@@ -2878,7 +2877,7 @@ Long.prototype.divide = function (divisor) {
var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48), approxRes = Long.fromNumber(approx), approxRem = approxRes.multiply(divisor); var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48), approxRes = Long.fromNumber(approx), approxRem = approxRes.multiply(divisor);
while (approxRem.isNegative() || approxRem.greaterThan(rem)) { while (approxRem.isNegative() || approxRem.greaterThan(rem)) {
approx -= delta; approx -= delta;
approxRes = Long.fromNumber(approx, this.unsigned); approxRes = Long.fromNumber(approx, i.unsigned);
approxRem = approxRes.multiply(divisor); approxRem = approxRes.multiply(divisor);
} }
if (approxRes.isZero()) if (approxRes.isZero())
@@ -2924,7 +2923,7 @@ Long.prototype.greaterThan = function (other) {
}; };
Long.prototype.compare = function (other) { Long.prototype.compare = function (other) {
var i = this; var i = this;
if (typeof (other) === "number") if (typeof other === "number")
other = Long.fromValue(other); other = Long.fromValue(other);
if (i.equals(other)) if (i.equals(other))
return 0; return 0;
@@ -4251,7 +4250,7 @@ var NumberDictionary = (function () {
this._store = new Map(); this._store = new Map();
} }
NumberDictionary.prototype.getKey = function (x, y) { NumberDictionary.prototype.getKey = function (x, y) {
return Number(Long.fromValue(x).shiftLeft(32).toString(10)) | this.intToUint(y); return Number(Long.fromNumber(x).shiftLeft(32).toString()) | this.intToUint(y);
}; };
NumberDictionary.prototype.intToUint = function (i) { NumberDictionary.prototype.intToUint = function (i) {
if (i >= 0) if (i >= 0)

File diff suppressed because one or more lines are too long

View File

@@ -559,11 +559,11 @@ declare interface Long {
divide(divisor: any): Long; divide(divisor: any): Long;
equals(other: any): any; equals(other: any): any;
not(): any; not(): any;
toString(radix: any): string; toString(radix?: any): string;
isZero(): any; isZero(): any;
isNegative(): any; isNegative(): any;
multiply(multiplier: any): Long; multiply(multiplier: any): Long;
shiftRight(numBits: any): any; shiftRight(numBits: any): Long;
shiftRightUnsigned(numBits: any): any; shiftRightUnsigned(numBits: any): any;
subtract(subtrahend: any): Long; subtract(subtrahend: any): Long;
greaterThan(other: any): any; greaterThan(other: any): any;
@@ -593,7 +593,7 @@ declare class Long {
static max_value: Long; static max_value: Long;
static one: Long; static one: Long;
static neg_one: Long; static neg_one: Long;
constructor(low: number, high: number, unsigned?: boolean); constructor(low: number, high: number, unsigned: boolean);
shiftLeft(numBits: number | Long): Long; shiftLeft(numBits: number | Long): Long;
static fromBits(lowBits: any, highBits: any, unsigned: any): Long; static fromBits(lowBits: any, highBits: any, unsigned: any): Long;
static fromValue(val: number | string | { static fromValue(val: number | string | {

View File

@@ -2613,7 +2613,6 @@ var Flags = (function () {
}()); }());
var Long = (function () { var Long = (function () {
function Long(low, high, unsigned) { function Long(low, high, unsigned) {
if (unsigned === void 0) { unsigned = true; }
this.low = low | 0; this.low = low | 0;
this.high = high | 0; this.high = high | 0;
this.unsigned = !!unsigned; this.unsigned = !!unsigned;
@@ -2841,8 +2840,8 @@ Long.prototype.divide = function (divisor) {
return Long.one; return Long.one;
else { else {
var halfThis = i.shiftRight(1); var halfThis = i.shiftRight(1);
approx = halfThis.div(divisor).shl(1); approx = halfThis.divide(divisor).shiftLeft(1);
if (approx.eq(Long.zero)) { if (approx.equals(Long.zero)) {
return divisor.isNegative() ? Long.one : Long.neg_one; return divisor.isNegative() ? Long.one : Long.neg_one;
} }
else { else {
@@ -2860,7 +2859,7 @@ Long.prototype.divide = function (divisor) {
return i.negate().divide(divisor).negate(); return i.negate().divide(divisor).negate();
} }
else if (divisor.isNegative()) else if (divisor.isNegative())
return this.div(divisor.negate()).neg(); return i.divide(divisor.negate()).negate();
res = Long.zero; res = Long.zero;
} }
else { else {
@@ -2878,7 +2877,7 @@ Long.prototype.divide = function (divisor) {
var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48), approxRes = Long.fromNumber(approx), approxRem = approxRes.multiply(divisor); var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48), approxRes = Long.fromNumber(approx), approxRem = approxRes.multiply(divisor);
while (approxRem.isNegative() || approxRem.greaterThan(rem)) { while (approxRem.isNegative() || approxRem.greaterThan(rem)) {
approx -= delta; approx -= delta;
approxRes = Long.fromNumber(approx, this.unsigned); approxRes = Long.fromNumber(approx, i.unsigned);
approxRem = approxRes.multiply(divisor); approxRem = approxRes.multiply(divisor);
} }
if (approxRes.isZero()) if (approxRes.isZero())
@@ -2924,7 +2923,7 @@ Long.prototype.greaterThan = function (other) {
}; };
Long.prototype.compare = function (other) { Long.prototype.compare = function (other) {
var i = this; var i = this;
if (typeof (other) === "number") if (typeof other === "number")
other = Long.fromValue(other); other = Long.fromValue(other);
if (i.equals(other)) if (i.equals(other))
return 0; return 0;
@@ -4251,7 +4250,7 @@ var NumberDictionary = (function () {
this._store = new Map(); this._store = new Map();
} }
NumberDictionary.prototype.getKey = function (x, y) { NumberDictionary.prototype.getKey = function (x, y) {
return Number(Long.fromValue(x).shiftLeft(32).toString(10)) | this.intToUint(y); return Number(Long.fromNumber(x << 32).toString()) | this.intToUint(y);
}; };
NumberDictionary.prototype.intToUint = function (i) { NumberDictionary.prototype.intToUint = function (i) {
if (i >= 0) if (i >= 0)

File diff suppressed because one or more lines are too long

View File

@@ -5,11 +5,11 @@ declare interface Long {
divide(divisor): Long; divide(divisor): Long;
equals(other); equals(other);
not(); not();
toString(radix): string; toString(radix?): string;
isZero(); isZero();
isNegative(); isNegative();
multiply(multiplier): Long; multiply(multiplier): Long;
shiftRight(numBits); shiftRight(numBits): Long;
shiftRightUnsigned(numBits); shiftRightUnsigned(numBits);
subtract(subtrahend): Long; subtract(subtrahend): Long;
greaterThan(other); greaterThan(other);
@@ -42,7 +42,7 @@ class Long {
public static one = Long.fromInt(1); public static one = Long.fromInt(1);
public static neg_one = Long.fromInt(-1); public static neg_one = Long.fromInt(-1);
constructor(low: number, high: number, unsigned: boolean = true){ constructor(low: number, high: number, unsigned: boolean){
this.low = low | 0; this.low = low | 0;
this.high = high | 0; this.high = high | 0;
this.unsigned = !!unsigned; this.unsigned = !!unsigned;
@@ -216,7 +216,7 @@ Long.prototype.not = function(){
return Long.fromBits(~i.low, ~i.high, i.unsigned); return Long.fromBits(~i.low, ~i.high, i.unsigned);
} }
Long.prototype.toString = function(radix){ Long.prototype.toString = function(radix?){
let i = this as Long; let i = this as Long;
radix = radix || 10; radix = radix || 10;
if (radix < 2 || 36 < radix) if (radix < 2 || 36 < radix)
@@ -271,7 +271,7 @@ Long.prototype.divide = function(divisor: number | Long){
if (i.isZero()) if (i.isZero())
return i.unsigned ? Long.uzero : Long.zero; return i.unsigned ? Long.uzero : Long.zero;
let approx, rem: Long, res; let approx: number | Long, rem: Long, res;
if (!i.unsigned) { if (!i.unsigned) {
if (i.equals(Long.min_value)) { if (i.equals(Long.min_value)) {
if (divisor.equals(Long.one) || divisor.equals(Long.neg_one)) if (divisor.equals(Long.one) || divisor.equals(Long.neg_one))
@@ -279,9 +279,9 @@ Long.prototype.divide = function(divisor: number | Long){
else if (divisor.equals(Long.min_value)) else if (divisor.equals(Long.min_value))
return Long.one; return Long.one;
else { else {
var halfThis = i.shiftRight(1); let halfThis = i.shiftRight(1);
approx = halfThis.div(divisor).shl(1); approx = halfThis.divide(divisor).shiftLeft(1);
if (approx.eq(Long.zero)) { if (approx.equals(Long.zero)) {
return divisor.isNegative() ? Long.one : Long.neg_one; return divisor.isNegative() ? Long.one : Long.neg_one;
} else { } else {
rem = i.subtract(divisor.multiply(approx)); rem = i.subtract(divisor.multiply(approx));
@@ -296,7 +296,7 @@ Long.prototype.divide = function(divisor: number | Long){
return i.negate().divide(divisor.negate()); return i.negate().divide(divisor.negate());
return i.negate().divide(divisor).negate(); return i.negate().divide(divisor).negate();
} else if (divisor.isNegative()) } else if (divisor.isNegative())
return this.div(divisor.negate()).neg(); return i.divide(divisor.negate()).negate();
res = Long.zero; res = Long.zero;
} else { } else {
if (!divisor.unsigned) if (!divisor.unsigned)
@@ -318,7 +318,7 @@ Long.prototype.divide = function(divisor: number | Long){
approxRem = approxRes.multiply(divisor); approxRem = approxRes.multiply(divisor);
while (approxRem.isNegative() || approxRem.greaterThan(rem)) { while (approxRem.isNegative() || approxRem.greaterThan(rem)) {
approx -= delta; approx -= delta;
approxRes = Long.fromNumber(approx, this.unsigned); approxRes = Long.fromNumber(approx, i.unsigned);
approxRem = approxRes.multiply(divisor); approxRem = approxRes.multiply(divisor);
} }
@@ -358,7 +358,7 @@ Long.prototype.subtract = function(subtrahend: number | Long){
let i = this as Long; let i = this as Long;
if (typeof subtrahend === "number") if (typeof subtrahend === "number")
subtrahend = Long.fromValue(subtrahend); subtrahend = Long.fromValue(subtrahend);
return i.add((subtrahend as Long).negate()); return i.add(subtrahend.negate());
} }
Long.prototype.greaterThan = function(other){ Long.prototype.greaterThan = function(other){
@@ -368,7 +368,7 @@ Long.prototype.greaterThan = function(other){
Long.prototype.compare = function(other: number | Long){ Long.prototype.compare = function(other: number | Long){
let i = this as Long; let i = this as Long;
if (typeof (other) === "number") if (typeof other === "number")
other = Long.fromValue(other); other = Long.fromValue(other);
if (i.equals(other)) if (i.equals(other))
return 0; return 0;

View File

@@ -132,7 +132,7 @@ class NumberDictionary {
* @param y * @param y
*/ */
private getKey(x: number, y: number): number { private getKey(x: number, y: number): number {
return Number(Long.fromValue(x).shiftLeft(32).toString(10)) | this.intToUint(y); return Number(Long.fromNumber(x << 32).toString()) | this.intToUint(y);
} }
private intToUint(i) { private intToUint(i) {