@tevm/voltaire / primitives/Int256
primitives/Int256
Type Aliases
BrandedInt256
BrandedInt256 =Defined in: src/primitives/Int256/Int256Type.ts:9 Branded Int256 type (critical for EVM signed operations)bigint&object
Type Declaration
[brand]
readonly[brand]:"Int256"
See
https://voltaire.tevm.sh/primitives/int256 for Int256 documentationSince
0.0.0Variables
BITS
Defined in: src/primitives/Int256/constants.js:51 Size in bitsconstBITS:number=256
Int256
Defined in: src/primitives/Int256/index.ts:98constInt256:object
Type Declaration
abs()
abs: (Absolute value of Int256value) =>BrandedInt256
Parameters
value
BrandedInt256
Input value
Returns
BrandedInt256
Absolute value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If value is MIN (abs(MIN) overflows)Example
bitLength()
bitLength: (Get bit length of Int256 valuevalue) =>number
Parameters
value
BrandedInt256
Input value
Returns
number
Number of bits needed to represent value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
BITS
BITS: number
Size in bits
bitwiseAnd()
bitwiseAnd: (Bitwise AND of Int256 valuesa,b) =>BrandedInt256
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
BrandedInt256
Result
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
bitwiseNot()
bitwiseNot: (Bitwise NOT of Int256 valuevalue) =>BrandedInt256
Parameters
value
BrandedInt256
Input value
Returns
BrandedInt256
Result
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
bitwiseOr()
bitwiseOr: (Bitwise OR of Int256 valuesa,b) =>BrandedInt256
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
BrandedInt256
Result
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
bitwiseXor()
bitwiseXor: (Bitwise XOR of Int256 valuesa,b) =>BrandedInt256
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
BrandedInt256
Result
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
dividedBy()
dividedBy: (Divide Int256 values (EVM SDIV - signed division, truncate toward zero) EVM SDIV semantics:a,b) =>BrandedInt256
- Truncates toward zero (not floor division)
- -10 / 3 = -3 (not -4)
- MIN / -1 overflows (throws error)
- 0 / 0 throws error
Parameters
a
BrandedInt256
Dividend
b
BrandedInt256
Divisor
Returns
BrandedInt256
Quotient (truncated toward zero)
See
- https://voltaire.tevm.sh/primitives/int256 for Int256 documentation
- https://eips.ethereum.org/EIPS/eip-145 for EVM SDIV specification
Since
0.0.0Throws
If divisor is zero or MIN / -1 (overflow)Example
equals()
equals: (Check Int256 equalitya,b) =>boolean
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
boolean
True if equal
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
from()
from: (Create Int256 from bigint, number, or stringvalue) =>BrandedInt256
Parameters
value
bigint, number, or decimal/hex stringstring | number | bigint
Returns
BrandedInt256
Int256 value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If value is out of range or invalidExample
fromBigInt()
fromBigInt: (Create Int256 from bigintvalue) =>BrandedInt256
Parameters
value
bigint
BigInt value
Returns
BrandedInt256
Int256 value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If value is out of rangeExample
fromBytes()
fromBytes: (Create Int256 from bytes (two’s complement, big-endian)bytes) =>BrandedInt256
Parameters
bytes
Uint8Array<ArrayBufferLike>
Byte array (32 bytes)
Returns
BrandedInt256
Int256 value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If bytes length is incorrectExample
fromHex()
fromHex: (Create Int256 from hex string (two’s complement)hex) =>BrandedInt256
Parameters
hex
string
Hex string (with or without 0x prefix)
Returns
BrandedInt256
Int256 value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If hex is invalid or out of rangeExample
fromNumber()
fromNumber: (Create Int256 from numbervalue) =>BrandedInt256
Parameters
value
number
Integer number
Returns
BrandedInt256
Int256 value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If value is not an integer or out of rangeExample
greaterThan()
greaterThan: (Check if Int256 is greater than anothera,b) =>boolean
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
boolean
True if a > b
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
isNegative()
isNegative: (Check if Int256 is negativevalue) =>boolean
Parameters
value
BrandedInt256
Input value
Returns
boolean
True if negative
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
isPositive()
isPositive: (Check if Int256 is positivevalue) =>boolean
Parameters
value
BrandedInt256
Input value
Returns
boolean
True if positive
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
isValid()
isValid: (Check if value is valid Int256value) =>boolean
Parameters
value
bigint
Value to check
Returns
boolean
True if valid Int256
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
isZero()
isZero: (Check if Int256 is zerovalue) =>boolean
Parameters
value
BrandedInt256
Input value
Returns
boolean
True if zero
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
leadingZeros()
leadingZeros: (Count leading zeros in Int256 two’s complement representationvalue) =>number
Parameters
value
BrandedInt256
Input value
Returns
number
Number of leading zero bits
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
lessThan()
lessThan: (Check if Int256 is less than anothera,b) =>boolean
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
boolean
True if a < b
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
MAX
MAX: bigint
Maximum Int256 value: 2^255 - 1
EVM: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
maximum()
maximum: (Return maximum of two Int256 valuesa,b) =>BrandedInt256
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
BrandedInt256
Maximum value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
MIN
MIN: bigint
Minimum Int256 value: -2^255
EVM: 0x8000000000000000000000000000000000000000000000000000000000000000
minimum()
minimum: (Return minimum of two Int256 valuesa,b) =>BrandedInt256
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
BrandedInt256
Minimum value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
minus()
minus: (Subtract Int256 values with wrapping (EVM SUB with signed interpretation)a,b) =>BrandedInt256
Parameters
a
BrandedInt256
Minuend
b
BrandedInt256
Subtrahend
Returns
BrandedInt256
Difference with wrapping
See
https://voltaire.tevm.sh/primitives/int256 for Int256 documentationSince
0.0.0Example
modulo()
modulo: (Modulo Int256 values (EVM SMOD - signed modulo, sign follows dividend) EVM SMOD semantics:a,b) =>BrandedInt256
- Sign of result follows dividend (first operand)
- -10 % 3 = -1 (not 2)
- 10 % -3 = 1 (not -2)
- Property: a = (a/b)*b + (a%b)
Parameters
a
BrandedInt256
Dividend
b
BrandedInt256
Divisor
Returns
BrandedInt256
Remainder (sign follows dividend)
See
- https://voltaire.tevm.sh/primitives/int256 for Int256 documentation
- https://eips.ethereum.org/EIPS/eip-145 for EVM SMOD specification
Since
0.0.0Throws
If divisor is zeroExample
MODULO
MODULO: bigint
Modulo value for wrapping: 2^256
NEG_ONE
NEG_ONE: bigint
Negative one value (-1 in two’s complement)
EVM: 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
negate()
negate: (Negate Int256 value with wrappingvalue) =>BrandedInt256
Parameters
value
BrandedInt256
Input value
Returns
BrandedInt256
Negated value with wrapping
See
https://voltaire.tevm.sh/primitives/int256 for Int256 documentationSince
0.0.0Example
ONE
ONE: bigint
One value
plus()
plus: (Add Int256 values with wrapping (EVM ADD with signed interpretation)a,b) =>BrandedInt256
Parameters
a
BrandedInt256
First operand
b
BrandedInt256
Second operand
Returns
BrandedInt256
Sum with wrapping
See
https://voltaire.tevm.sh/primitives/int256 for Int256 documentationSince
0.0.0Example
popCount()
popCount: (Count set bits in Int256 two’s complement representationvalue) =>number
Parameters
value
BrandedInt256
Input value
Returns
number
Number of set bits
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
shiftLeft()
shiftLeft: (Shift Int256 left with wrappingvalue,shift) =>BrandedInt256
Parameters
value
BrandedInt256
Value to shift
shift
Shift amountnumber | bigint
Returns
BrandedInt256
Shifted value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
shiftRight()
shiftRight: (Arithmetic right shift of Int256 (EVM SAR - sign-preserving) EVM SAR semantics:value,shift) =>BrandedInt256
- Preserves sign bit during shift
- Negative values remain negative
- -256 >> 1 = -128 (not 128)
- Equivalent to division by 2^shift with floor toward negative infinity
Parameters
value
BrandedInt256
Value to shift
shift
Shift amountnumber | bigint
Returns
BrandedInt256
Shifted value (sign-extended)
See
- https://voltaire.tevm.sh/primitives/int256 for Int256 documentation
- https://eips.ethereum.org/EIPS/eip-145 for EVM SAR specification
Since
0.0.0Example
sign()
sign: (Get sign of Int256 valuevalue) =>-1|0|1
Parameters
value
BrandedInt256
Input value
Returns
-1 | 0 | 1
-1 for negative, 0 for zero, 1 for positive
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
SIZE
SIZE: number
Size in bytes
times()
times: (Multiply Int256 values with wrapping (EVM MUL with signed interpretation)a,b) =>BrandedInt256
Parameters
a
BrandedInt256
First operand
b
BrandedInt256
Second operand
Returns
BrandedInt256
Product with wrapping
See
https://voltaire.tevm.sh/primitives/int256 for Int256 documentationSince
0.0.0Example
toBigInt()
toBigInt: (Convert Int256 to bigintvalue) =>bigint
Parameters
value
BrandedInt256
Int256 value
Returns
bigint
BigInt value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
toBytes()
toBytes: (Convert Int256 to bytes (two’s complement, big-endian)value) =>Uint8Array<ArrayBufferLike>
Parameters
value
BrandedInt256
Int256 value
Returns
Uint8Array<ArrayBufferLike>
Byte array (32 bytes)
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
toHex()
toHex: (Convert Int256 to hex string (two’s complement)value) =>string
Parameters
value
BrandedInt256
Int256 value
Returns
string
Hex string with 0x prefix
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
toNumber()
toNumber: (Convert Int256 to number (warns on overflow)value) =>number
Parameters
value
BrandedInt256
Int256 value
Returns
number
Number value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If value exceeds Number.MAX_SAFE_INTEGER or Number.MIN_SAFE_INTEGERExample
toString()
toString: (Convert Int256 to decimal stringvalue) =>string
Parameters
value
BrandedInt256
Int256 value
Returns
string
Decimal string
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
ZERO
ZERO: bigint
Zero value
MAX
Defined in: src/primitives/Int256/constants.js:20 Maximum Int256 value: 2^255 - 1 EVM: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffconstMAX:bigint
MIN
Defined in: src/primitives/Int256/constants.js:13 Minimum Int256 value: -2^255 EVM: 0x8000000000000000000000000000000000000000000000000000000000000000constMIN:bigint
MODULO
Defined in: src/primitives/Int256/constants.js:57 Modulo value for wrapping: 2^256constMODULO:bigint
NEG_ONE
Defined in: src/primitives/Int256/constants.js:39 Negative one value (-1 in two’s complement) EVM: 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffconstNEG_ONE:bigint=-1n
ONE
Defined in: src/primitives/Int256/constants.js:32 One valueconstONE:bigint=1n
SIZE
Defined in: src/primitives/Int256/constants.js:45 Size in bytesconstSIZE:number=32
ZERO
Defined in: src/primitives/Int256/constants.js:26 Zero valueconstZERO:bigint=0n
Functions
abs()
abs(Defined in: src/primitives/Int256/abs.js:18 Absolute value of Int256value):BrandedInt256
Parameters
value
BrandedInt256
Input value
Returns
BrandedInt256
Absolute value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If value is MIN (abs(MIN) overflows)Example
bitLength()
bitLength(Defined in: src/primitives/Int256/bitLength.js:17 Get bit length of Int256 valuevalue):number
Parameters
value
BrandedInt256
Input value
Returns
number
Number of bits needed to represent value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
bitwiseAnd()
bitwiseAnd(Defined in: src/primitives/Int256/bitwiseAnd.js:19 Bitwise AND of Int256 valuesa,b):BrandedInt256
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
BrandedInt256
Result
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
bitwiseNot()
bitwiseNot(Defined in: src/primitives/Int256/bitwiseNot.js:17 Bitwise NOT of Int256 valuevalue):BrandedInt256
Parameters
value
BrandedInt256
Input value
Returns
BrandedInt256
Result
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
bitwiseOr()
bitwiseOr(Defined in: src/primitives/Int256/bitwiseOr.js:19 Bitwise OR of Int256 valuesa,b):BrandedInt256
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
BrandedInt256
Result
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
bitwiseXor()
bitwiseXor(Defined in: src/primitives/Int256/bitwiseXor.js:19 Bitwise XOR of Int256 valuesa,b):BrandedInt256
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
BrandedInt256
Result
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
dividedBy()
dividedBy(Defined in: src/primitives/Int256/dividedBy.js:32 Divide Int256 values (EVM SDIV - signed division, truncate toward zero) EVM SDIV semantics:a,b):BrandedInt256
- Truncates toward zero (not floor division)
- -10 / 3 = -3 (not -4)
- MIN / -1 overflows (throws error)
- 0 / 0 throws error
Parameters
a
BrandedInt256
Dividend
b
BrandedInt256
Divisor
Returns
BrandedInt256
Quotient (truncated toward zero)
See
- https://voltaire.tevm.sh/primitives/int256 for Int256 documentation
- https://eips.ethereum.org/EIPS/eip-145 for EVM SDIV specification
Since
0.0.0Throws
If divisor is zero or MIN / -1 (overflow)Example
equals()
equals(Defined in: src/primitives/Int256/equals.js:17 Check Int256 equalitya,b):boolean
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
boolean
True if equal
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
from()
from(Defined in: src/primitives/Int256/from.js:20 Create Int256 from bigint, number, or stringvalue):BrandedInt256
Parameters
value
bigint, number, or decimal/hex stringstring | number | bigint
Returns
BrandedInt256
Int256 value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If value is out of range or invalidExample
fromBigInt()
fromBigInt(Defined in: src/primitives/Int256/fromBigInt.js:18 Create Int256 from bigintvalue):BrandedInt256
Parameters
value
bigint
BigInt value
Returns
BrandedInt256
Int256 value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If value is out of rangeExample
fromBytes()
fromBytes(Defined in: src/primitives/Int256/fromBytes.js:19 Create Int256 from bytes (two’s complement, big-endian)bytes):BrandedInt256
Parameters
bytes
Uint8Array<ArrayBufferLike>
Byte array (32 bytes)
Returns
BrandedInt256
Int256 value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If bytes length is incorrectExample
fromHex()
fromHex(Defined in: src/primitives/Int256/fromHex.js:19 Create Int256 from hex string (two’s complement)hex):BrandedInt256
Parameters
hex
string
Hex string (with or without 0x prefix)
Returns
BrandedInt256
Int256 value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If hex is invalid or out of rangeExample
fromNumber()
fromNumber(Defined in: src/primitives/Int256/fromNumber.js:18 Create Int256 from numbervalue):BrandedInt256
Parameters
value
number
Integer number
Returns
BrandedInt256
Int256 value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If value is not an integer or out of rangeExample
greaterThan()
greaterThan(Defined in: src/primitives/Int256/greaterThan.js:17 Check if Int256 is greater than anothera,b):boolean
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
boolean
True if a > b
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
isNegative()
isNegative(Defined in: src/primitives/Int256/isNegative.js:15 Check if Int256 is negativevalue):boolean
Parameters
value
BrandedInt256
Input value
Returns
boolean
True if negative
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
isPositive()
isPositive(Defined in: src/primitives/Int256/isPositive.js:15 Check if Int256 is positivevalue):boolean
Parameters
value
BrandedInt256
Input value
Returns
boolean
True if positive
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
isValid()
isValid(Defined in: src/primitives/Int256/isValid.js:17 Check if value is valid Int256value):boolean
Parameters
value
bigint
Value to check
Returns
boolean
True if valid Int256
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
isZero()
isZero(Defined in: src/primitives/Int256/isZero.js:15 Check if Int256 is zerovalue):boolean
Parameters
value
BrandedInt256
Input value
Returns
boolean
True if zero
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
leadingZeros()
leadingZeros(Defined in: src/primitives/Int256/leadingZeros.js:17 Count leading zeros in Int256 two’s complement representationvalue):number
Parameters
value
BrandedInt256
Input value
Returns
number
Number of leading zero bits
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
lessThan()
lessThan(Defined in: src/primitives/Int256/lessThan.js:17 Check if Int256 is less than anothera,b):boolean
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
boolean
True if a < b
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
maximum()
maximum(Defined in: src/primitives/Int256/maximum.js:17 Return maximum of two Int256 valuesa,b):BrandedInt256
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
BrandedInt256
Maximum value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
minimum()
minimum(Defined in: src/primitives/Int256/minimum.js:17 Return minimum of two Int256 valuesa,b):BrandedInt256
Parameters
a
BrandedInt256
First value
b
BrandedInt256
Second value
Returns
BrandedInt256
Minimum value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
minus()
minus(Defined in: src/primitives/Int256/minus.js:19 Subtract Int256 values with wrapping (EVM SUB with signed interpretation)a,b):BrandedInt256
Parameters
a
BrandedInt256
Minuend
b
BrandedInt256
Subtrahend
Returns
BrandedInt256
Difference with wrapping
See
https://voltaire.tevm.sh/primitives/int256 for Int256 documentationSince
0.0.0Example
modulo()
modulo(Defined in: src/primitives/Int256/modulo.js:30 Modulo Int256 values (EVM SMOD - signed modulo, sign follows dividend) EVM SMOD semantics:a,b):BrandedInt256
- Sign of result follows dividend (first operand)
- -10 % 3 = -1 (not 2)
- 10 % -3 = 1 (not -2)
- Property: a = (a/b)*b + (a%b)
Parameters
a
BrandedInt256
Dividend
b
BrandedInt256
Divisor
Returns
BrandedInt256
Remainder (sign follows dividend)
See
- https://voltaire.tevm.sh/primitives/int256 for Int256 documentation
- https://eips.ethereum.org/EIPS/eip-145 for EVM SMOD specification
Since
0.0.0Throws
If divisor is zeroExample
negate()
negate(Defined in: src/primitives/Int256/negate.js:19 Negate Int256 value with wrappingvalue):BrandedInt256
Parameters
value
BrandedInt256
Input value
Returns
BrandedInt256
Negated value with wrapping
See
https://voltaire.tevm.sh/primitives/int256 for Int256 documentationSince
0.0.0Example
plus()
plus(Defined in: src/primitives/Int256/plus.js:19 Add Int256 values with wrapping (EVM ADD with signed interpretation)a,b):BrandedInt256
Parameters
a
BrandedInt256
First operand
b
BrandedInt256
Second operand
Returns
BrandedInt256
Sum with wrapping
See
https://voltaire.tevm.sh/primitives/int256 for Int256 documentationSince
0.0.0Example
popCount()
popCount(Defined in: src/primitives/Int256/popCount.js:17 Count set bits in Int256 two’s complement representationvalue):number
Parameters
value
BrandedInt256
Input value
Returns
number
Number of set bits
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
shiftLeft()
shiftLeft(Defined in: src/primitives/Int256/shiftLeft.js:18 Shift Int256 left with wrappingvalue,shift):BrandedInt256
Parameters
value
BrandedInt256
Value to shift
shift
Shift amountnumber | bigint
Returns
BrandedInt256
Shifted value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
shiftRight()
shiftRight(Defined in: src/primitives/Int256/shiftRight.js:29 Arithmetic right shift of Int256 (EVM SAR - sign-preserving) EVM SAR semantics:value,shift):BrandedInt256
- Preserves sign bit during shift
- Negative values remain negative
- -256 >> 1 = -128 (not 128)
- Equivalent to division by 2^shift with floor toward negative infinity
Parameters
value
BrandedInt256
Value to shift
shift
Shift amountnumber | bigint
Returns
BrandedInt256
Shifted value (sign-extended)
See
- https://voltaire.tevm.sh/primitives/int256 for Int256 documentation
- https://eips.ethereum.org/EIPS/eip-145 for EVM SAR specification
Since
0.0.0Example
sign()
sign(Defined in: src/primitives/Int256/sign.js:19 Get sign of Int256 valuevalue):-1|0|1
Parameters
value
BrandedInt256
Input value
Returns
-1 | 0 | 1
-1 for negative, 0 for zero, 1 for positive
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
times()
times(Defined in: src/primitives/Int256/times.js:19 Multiply Int256 values with wrapping (EVM MUL with signed interpretation)a,b):BrandedInt256
Parameters
a
BrandedInt256
First operand
b
BrandedInt256
Second operand
Returns
BrandedInt256
Product with wrapping
See
https://voltaire.tevm.sh/primitives/int256 for Int256 documentationSince
0.0.0Example
toBigInt()
toBigInt(Defined in: src/primitives/Int256/toBigInt.js:15 Convert Int256 to bigintvalue):bigint
Parameters
value
BrandedInt256
Int256 value
Returns
bigint
BigInt value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
toBytes()
toBytes(Defined in: src/primitives/Int256/toBytes.js:17 Convert Int256 to bytes (two’s complement, big-endian)value):Uint8Array<ArrayBufferLike>
Parameters
value
BrandedInt256
Int256 value
Returns
Uint8Array<ArrayBufferLike>
Byte array (32 bytes)
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
toHex()
toHex(Defined in: src/primitives/Int256/toHex.js:19 Convert Int256 to hex string (two’s complement)value):string
Parameters
value
BrandedInt256
Int256 value
Returns
string
Hex string with 0x prefix
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Example
toNumber()
toNumber(Defined in: src/primitives/Int256/toNumber.js:16 Convert Int256 to number (warns on overflow)value):number
Parameters
value
BrandedInt256
Int256 value
Returns
number
Number value
See
https://voltaire.tevm.sh/primitives/int128 for Int256 documentationSince
0.0.0Throws
If value exceeds Number.MAX_SAFE_INTEGER or Number.MIN_SAFE_INTEGERExample
toString()
toString(Defined in: src/primitives/Int256/toString.js:16 Convert Int256 to decimal stringvalue):string
Parameters
value
BrandedInt256
Int256 value
Returns
string
Decimal string

