Int128 class

Implemented types

Constructors

Int128(int value)
Builds from a plain Dart int (positive or negative).
factory
Int128.fromBigInt(BigInt value)
Builds from an arbitrary signed BigInt, truncating to 128 bits like a wrapping cast. BigInt.toUnsigned gives the exact two's-complement bit pattern directly, so this is correct for any magnitude.
factory
Int128.unsafe(Uint128 bits)
Raw bit-pattern constructor for an already-computed two's-complement Uint128 pattern. Prefer Int128.new or Int128.fromBigInt otherwise.
const

Properties

hashCode int
The hash code for this object.
no setteroverride
isEven bool
no setter
isNegative bool
no setter
isZero bool
no setter
rawBits Uint128
Raw two's-complement bit pattern as a Uint128.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

abs() Int128
addChecked(Int128 other) Int128
compareTo(Int128 other) int
Flips the top bit on both operands, which turns two's-complement ordering into plain unsigned ordering — then delegates to Uint128.compareTo.
override
mulChecked(Int128 other) Int128
Detects overflow via round-trip: wrap-multiply then divide back out. Detects overflow via round-trip: wrap-multiply then divide back out.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
subChecked(Int128 other) Int128
-other wraps back to Int128.min itself when other == Int128.min (no positive counterpart in two's complement), so that case can't go through addChecked(-other) like every other value can. this - Int128.min only fits the signed range when this is negative, in which case the plain wrapping subtract is already exact.
toBigInt() BigInt
toBytes([Endian endian = Endian.big]) List<int>
Fixed 16-byte two's-complement encoding — identical bit-for-bit to Uint128.toBytes, so this just delegates.
toHexString({bool padded = true}) String
toInt() int
Safe only if the magnitude fits in a double-safe int — delegates to Uint128.toInt()'s own guard, so it throws IntegerError otherwise (use toBigInt for the general case).
toInt128() Int128
Same-width reinterpretation.
toInt32() Int32
Signed narrowing to Int32.
toInt64() Int64
Signed narrowing to Int64.
toString() String
A string representation of this object.
override
toUint128() Uint128
Same-width bit reinterpretation.
toUint256() Uint256
Zero/sign extending cast to 256 bits.
toUint32() Uint32
Truncating cast, keeps the low 32 bits.
toUint64() Uint64
Truncating cast, keeps the low 64 bits.
unsignedShiftRight(int n) Int128
Logical (unsigned) right shift — top bits filled with zero regardless of sign.

Operators

operator %(Int128 other) Int128
Truncating remainder (same sign as the dividend), consistent with operator ~/ above.
operator &(Int128 other) Int128
operator *(Int128 other) Int128
operator +(Int128 other) Int128
operator -(Int128 other) Int128
operator <(Int128 other) bool
operator <<(int n) Int128
Logical left shift — identical for signed and unsigned, delegates to Uint128.
operator <=(Int128 other) bool
operator ==(Object other) bool
The equality operator.
override
operator >(Int128 other) bool
operator >=(Int128 other) bool
operator >>(int n) Int128
Arithmetic (sign-propagating) right shift.
operator ^(Int128 other) Int128
operator unary-() Int128
operator |(Int128 other) Int128
operator ~() Int128
operator ~/(Int128 other) Int128
Truncating division (toward zero). Int128.min ~/ Int128.minusOne wraps back to Int128.min (the one case where the mathematical quotient doesn't fit).

Static Methods

fromBytes(List<int> bytes, {Endian endian = Endian.big, int offset = 0}) Int128
parseDecimal(String s) Int128
Strict decimal parse: throws IntegerError on overflow/underflow, unlike the wrapping constructor.
parseHex(String s) Int128

Constants

max → const Int128
min → const Int128
minusOne → const Int128
one → const Int128
zero → const Int128