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_值(-2^63),因为-MIN_VALUE == MIN_VALUE(因为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构造函数

constructor构造函数

  • 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位值和高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 longlong的低(有符号)32位

    • Optional high: number | boolean

      The high (signed) 32 bits of the longlong的高(有符号)32位

    • Optional unsigned: 无符号:boolean

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

    Returns返回Long

Properties属性

__isLong__

__isLong__: true

An indicator used to reliably determine if an object is a Long or not.一种指示器,用于可靠地确定对象是否为长对象。

_bsontype

_bsontype: "Long"

high

high: number

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

low

low: number

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

unsigned

unsigned: boolean

Whether unsigned or not.

Static MAX_UNSIGNED_VALUE

MAX_UNSIGNED_VALUE: Long

Maximum unsigned value.最大无符号值。

Static MAX_VALUE

MAX_VALUE: Long

Maximum signed value.最大有符号值。

Static MIN_VALUE

MIN_VALUE: Long

Minimum signed value.最小有符号值。

Static NEG_ONE

NEG_ONE: Long

Signed negative one.有符号-1。

Static ONE

ONE: Long

Signed one.有符号1。

Static TWO_PWR_24

TWO_PWR_24: Long

Static UONE

UONE: Long

Unsigned one.无符号1

Static UZERO

UZERO: Long

Unsigned zero.无符号0

Static ZERO

ZERO: Long

Signed zero有符号0

Methods方法

add

  • Returns the sum of this and the specified Long.返回此长度与指定长度的总和。

    Parameters参数

    Returns返回Long

and

  • Returns the sum of this and the specified Long.返回此长度与指定长度的总和。

    Parameters参数

    Returns返回Long

    Sum

comp

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

    Parameters参数

    Returns返回0 | 1 | -1

compare

  • 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;如果this更大,则为1;如果给定值更大,则为-1

div

  • This is an alias of Long.divide

    这是Long.divide的别名

    Parameters参数

    Returns返回Long

divide

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

    Parameters参数

    Returns返回Long

    Quotient

eq

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

    Parameters参数

    Returns返回boolean

equals

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

    Parameters参数

    • other: string | number | Long | Timestamp

      Other value其他价值

    Returns返回boolean

eqz

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

    Returns返回boolean

ge

getHighBits

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

    Returns返回number

getHighBitsUnsigned

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

    Returns返回number

getLowBits

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

    Returns返回number

getLowBitsUnsigned

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

    Returns返回number

getNumBitsAbs

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

    Returns返回number

greaterThan

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

    Parameters参数

    Returns返回boolean

greaterThanOrEqual

  • 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

gt

gte

inspect

  • inspect(): string
  • Returns返回string

isEven

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

    Returns返回boolean

isNegative

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

    Returns返回boolean

isOdd

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

    Returns返回boolean

isPositive

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

    Returns返回boolean

isZero

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

    Returns返回boolean

le

lessThan

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

    Parameters参数

    Returns返回boolean

lessThanOrEqual

  • 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

lt

  • This is an alias of {@link Long#lessThan}.这是{@link Long#lessThan}的别名。

    Parameters参数

    Returns返回boolean

lte

mod

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

    Parameters参数

    Returns返回Long

modulo

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

    Parameters参数

    Returns返回Long

mul

multiply

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

    Parameters参数

    Returns返回Long

    Product

ne

neg

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

    Returns返回Long

negate

  • Returns the Negation of this Long's value.返回此Long值的反运算。

    Returns返回Long

neq

not

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

    Returns返回Long

notEquals

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

    Parameters参数

    Returns返回boolean

or

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

    Parameters参数

    • other: string | number | Long

    Returns返回Long

rem

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

    Parameters参数

    Returns返回Long

shiftLeft

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

    Parameters参数

    • numBits: number | Long

      Number of bits

    Returns返回Long

    Shifted Long

shiftRight

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

    Parameters参数

    • numBits: number | Long

      Number of bits位数

    Returns返回Long

    Shifted Long

shiftRightUnsigned

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

    Parameters参数

    • numBits: number | Long

      Number of bits

    Returns返回Long

    Shifted Long

shl

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

    Parameters参数

    • numBits: number | Long

    Returns返回Long

shr

shr_u

shru

sub

subtract

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

    Parameters参数

    • subtrahend: string | number | Long | Timestamp

      Subtrahend减数

    Returns返回Long

    Difference差别

toBigInt

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

    Returns返回bigint

toBytes

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

    Parameters参数

    • Optional le: boolean

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

    Returns返回number[]

    Byte representation

toBytesBE

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

    Returns返回number[]

    Big endian byte representation大端字节表示法

toBytesLE

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

    Returns返回number[]

    Little endian byte representation小端字节表示法

toExtendedJSON

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

    • Optional options: Options

    Returns返回number | LongExtended

toInt

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

    Returns返回number

toNumber

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

    Returns返回number

toSigned

  • Converts this Long to signed.将此长度转换为已签名。

    Returns返回Long

toString

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

    throws

    RangeError If radix is out of range如果radix超出范围,则出现RangeError

    Parameters参数

    • Optional radix: number

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

    Returns返回string

toUnsigned

  • toUnsigned(): Long
  • Converts this Long to unsigned.将此长度转换为无符号。

    Returns返回Long

xor

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

    Parameters参数

    • other: string | number | Long

    Returns返回Long

Static fromBigInt

  • 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对应的长值

Static fromBits

  • 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对应的长值

Static fromBytes

  • 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对应的长值

Static fromBytesBE

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

    Parameters参数

    • bytes: number[]

      Big endian byte representation大端字节表示法

    • Optional unsigned: boolean

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

    Returns返回Long

    The corresponding Long value

Static fromBytesLE

  • 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对应的长值

Static fromExtendedJSON

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

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

    Returns返回number | Long

Static fromInt

  • 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对应的长值

Static fromNumber

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

    Parameters参数

    • value: number

      The number in question有问题的数字

    • Optional unsigned: boolean

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

    Returns返回Long

    The corresponding Long value对应的长值

Static fromString

  • 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对应的长值

Static fromValue

  • 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

Static isLong

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

    Parameters参数

    • value: any

    Returns返回value is Long

Generated using TypeDoc