API 参考
    正在准备搜索索引...

    A class representing a 64-bit integer

    The internal representation of a long is the two given signed, 32-bit values. We use 32-bit pieces because these are the size of integers on which Javascript performs bit-operations. 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. 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). 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.

    层级 (查看层级一览)

    索引

    构造函数

    • Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as signed integers. See the from* functions below for more convenient ways of constructing Longs.

      Acceptable signatures are:

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

      参数

      • 可选low: string | number | bigint

        The low (signed) 32 bits of the long

      • 可选high: number | boolean

        The high (signed) 32 bits of the long

      • 可选unsigned: boolean

        Whether unsigned or not, defaults to signed

      返回 Long

    属性

    high: number

    The high 32 bits as a signed value.

    low: number

    The low 32 bits as a signed value.

    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

    访问器

    • get __isLong__(): boolean

      An indicator used to reliably determine if an object is a Long or not.

      返回 boolean

    • get _bsontype(): "Long"

      返回 "Long"

    方法

    • Returns the sum of this and the specified Long.

      参数

      返回 Long

    • Returns the sum of this and the specified Long.

      参数

      返回 Long

      Sum

    • This is an alias of Long.compare

      参数

      返回 -1 | 0 | 1

    • Compares this Long's value with the specified's.

      参数

      返回 -1 | 0 | 1

      0 if they are the same, 1 if the this is greater and -1 if the given one is greater

    • This is an alias of Long.divide

      参数

      返回 Long

    • Returns this Long divided by the specified. The result is signed if this Long is signed or unsigned if this Long is unsigned.

      参数

      返回 Long

      Quotient

    • This is an alias of Long.equals

      参数

      返回 boolean

    • Tests if this Long's value equals the specified's.

      参数

      返回 boolean

    • This is an alias of Long.isZero

      返回 boolean

    • This is an alias of Long.greaterThanOrEqual

      参数

      返回 boolean

    • Gets the high 32 bits as a signed integer.

      返回 number

    • Gets the high 32 bits as an unsigned integer.

      返回 number

    • Gets the low 32 bits as a signed integer.

      返回 number

    • Gets the low 32 bits as an unsigned integer.

      返回 number

    • Gets the number of bits needed to represent the absolute value of this Long.

      返回 number

    • Tests if this Long's value is greater than the specified's.

      参数

      返回 boolean

    • Tests if this Long's value is greater than or equal the specified's.

      参数

      返回 boolean

    • This is an alias of Long.greaterThan

      参数

      返回 boolean

    • This is an alias of Long.greaterThanOrEqual

      参数

      返回 boolean

    • 返回 string

    • Tests if this Long's value is even.

      返回 boolean

    • Tests if this Long's value is negative.

      返回 boolean

    • Tests if this Long's value is odd.

      返回 boolean

    • Tests if this Long's value is positive.

      返回 boolean

    • Tests if this Long's value equals zero.

      返回 boolean

    • This is an alias of Long.lessThanOrEqual

      参数

      返回 boolean

    • Tests if this Long's value is less than the specified's.

      参数

      返回 boolean

    • Tests if this Long's value is less than or equal the specified's.

      参数

      返回 boolean

    • This is an alias of Long#lessThan.

      参数

      返回 boolean

    • This is an alias of Long.lessThanOrEqual

      参数

      返回 boolean

    • This is an alias of Long.modulo

      参数

      返回 Long

    • Returns this Long modulo the specified.

      参数

      返回 Long

    • This is an alias of Long.multiply

      参数

      返回 Long

    • Returns the product of this and the specified Long.

      参数

      返回 Long

      Product

    • This is an alias of Long.notEquals

      参数

      返回 boolean

    • This is an alias of Long.negate

      返回 Long

    • Returns the Negation of this Long's value.

      返回 Long

    • This is an alias of Long.notEquals

      参数

      返回 boolean

    • Returns the bitwise NOT of this Long.

      返回 Long

    • Tests if this Long's value differs from the specified's.

      参数

      返回 boolean

    • Returns the bitwise OR of this Long and the specified.

      参数

      • other: string | number | Long

      返回 Long

    • This is an alias of Long.modulo

      参数

      返回 Long

    • Returns this Long with bits shifted to the left by the given amount.

      参数

      • numBits: number | Long

        Number of bits

      返回 Long

      Shifted Long

    • Returns this Long with bits arithmetically shifted to the right by the given amount.

      参数

      • numBits: number | Long

        Number of bits

      返回 Long

      Shifted Long

    • Returns this Long with bits logically shifted to the right by the given amount.

      参数

      • numBits: number | Long

        Number of bits

      返回 Long

      Shifted Long

    • This is an alias of Long.shiftLeft

      参数

      • numBits: number | Long

      返回 Long

    • This is an alias of Long.shiftRight

      参数

      • numBits: number | Long

      返回 Long

    • This is an alias of Long.shiftRightUnsigned

      参数

      • numBits: number | Long

      返回 Long

    • This is an alias of Long.shiftRightUnsigned

      参数

      • numBits: number | Long

      返回 Long

    • This is an alias of Long.subtract

      参数

      返回 Long

    • Returns the difference of this and the specified Long.

      参数

      返回 Long

      Difference

    • Converts the Long to a BigInt (arbitrary precision).

      返回 bigint

    • Converts this Long to its byte representation.

      参数

      • 可选le: boolean

        Whether little or big endian, defaults to big endian

      返回 number[]

      Byte representation

    • Converts this Long to its big endian byte representation.

      返回 number[]

      Big endian byte representation

    • Converts this Long to its little endian byte representation.

      返回 number[]

      Little endian byte representation

    • 参数

      返回 number | LongExtended

    • Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.

      返回 number

    • Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).

      返回 number

    • Converts this Long to signed.

      返回 Long

    • Converts the Long to a string written in the specified radix.

      参数

      • 可选radix: number

        Radix (2-36), defaults to 10

      返回 string

      RangeError If radix is out of range

    • Converts this Long to unsigned.

      返回 Long

    • Returns the bitwise XOR of this Long and the given one.

      参数

      • other: string | number | Long

      返回 Long

    • Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.

      参数

      • value: bigint

        The number in question

      • 可选unsigned: boolean

        Whether unsigned or not, defaults to signed

      返回 Long

      The corresponding Long value

    • Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is assumed to use 32 bits.

      参数

      • lowBits: number

        The low 32 bits

      • highBits: number

        The high 32 bits

      • 可选unsigned: boolean

        Whether unsigned or not, defaults to signed

      返回 Long

      The corresponding Long value

    • Creates a Long from its byte representation.

      参数

      • bytes: number[]

        Byte representation

      • 可选unsigned: boolean

        Whether unsigned or not, defaults to signed

      • 可选le: boolean

        Whether little or big endian, defaults to big endian

      返回 Long

      The corresponding Long value

    • Creates a Long from its big endian byte representation.

      参数

      • bytes: number[]

        Big endian byte representation

      • 可选unsigned: boolean

        Whether unsigned or not, defaults to signed

      返回 Long

      The corresponding Long value

    • Creates a Long from its little endian byte representation.

      参数

      • bytes: number[]

        Little endian byte representation

      • 可选unsigned: boolean

        Whether unsigned or not, defaults to signed

      返回 Long

      The corresponding Long value

    • 参数

      返回 number | bigint | Long

    • Returns a Long representing the given 32 bit integer value.

      参数

      • value: number

        The 32 bit integer in question

      • 可选unsigned: boolean

        Whether unsigned or not, defaults to signed

      返回 Long

      The corresponding Long value

    • Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.

      参数

      • value: number

        The number in question

      • 可选unsigned: boolean

        Whether unsigned or not, defaults to signed

      返回 Long

      The corresponding Long value

    • Returns a Long representation of the given string, written using the specified radix.

      参数

      • str: string

        The textual representation of the Long

      • 可选unsigned: boolean

        Whether unsigned or not, defaults to signed

      • 可选radix: number

        The radix in which the text is written (2-36), defaults to 10

      返回 Long

      The corresponding Long value

    • Converts the specified value to a Long.

      参数

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

        Whether unsigned or not, defaults to signed

      返回 Long

    • Tests if the specified object is a Long.

      参数

      • value: unknown

      返回 value is Long