/** * Tests if this Long's value is negative. * @returns {boolean} */ isNegative() { return this.value < BigInt(0) }
process(src, fileName) { // Make sure that source maps are always enabled and inline so that they // can be picked up by the `source-map-support` package. return tsc.transpileModule(src, { compilerOptions: compilerOptions, fileName: fileName, }).outputText; }
/** * Gets the low 32 bits as a signed integer. * @returns {number} Signed low bits */ getLowBits() { return Number(BigInt.asIntN(32, this.value)) }
/** * @param {string} str * @returns {!Long} * @inner */ static fromString(str) { if (str.length === 0) throw Error('empty string') if (str === 'NaN' || str === 'Infinity' || str === '+Infinity' || str === '-Infinity') return Long.ZERO return new Long(BigInt(str)) }
/** * @function * @param {bigint|number|string|Long} val * @returns {!Long} * @inner */ static fromValue(val) { if (typeof val === 'number') return this.fromNumber(val) if (typeof val === 'string') return this.fromString(val) if (typeof val === 'bigint') return new Long(val) if (this.isLong(val)) return new Long(BigInt(val.value)) return new Long(BigInt(val)) }
readInt64() { const first = this.buffer[this.offset] const last = this.buffer[this.offset + 7] const low = (first << 24) + // Overflow this.buffer[this.offset + 1] * 2 ** 16 + this.buffer[this.offset + 2] * 2 ** 8 + this.buffer[this.offset + 3] const high = this.buffer[this.offset + 4] * 2 ** 24 + this.buffer[this.offset + 5] * 2 ** 16 + this.buffer[this.offset + 6] * 2 ** 8 + last this.offset += INT64_SIZE return (BigInt(low) << 32n) + BigInt(high) }
/** * Returns this Long with bits arithmetically shifted to the right by the given amount. * @param {number|bigint} numBits Number of bits * @returns {!Long} Shifted bigint */ shiftRight(numBits) { return new Long(this.value >> BigInt(numBits)) }
/** * @param {number} value * @returns {!Long} * @inner */ static fromBits(value) { return new Long(BigInt(value)) }
/** * @param {number} value * @returns {!Long} * @inner */ static fromNumber(value) { if (isNaN(value)) return Long.ZERO return new Long(BigInt(value)) }
/** * Tests if this Long's value equals zero. * @returns {boolean} */ isZero() { return this.value === BigInt(0) }
/** * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. * @returns {number} */ toInt() { return Number(BigInt.asIntN(32, this.value)) }
/** * Returns this Long with bits shifted to the left by the given amount. * @param {number|bigint} numBits Number of bits * @returns {!Long} Shifted bigint */ shiftLeft(numBits) { return new Long(this.value << BigInt(numBits)) }