Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Long

A class representing a 64-bit integer表示64位整数的类

remarks

The internal representation of a long is the two given signed, 32-bit values. long的内部表示形式是两个给定的32位有符号值。We use 32-bit pieces because these are the size of integers on which Javascript performs bit-operations. 我们使用32位片段,因为它们是Javascript执行位操作的整数大小。For operations like addition and multiplication, we split each number into 16 bit pieces, which can easily be multiplied within Javascript's floating-point representation without overflow or change in sign. 对于加法和乘法等操作,我们将每个数字拆分为16位的部分,这些部分可以在Javascript的浮点表示中轻松地进行乘法运算,而不会溢出或改变符号。In the algorithms below, we frequently reduce the negative case to the positive case by negating the input(s) and then post-processing the result. 在下面的算法中,我们经常通过对输入求反,然后对结果进行后处理,将否定情况减少为肯定情况。Note that we must ALWAYS check specially whether those values are MIN_VALUE (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as a positive number, it overflows back into a negative). 请注意,我们必须始终特别检查这些值是否为MIN_VALUE(-2^63),因为-MIN_VALUE==MIN_WALUE(由于2^63不能表示为正数,它会溢出返回负数)。Not handling this case would often result in infinite recursion. 不处理这种情况通常会导致无限递归。Common constant values ZERO, ONE, NEG_ONE, etc. are found as static properties on this class.常见常数值ZERO、ONE、NEG_ONE等都是此类的静态属性。

Hierarchy继承层级

  • Long

Index索引

Constructors构造函数

  • new Long(low?: string | number | bigint, high?: number | boolean, unsigned?: boolean): Long
  • Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as signed integers. 构造一个64位2的补全整数,将其低位和高位32位值作为有符号整数。See the from* functions below for more convenient ways of constructing Longs.有关构造Long的更方便方法,请参阅下面的from*函数。

    Acceptable signatures are:可接受的签名为:

    • Long(low, high, unsigned?)
    • Long(bigint, unsigned?)
    • Long(string, unsigned?)

    Parameters参数

    • Optional low: string | number | bigint

      The low (signed) 32 bits of the long长的低(带符号)32位

    • Optional high: number | boolean

      The high (signed) 32 bits of the long长的高(带符号)32位

    • Optional unsigned: boolean

      Whether unsigned or not, defaults to signed无论是否未签名,默认为已签名

    Returns 返回 Long

Properties属性

__isLong__: true

An indicator used to reliably determine if an object is a Long or not.用于可靠确定对象是否为Long的指示符。

_bsontype: "Long"
high: number

The high 32 bits as a signed value.高32位作为有符号值。

low: number

The low 32 bits as a signed value.低32位作为有符号值。

unsigned: boolean

Whether unsigned or not.无论是否未签名。

MAX_UNSIGNED_VALUE: Long

Maximum unsigned value.最大无符号值。

MAX_VALUE: Long

Maximum signed value.最大有符号值。

MIN_VALUE: Long

Minimum signed value.最小有符号值。

NEG_ONE: Long

Signed negative one.有符号的负数。

ONE: Long

Signed one.签名一。

TWO_PWR_24: Long
UONE: Long

Unsigned one.未签名的。

UZERO: Long

Unsigned zero.无符号零。

ZERO: Long

Signed zero有符号零

Methods方法

  • Returns the sum of this and the specified Long.返回此值与指定的Long值之和。

    Parameters参数

    Returns 返回 Long

  • Returns the sum of this and the specified Long.返回此值与指定的Long值之和。

    Parameters参数

    Returns 返回 Long

    Sum

  • This is an alias of Long.compare这是Long.compare的别名

    Parameters参数

    Returns 返回 0 | 1 | -1

  • Compares this Long's value with the specified's.将此Long的值与指定的值进行比较。

    Parameters参数

    Returns 返回 0 | 1 | -1

    0 if they are the same, 1 if the this is greater and -1 if the given one is greater如果相同,则为0;如果大于1,则为1;如果给定值大于-1,则为-1

  • Returns this Long divided by the specified. 返回此Long除以指定的值。The result is signed if this Long is signed or unsigned if this Long is unsigned.如果此Long为有符号,则结果为有符号;如果此Log为无符号,则为无符号。

    Parameters参数

    Returns 返回 Long

    Quotient

  • This is an alias of Long.equals这是Long.equals的别名

    Parameters参数

    Returns 返回 boolean

  • Tests if this Long's value equals the specified's.测试此Long的值是否等于指定的值。

    Parameters参数

    • other: string | number | Long | Timestamp

      Other value其他价值

    Returns 返回 boolean

  • eqz(): boolean
  • This is an alias of Long.isZero这是Long.isZero的别名

    Returns 返回 boolean

  • This is an alias of 这是Long.greaterThanOrEqual的别名

    Parameters参数

    Returns 返回 boolean

  • getHighBits(): number
  • Gets the high 32 bits as a signed integer.获取高位32位作为有符号整数。

    Returns 返回 number

  • getHighBitsUnsigned(): number
  • Gets the high 32 bits as an unsigned integer.获取高位32位作为无符号整数。

    Returns 返回 number

  • getLowBits(): number
  • Gets the low 32 bits as a signed integer.获取低32位作为有符号整数。

    Returns 返回 number

  • getLowBitsUnsigned(): number
  • Gets the low 32 bits as an unsigned integer.获取低32位作为无符号整数。

    Returns 返回 number

  • getNumBitsAbs(): number
  • Gets the number of bits needed to represent the absolute value of this Long.获取表示此Long的绝对值所需的位数。

    Returns 返回 number

  • Tests if this Long's value is greater than the specified's.测试此Long的值是否大于指定值。

    Parameters参数

    Returns 返回 boolean

  • greaterThanOrEqual(other: string | number | Long | Timestamp): boolean
  • Tests if this Long's value is greater than or equal the specified's.测试此Long值是否大于或等于指定值。

    Parameters参数

    Returns 返回 boolean

  • This is an alias of 这是Long.greaterThan的别名

    Parameters参数

    Returns 返回 boolean

  • This is an alias of 这是Long.greaterThanOrEqual的别名

    Parameters参数

    Returns 返回 boolean

  • inspect(): string
  • Returns 返回 string

  • isEven(): boolean
  • Tests if this Long's value is even.测试此Long的值是否为偶数。

    Returns 返回 boolean

  • isNegative(): boolean
  • Tests if this Long's value is negative.测试此Long的值是否为负值。

    Returns 返回 boolean

  • isOdd(): boolean
  • Tests if this Long's value is odd.测试此Long的值是否为奇数。

    Returns 返回 boolean

  • isPositive(): boolean
  • Tests if this Long's value is positive.测试此Long的值是否为正。

    Returns 返回 boolean

  • isZero(): boolean
  • Tests if this Long's value equals zero.测试此Long的值是否等于零。

    Returns 返回 boolean

  • This is an alias of 这是Long.lessThanOrEqual的别名

    Parameters参数

    Returns 返回 boolean

  • Tests if this Long's value is less than the specified's.测试此Long的值是否小于指定值。

    Parameters参数

    Returns 返回 boolean

  • lessThanOrEqual(other: string | number | Long | Timestamp): boolean
  • Tests if this Long's value is less than or equal the specified's.测试此Long值是否小于或等于指定值。

    Parameters参数

    Returns 返回 boolean

  • This is an alias of Long.lessThan.这是Long.lessThan的别名。

    Parameters参数

    Returns 返回 boolean

  • This is an alias of 这是Long.lessThanOrEqual的别名

    Parameters参数

    Returns 返回 boolean

  • This is an alias of 这是Long.modulo的别名

    Parameters参数

    Returns 返回 Long

  • Returns this Long modulo the specified.返回指定的长模。

    Parameters参数

    Returns 返回 Long

  • This is an alias of 这是Long.multiply的别名

    Parameters参数

    Returns 返回 Long

  • Returns the product of this and the specified Long.返回此值与指定Long的乘积。

    Parameters参数

    Returns 返回 Long

    Product

  • This is an alias of 这是Long.notEquals的别名

    Parameters参数

    Returns 返回 boolean

  • This is an alias of 这是Long.negate的别名

    Returns 返回 Long

  • Returns the Negation of this Long's value.返回此Long值的否定值。

    Returns 返回 Long

  • This is an alias of 这是Long.notEquals的别名

    Parameters参数

    Returns 返回 boolean

  • Returns the bitwise NOT of this Long.返回此Long的按位NOT。

    Returns 返回 Long

  • Tests if this Long's value differs from the specified's.测试此Long的值是否与指定值不同。

    Parameters参数

    Returns 返回 boolean

  • or(other: string | number | Long): Long
  • Returns the bitwise OR of this Long and the specified.返回此Long与指定值的按位OR。

    Parameters参数

    • other: string | number | Long

    Returns 返回 Long

  • This is an alias of 这是Long.modulo的别名

    Parameters参数

    Returns 返回 Long

  • shiftLeft(numBits: number | Long): Long
  • Returns this Long with bits shifted to the left by the given amount.返回此Long,其中位向左移动给定量。

    Parameters参数

    • numBits: number | Long

      Number of bits位数

    Returns 返回 Long

    Shifted Long移位后的Long

  • shiftRight(numBits: number | Long): Long
  • Returns this Long with bits arithmetically shifted to the right by the given amount.返回此Long,并将位算术右移给定量。

    Parameters参数

    • numBits: number | Long

      Number of bits位数

    Returns 返回 Long

    Shifted Long移位后的Long

  • shiftRightUnsigned(numBits: number | Long): Long
  • Returns this Long with bits logically shifted to the right by the given amount.返回此Long,其中位逻辑右移给定量。

    Parameters参数

    • numBits: number | Long

      Number of bits位数

    Returns 返回 Long

    Shifted Long移位后的Long

  • This is an alias of 这是Long.shiftLeft的别名

    Parameters参数

    • numBits: number | Long

    Returns 返回 Long

  • This is an alias of 这是Long.shiftRight的别名

    Parameters参数

    • numBits: number | Long

    Returns 返回 Long

  • This is an alias of 这是Long.shiftRightUnsigned的别名

    Parameters参数

    • numBits: number | Long

    Returns 返回 Long

  • This is an alias of 这是Long.shiftRightUnsigned的别名

    Parameters参数

    • numBits: number | Long

    Returns 返回 Long

  • This is an alias of 这是Long.subtract的别名

    Parameters参数

    Returns 返回 Long

  • Returns the difference of this and the specified Long.返回此值与指定的Long值之差。

    Parameters参数

    Returns 返回 Long

    Difference

  • toBigInt(): bigint
  • Converts the Long to a BigInt (arbitrary precision).将Long转换为BigInt(任意精度)。

    Returns 返回 bigint

  • toBytes(le?: boolean): number[]
  • Converts this Long to its byte representation.将此Long转换为其字节表示形式。

    Parameters参数

    • Optional le: boolean

      Whether little or big endian, defaults to big endian无论是小端还是大端,默认为大端

    Returns 返回 number[]

    Byte representation

  • toBytesBE(): number[]
  • Converts this Long to its big endian byte representation.将此Long转换为其大端字节表示形式。

    Returns 返回 number[]

    Big endian byte representation大端字节表示

  • toBytesLE(): number[]
  • Converts this Long to its little endian byte representation.将此Long转换为其小端字节表示形式。

    Returns 返回 number[]

    Little endian byte representation小端字节表示

  • toExtendedJSON(options?: Options): number | LongExtended
  • Parameters参数

    • Optional options: Options

    Returns 返回 number | LongExtended

  • toInt(): number
  • Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.将Long转换为32位整数,假定它是32位整数。

    Returns 返回 number

  • toNumber(): number
  • Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).将“长”转换为此值的最近浮点表示形式(双精度,53位尾数)。

    Returns 返回 number

  • Converts this Long to signed.将此Long转换为有符号。

    Returns 返回 Long

  • toString(radix?: number): string
  • Converts the Long to a string written in the specified radix.将Long转换为以指定基数写入的字符串。

    throws

    RangeError If radix is out of range

    Parameters参数

    • Optional radix: number

      Radix (2-36), defaults to 10基数(2-36),默认为10

    Returns 返回 string

  • Converts this Long to unsigned.将此Long转换为无符号。

    Returns 返回 Long

  • xor(other: string | number | Long): Long
  • Returns the bitwise XOR of this Long and the given one.返回此Long与给定Long的按位XOR。

    Parameters参数

    • other: string | number | Long

    Returns 返回 Long

  • fromBigInt(value: bigint, unsigned?: boolean): Long
  • Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.返回表示给定值的Long,前提是它是一个有限数。否则,返回零。

    Parameters参数

    • value: bigint

      The number in question有问题的数字

    • Optional unsigned: boolean

      Whether unsigned or not, defaults to signed是否有符号,默认为有符号

    Returns 返回 Long

    The corresponding Long value对应的Long值

  • fromBits(lowBits: number, highBits: number, unsigned?: boolean): Long
  • Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. 返回一个Long,表示通过连接给定的低位和高位而得到的64位整数。Each is assumed to use 32 bits.假设每个都使用32位。

    Parameters参数

    • lowBits: number

      The low 32 bits低32位

    • highBits: number

      The high 32 bits高32位

    • Optional unsigned: boolean

      Whether unsigned or not, defaults to signed无论是否未签名,默认为已签名

    Returns 返回 Long

    The corresponding Long value对应的Long值

  • fromBytes(bytes: number[], unsigned?: boolean, le?: boolean): Long
  • Creates a Long from its byte representation.从字节表示创建Long。

    Parameters参数

    • bytes: number[]

      Byte representation字节表示法

    • Optional unsigned: boolean

      Whether unsigned or not, defaults to signed无论是否未签名,默认为已签名

    • Optional le: boolean

      Whether little or big endian, defaults to big endian无论是小端还是大端,默认为大端

    Returns 返回 Long

    The corresponding Long value对应的Long值

  • fromBytesBE(bytes: number[], unsigned?: boolean): Long
  • Creates a Long from its big endian byte representation.从其大端字节表示创建Long。

    Parameters参数

    • bytes: number[]

      Big endian byte representation大端字节表示

    • Optional unsigned: boolean

      Whether unsigned or not, defaults to signed是否有符号,默认为有符号

    Returns 返回 Long

    The corresponding Long value对应的Long值

  • fromBytesLE(bytes: number[], unsigned?: boolean): Long
  • Creates a Long from its little endian byte representation.从其小端字节表示创建Long。

    Parameters参数

    • bytes: number[]

      Little endian byte representation小端字节表示

    • Optional unsigned: boolean

      Whether unsigned or not, defaults to signed是否有符号,默认为有符号

    Returns 返回 Long

    The corresponding Long value对应的Long值

  • fromExtendedJSON(doc: { $numberLong: string }, options?: Options): number | Long
  • Parameters参数

    • doc: { $numberLong: string }
      • $numberLong: string
    • Optional options: Options

    Returns 返回 number | Long

  • fromInt(value: number, unsigned?: boolean): Long
  • Returns a Long representing the given 32 bit integer value.返回表示给定32位整数值的Long。

    Parameters参数

    • value: number

      The 32 bit integer in question有问题的32位整数

    • Optional unsigned: boolean

      Whether unsigned or not, defaults to signed是否有符号,默认为有符号

    Returns 返回 Long

    The corresponding Long value对应的Long值

  • fromNumber(value: number, unsigned?: boolean): Long
  • Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.返回表示给定值的Long,前提是它是一个有限数。否则,返回零。

    Parameters参数

    • value: number

      The number in question有问题的数字

    • Optional unsigned: boolean

      Whether unsigned or not, defaults to signed是否有符号,默认为有符号

    Returns 返回 Long

    The corresponding Long value对应的Long值

  • fromString(str: string, unsigned?: boolean, radix?: number): Long
  • Returns a Long representation of the given string, written using the specified radix.返回给定字符串的长表示形式,使用指定的基数写入。

    Parameters参数

    • str: string

      The textual representation of the LongLong的文本表示

    • Optional unsigned: boolean

      Whether unsigned or not, defaults to signed是否有符号,默认为有符号

    • Optional radix: number

      The radix in which the text is written (2-36), defaults to 10写入文本的基数(2-36),默认为10

    Returns 返回 Long

    The corresponding Long value对应的Long值

  • fromValue(val: string | number | { high: number; low: number; unsigned?: boolean }, unsigned?: boolean): Long
  • Converts the specified value to a Long.将指定的值转换为Long。

    Parameters参数

    • val: string | number | { high: number; low: number; unsigned?: boolean }
    • Optional unsigned: boolean

      Whether unsigned or not, defaults to signed是否有符号,默认为有符号

    Returns 返回 Long

  • isLong(value: unknown): value is Long
  • Tests if the specified object is a Long.测试指定的对象是否为Long。

    Parameters参数

    • value: unknown

    Returns 返回 value is Long

Generated using TypeDoc