Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/Int64

primitives/Int64

Type Aliases

BrandedInt64

BrandedInt64 = bigint & object
Defined in: src/primitives/Int64/Int64Type.ts:25 A signed 64-bit integer branded type. Internally a JavaScript bigint constrained to [-2^63, 2^63-1].

Type Declaration

[brand]
readonly [brand]: "Int64"

Variables

INT64_MAX

const INT64_MAX: 9223372036854775807n = 9223372036854775807n
Defined in: src/primitives/Int64/Int64Type.ts:30

INT64_MIN

const INT64_MIN: -9223372036854775808n = -9223372036854775808n
Defined in: src/primitives/Int64/Int64Type.ts:29

MAX

const MAX: 9223372036854775807n
Defined in: src/primitives/Int64/constants.js:11

MIN

const MIN: -9223372036854775808n
Defined in: src/primitives/Int64/constants.js:8

MINUS_ONE

const MINUS_ONE: -1n
Defined in: src/primitives/Int64/constants.js:20

ONE

const ONE: 1n
Defined in: src/primitives/Int64/constants.js:17

SIZE

const SIZE: 8 = 8
Defined in: src/primitives/Int64/constants.js:23

ZERO

const ZERO: 0n
Defined in: src/primitives/Int64/constants.js:14

Functions

abs()

abs(value): BrandedInt64
Defined in: src/primitives/Int64/abs.js:8 Get absolute value of Int64

Parameters

value
BrandedInt64 Value

Returns

BrandedInt64 Absolute value

Throws

If value is MIN (abs would overflow)

bitwiseAnd()

bitwiseAnd(a, b): BrandedInt64
Defined in: src/primitives/Int64/bitwiseAnd.js:8 Bitwise AND of two Int64 values

Parameters

a
BrandedInt64 First value
b
BrandedInt64 Second value

Returns

BrandedInt64 Result

bitwiseNot()

bitwiseNot(value): BrandedInt64
Defined in: src/primitives/Int64/bitwiseNot.js:7 Bitwise NOT of Int64 value

Parameters

value
BrandedInt64 Value

Returns

BrandedInt64 Result

bitwiseOr()

bitwiseOr(a, b): BrandedInt64
Defined in: src/primitives/Int64/bitwiseOr.js:8 Bitwise OR of two Int64 values

Parameters

a
BrandedInt64 First value
b
BrandedInt64 Second value

Returns

BrandedInt64 Result

bitwiseXor()

bitwiseXor(a, b): BrandedInt64
Defined in: src/primitives/Int64/bitwiseXor.js:8 Bitwise XOR of two Int64 values

Parameters

a
BrandedInt64 First value
b
BrandedInt64 Second value

Returns

BrandedInt64 Result

clone()

clone(value): BrandedInt64
Defined in: src/primitives/Int64/clone.js:7 Clone Int64 value

Parameters

value
BrandedInt64 Value to clone

Returns

BrandedInt64 Cloned value

dividedBy()

dividedBy(a, b): BrandedInt64
Defined in: src/primitives/Int64/dividedBy.js:9 Divide two Int64 values (truncates toward zero)

Parameters

a
BrandedInt64 Dividend
b
BrandedInt64 Divisor

Returns

BrandedInt64 Quotient

Throws

If divisor is zero or overflow occurs

equals()

equals(a, b): boolean
Defined in: src/primitives/Int64/equals.js:8 Check if two Int64 values are equal

Parameters

a
BrandedInt64 First value
b
BrandedInt64 Second value

Returns

boolean True if equal

from()

from(value): BrandedInt64
Defined in: src/primitives/Int64/from.js:15 Create Int64 from various input types

Parameters

value
Value to convert string | number | bigint

Returns

BrandedInt64 Int64 value

Throws

If value is out of range

Example

import * as Int64 from './primitives/Int64/index.js';
const a = Int64.from(-42n);
const b = Int64.from("123");
const c = Int64.from(42);

fromBigInt()

fromBigInt(value): BrandedInt64
Defined in: src/primitives/Int64/fromBigInt.js:8 Create Int64 from bigint

Parameters

value
bigint BigInt to convert

Returns

BrandedInt64 Int64 value

Throws

If value is out of range

fromBytes()

fromBytes(bytes): BrandedInt64
Defined in: src/primitives/Int64/fromBytes.js:8 Create Int64 from bytes (big-endian, two’s complement)

Parameters

bytes
Uint8Array<ArrayBufferLike> Bytes to convert (up to 8 bytes)

Returns

BrandedInt64 Int64 value

Throws

If bytes length exceeds 8

fromHex()

fromHex(hex): BrandedInt64
Defined in: src/primitives/Int64/fromHex.js:8 Create Int64 from hex string (two’s complement)

Parameters

hex
string Hex string (with or without 0x prefix)

Returns

BrandedInt64 Int64 value

Throws

If hex is invalid or exceeds 8 bytes

fromNumber()

fromNumber(value): BrandedInt64
Defined in: src/primitives/Int64/fromNumber.js:8 Create Int64 from number

Parameters

value
number Number to convert

Returns

BrandedInt64 Int64 value

Throws

If value is out of range or NaN

greaterThan()

greaterThan(a, b): boolean
Defined in: src/primitives/Int64/greaterThan.js:8 Check if first Int64 is greater than second

Parameters

a
BrandedInt64 First value
b
BrandedInt64 Second value

Returns

boolean True if a > b

isNegative()

isNegative(value): boolean
Defined in: src/primitives/Int64/isNegative.js:7 Check if Int64 value is negative

Parameters

value
BrandedInt64 Value

Returns

boolean True if negative

isPositive()

isPositive(value): boolean
Defined in: src/primitives/Int64/isPositive.js:7 Check if Int64 value is positive

Parameters

value
BrandedInt64 Value

Returns

boolean True if positive

isValid()

isValid(value): boolean
Defined in: src/primitives/Int64/isValid.js:7 Check if value is a valid Int64

Parameters

value
unknown Value to check

Returns

boolean True if valid Int64

isZero()

isZero(value): boolean
Defined in: src/primitives/Int64/isZero.js:7 Check if Int64 value is zero

Parameters

value
BrandedInt64 Value

Returns

boolean True if zero

lessThan()

lessThan(a, b): boolean
Defined in: src/primitives/Int64/lessThan.js:8 Check if first Int64 is less than second

Parameters

a
BrandedInt64 First value
b
BrandedInt64 Second value

Returns

boolean True if a < b

maximum()

maximum(a, b): BrandedInt64
Defined in: src/primitives/Int64/maximum.js:8 Get maximum of two Int64 values

Parameters

a
BrandedInt64 First value
b
BrandedInt64 Second value

Returns

BrandedInt64 Maximum value

minimum()

minimum(a, b): BrandedInt64
Defined in: src/primitives/Int64/minimum.js:8 Get minimum of two Int64 values

Parameters

a
BrandedInt64 First value
b
BrandedInt64 Second value

Returns

BrandedInt64 Minimum value

minus()

minus(a, b): BrandedInt64
Defined in: src/primitives/Int64/minus.js:9 Subtract two Int64 values

Parameters

a
BrandedInt64 First value
b
BrandedInt64 Second value

Returns

BrandedInt64 Result

Throws

If result overflows

modulo()

modulo(a, b): BrandedInt64
Defined in: src/primitives/Int64/modulo.js:9 Compute modulo of two Int64 values

Parameters

a
BrandedInt64 Dividend
b
BrandedInt64 Divisor

Returns

BrandedInt64 Remainder

Throws

If divisor is zero

negate()

negate(value): BrandedInt64
Defined in: src/primitives/Int64/negate.js:8 Negate Int64 value

Parameters

value
BrandedInt64 Value

Returns

BrandedInt64 Negated value

Throws

If value is MIN (negation would overflow)

plus()

plus(a, b): BrandedInt64
Defined in: src/primitives/Int64/plus.js:9 Add two Int64 values

Parameters

a
BrandedInt64 First value
b
BrandedInt64 Second value

Returns

BrandedInt64 Result

Throws

If result overflows

shiftLeft()

shiftLeft(value, n): BrandedInt64
Defined in: src/primitives/Int64/shiftLeft.js:8 Shift Int64 left by n bits

Parameters

value
BrandedInt64 Value to shift
n
bigint Number of bits to shift

Returns

BrandedInt64 Result

shiftRight()

shiftRight(value, n): BrandedInt64
Defined in: src/primitives/Int64/shiftRight.js:8 Arithmetic shift Int64 right by n bits (preserves sign)

Parameters

value
BrandedInt64 Value to shift
n
bigint Number of bits to shift

Returns

BrandedInt64 Result

sign()

sign(value): -1 | 0 | 1
Defined in: src/primitives/Int64/sign.js:7 Get sign of Int64 value

Parameters

value
BrandedInt64 Value

Returns

-1 | 0 | 1 -1 if negative, 0 if zero, 1 if positive

times()

times(a, b): BrandedInt64
Defined in: src/primitives/Int64/times.js:9 Multiply two Int64 values

Parameters

a
BrandedInt64 First value
b
BrandedInt64 Second value

Returns

BrandedInt64 Result

Throws

If result overflows

toBigInt()

toBigInt(value): bigint
Defined in: src/primitives/Int64/toBigInt.js:7 Convert Int64 to bigint

Parameters

value
BrandedInt64 Int64 value

Returns

bigint BigInt value

toBytes()

toBytes(value): Uint8Array<ArrayBufferLike>
Defined in: src/primitives/Int64/toBytes.js:7 Convert Int64 to bytes (big-endian, two’s complement, 8 bytes)

Parameters

value
BrandedInt64 Int64 value

Returns

Uint8Array<ArrayBufferLike> 8-byte Uint8Array

toHex()

toHex(value): string
Defined in: src/primitives/Int64/toHex.js:7 Convert Int64 to hex string (two’s complement)

Parameters

value
BrandedInt64 Int64 value

Returns

string Hex string with 0x prefix

toNumber()

toNumber(value): number
Defined in: src/primitives/Int64/toNumber.js:8 Convert Int64 to number

Parameters

value
BrandedInt64 Int64 value

Returns

number Number value

Throws

If value exceeds safe integer range

toString()

toString(value): string
Defined in: src/primitives/Int64/toString.js:8 Convert Int64 to string

Parameters

value
BrandedInt64 Int64 value

Returns

string String representation