Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/web_bson/src/long.ts>Long

web_bson is a fork from mongodb/js-bson
Very Popular
Go to Latest
class Long
import { Long } from "https://deno.land/x/web_bson@v0.2.5/src/long.ts";

A class representing a 64-bit integer

Constructors

new
Long(
low?: number | bigint | string,
high?: number | boolean,
unsigned?: boolean,
)

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?)

Properties

_bsontype: string
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.

Methods

add(addend:
| string
| number
| Long
): Long

Returns the sum of this and the specified Long.

and(other:
| string
| number
| Long
): Long

Returns the sum of this and the specified Long.

comp(other:
| string
| number
| Long
): 0 | 1 | -1

This is an alias of Long.compare

compare(other:
| string
| number
| Long
): 0 | 1 | -1

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

div(divisor:
| string
| number
| Long
): Long

This is an alias of Long.divide

divide(divisor:
| string
| number
| Long
): Long

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

eq(other:
| string
| number
| Long
): boolean

This is an alias of Long.equals

equals(other:
| string
| number
| Long
): boolean

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

eqz(): boolean

This is an alias of Long.isZero

ge(other:
| string
| number
| Long
): boolean

This is an alias of Long.greaterThanOrEqual

getHighBits(): number

Gets the high 32 bits as a signed integer.

Gets the high 32 bits as an unsigned integer.

getLowBits(): number

Gets the low 32 bits as a signed integer.

Gets the low 32 bits as an unsigned integer.

getNumBitsAbs(): number

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

greaterThan(other:
| string
| number
| Long
): boolean

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

greaterThanOrEqual(other:
| string
| number
| Long
): boolean

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

gt(other:
| string
| number
| Long
): boolean

This is an alias of Long.greaterThan

gte(other:
| string
| number
| Long
): boolean

This is an alias of Long.greaterThanOrEqual

isEven(): boolean

Tests if this Long's value is even.

isNegative(): boolean

Tests if this Long's value is negative.

isOdd(): boolean

Tests if this Long's value is odd.

isPositive(): boolean

Tests if this Long's value is positive.

isZero(): boolean

Tests if this Long's value equals zero.

le(other:
| string
| number
| Long
): boolean

This is an alias of Long.lessThanOrEqual

lessThan(other:
| string
| number
| Long
): boolean

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

lessThanOrEqual(other:
| string
| number
| Long
): boolean

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

lt(other:
| string
| number
| Long
): boolean

This is an alias of Long#lessThan.

lte(other:
| string
| number
| Long
): boolean

This is an alias of Long.lessThanOrEqual

mod(divisor:
| string
| number
| Long
): Long

This is an alias of Long.modulo

modulo(divisor:
| string
| number
| Long
): Long

Returns this Long modulo the specified.

mul(multiplier:
| string
| number
| Long
): Long

This is an alias of Long.multiply

multiply(multiplier:
| string
| number
| Long
): Long

Returns the product of this and the specified Long.

ne(other:
| string
| number
| Long
): boolean

This is an alias of Long.notEquals

This is an alias of Long.negate

Returns the Negation of this Long's value.

neq(other:
| string
| number
| Long
): boolean

This is an alias of Long.notEquals

Returns the bitwise NOT of this Long.

notEquals(other:
| string
| number
| Long
): boolean

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

or(other: number | string | Long): Long

Returns the bitwise OR of this Long and the specified.

rem(divisor:
| string
| number
| Long
): Long

This is an alias of Long.modulo

shiftLeft(numBits: number | Long): Long

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

shiftRight(numBits: number | Long): Long

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

shiftRightUnsigned(numBits: Long | number): Long

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

shl(numBits: number | Long): Long

This is an alias of Long.shiftLeft

shr(numBits: number | Long): Long

This is an alias of Long.shiftRight

shr_u(numBits: number | Long): Long

This is an alias of Long.shiftRightUnsigned

shru(numBits: number | Long): Long

This is an alias of Long.shiftRightUnsigned

sub(subtrahend:
| string
| number
| Long
): Long

This is an alias of Long.subtract

subtract(subtrahend:
| string
| number
| Long
): Long

Returns the difference of this and the specified Long.

toBigInt(): bigint

Converts the Long to a BigInt (arbitrary precision).

toBytes(le?: boolean): number[]

Converts this Long to its byte representation.

toBytesBE(): number[]

Converts this Long to its big endian byte representation.

toBytesLE(): number[]

Converts this Long to its little endian byte representation.

toInt(): number

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

toNumber(): number

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

Converts this Long to signed.

toString(radix?): string

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

Converts this Long to unsigned.

xor(other: Long | number | string): Long

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

Static Properties

MAX_UNSIGNED_VALUE

Maximum unsigned value.

MAX_VALUE

Maximum signed value.

MIN_VALUE

Minimum signed value.

NEG_ONE

Signed negative one.

ONE

Signed one.

TWO_PWR_24
UONE

Unsigned one.

UZERO

Unsigned zero.

ZERO

Signed zero

Static Methods

fromBigInt(value: bigint, unsigned?: boolean): Long

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

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. Each is assumed to use 32 bits.

fromBytes(
bytes: number[],
unsigned?: boolean,
le?: boolean,
): Long

Creates a Long from its byte representation.

fromBytesBE(bytes: number[], unsigned?: boolean): Long

Creates a Long from its big endian byte representation.

fromBytesLE(bytes: number[], unsigned?: boolean): Long

Creates a Long from its little endian byte representation.

fromExtendedJSON(doc: { $numberLong: string; }, options?: EJSONOptions): number | Long
fromInt(value: number, unsigned?: boolean): Long

Returns a Long representing the given 32 bit integer value.

fromNumber(value: number, unsigned?: boolean): Long

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

fromString(
str: string,
unsigned?: boolean,
radix?: number,
): Long

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

fromValue(val: number | string | { low: number; high: number; unsigned?: boolean; }, unsigned?: boolean): Long

Converts the specified value to a Long.

isLong(value: any): value is Long

Tests if the specified object is a Long.