Class: Int64

Int64

Holds a 64-bit integer.

Constructor

new Int64()

Javascript Numbers are IEEE-754 binary double-precision floats, which limits the range of values that can be represented with integer precision to:
-(2^53) <= N <= 2^53
Int64 objects wrap a node Buffer that holds the 8-bytes of int64 data. These objects operate directly on the buffer which means that if they are created using an existing buffer then setting the value will modify the Buffer, and vice-versa.

Internal Representation

The internal buffer byte order is big-endian (i.e. the most-significant byte is at buffer[offset+0], the least significant at buffer[offset+7]). For the purposes of converting to/from Javascript native numbers, the value is assumed to be a signed integer stored in 2's complement form.

For details about IEEE-754 see: Double-precision floating-point format Constructor accepts any of the following argument types:

new Int64(buffer[, offset=0])  Buffer, with byte offset, holding 64-bit, big-endian encoded integer
new Int64(Uint8Array[, offset=0])  Uint8Array, with byte offset, holding 64-bit, big-endian encoded integer
new Int64(string)  Hex string (throws if n is outside int64 range)
new Int64(number)  Number (throws if n is outside int64 range)
new Int64(high, low)  Raw bits as two 32-bit values
Source:

Members

buffer :Buffer

Holds 8 byte integer in big-endian order.
Type:
  • Buffer
Source:

offset :Number

Offset within buffer of beginning of integer bytes.
Type:
  • Number
Source:

(static, constant) MAX_INT :Number

Maximum integer value that JS can accurately represent (2^52).
Type:
  • Number
Source:

(static, constant) MIN_INT :Number

Maximum integer value that JS can accurately represent -(2^52).
Type:
  • Number
Source:

Methods

_2scomp()

Performs in-place two's compliment of 8 byte number stored in buffer, starting at offset. See Two's complement.
Source:

copy(targetBuffer, targetOffsetopt)

Copy 8 bytes of int64 into target buffer at target offset.
Parameters:
Name Type Attributes Default Description
targetBuffer Buffer Buffer to copy into.
targetOffset number <optional>
0 Offset into target buffer.
Source:

inspect() → {String}

Returns a string represenation of the Int64 object.
[Int64 value:1006414150992247 octets:00 03 93 54 0d f7 81 77]
Source:
Returns:
String representation of object
Type
String

setValue()

Sets the integer value. Takes any of the following arguments:

setValue(string) - A hexidecimal string
setValue(number) - Number (throws if n is outside int64 range)
setValue(high, low) - Raw bits as two 32-bit values
Source:

toBuffer(rawBufferopt)

Returns newly allocated Buffer holding integer encoded as 8 bytes in big-endian order.
Parameters:
Name Type Attributes Default Description
rawBuffer bool <optional>
false If no offset and this is true, return the internal buffer. Should only be used if you're discarding the Int64 afterwards, as it breaks encapsulation.
Source:

toNumber(allowImprecise) → {Number}

Convert to a native Javascript number.

WARNING: Do not expect this value to be accurate to integer precision for large (positive or negative) numbers!

Parameters:
Name Type Description
allowImprecise Boolean If true, no check is performed to verify the returned value is accurate to integer precision. If false, imprecise numbers (very large positive or negative numbers) will be forced to +/-Infinity.
Source:
Returns:
Javascript number representing the integer, or +/-Infinity if not enough precision available and allowImprecise is set to true.
Type
Number

toOctetString(sep)

Return a string showing the buffer octets, with MSB on the left.
Parameters:
Name Type Description
sep String Separator string. default is '' (empty string)
Source:

toString(radixopt)

Return string representation of integer. Conversion is performed with valueOf().toString(radix).
Parameters:
Name Type Attributes Default Description
radix Number <optional>
10 Just like Number.toString() radix
Source:

valueOf() → {Number}

Convert to a Javascript Number. Does the conversion with a call to toNumber(false).
Source:
See:
Returns:
Javascript number representing the integer, or +/-Infinity if not enough precision to hold the integer.
Type
Number