An arbitrarily large integer value.
Big integers are signed and can have an arbitrary number ofsignificant digits, only limited by memory.
To create a big integer from the provided number, useBigInt.from.
var bigInteger = BigInt.from(-1); // -1bigInteger = BigInt.from(0.9999); // 0bigInteger = BigInt.from(-10.99); // -10bigInteger = BigInt.from(0x7FFFFFFFFFFFFFFF); // 9223372036854775807bigInteger = BigInt.from(1e+30); // 1000000000000000019884624838656To parse a large integer value from a string, useparse ortryParse.
var value = BigInt.parse('0x1ffffffffffffffff'); // 36893488147419103231value = BigInt.parse('12345678901234567890'); // 12345678901234567890To check whether a big integer can be represented as anint without losingprecision, useisValidInt.
print(bigNumber.isValidInt); // falseTo convert a big integer into anint, usetoInt.To convert a big integer into andouble, usetoDouble.
var bigValue = BigInt.from(10).pow(3);print(bigValue.isValidInt); // trueprint(bigValue.toInt()); // 1000print(bigValue.toDouble()); // 1000.0See also:
- Implemented types
Constructors
- BigInt.from(numvalue)
- Creates a big integer from the provided
valuenumber.factory
Properties
- bitLength→int
- Returns the minimum number of bits required to store this big integer.no setter
- hashCode→int
- The hash code for this object.no setterinherited
- isEven→bool
- Whether this big integer is even.no setter
- isNegative→bool
- Whether this number is negative.no setter
- isOdd→bool
- Whether this big integer is odd.no setter
- isValidInt→bool
- Whether this big integer can be represented as an
intwithout losingprecision.no setter - runtimeType→Type
- A representation of the runtime type of the object.no setterinherited
- sign→int
- Returns the sign of this big integer.no setter
Methods
- abs(
)→BigInt - Returns the absolute value of this integer.
- compareTo(
BigIntother)→int - Compares this to
other.override - gcd(
BigIntother)→BigInt - Returns the greatest common divisor of this big integer and
other. - modInverse(
BigIntmodulus)→BigInt - Returns the modular multiplicative inverse of this big integermodulo
modulus. - modPow(
BigIntexponent,BigIntmodulus)→BigInt - Returns this integer to the power of
exponentmodulomodulus. - noSuchMethod(
Invocationinvocation)→ dynamic - Invoked when a nonexistent method or property is accessed.inherited
- pow(
intexponent)→BigInt - Returns
thisto the power ofexponent. - remainder(
BigIntother)→BigInt - Returns the remainder of the truncating division of
thisbyother. - toDouble(
)→double - Returns thisBigInt as adouble.
- toInt(
)→int - Returns thisBigInt as anint.
- toRadixString(
intradix)→String - Converts thisBigInt to a string representation in the given
radix. - toSigned(
intwidth)→BigInt - Returns the least significant
widthbits of this integer, extending thehighest retained bit to the sign. This is the same as truncating the valueto fit inwidthbits using an signed 2-s complement representation. Thereturned value has the same bit value in all positions higher thanwidth. - toString(
)→String - Returns a String-representation of this integer.override
- toUnsigned(
intwidth)→BigInt - Returns the least significant
widthbits of this big integer as anon-negative number (i.e. unsigned representation). The returned value haszeros in all bit positions higher thanwidth.
Operators
- operator %(
BigIntother)→BigInt - Euclidean modulo operator.
- operator &(
BigIntother)→BigInt - Bit-wise and operator.
- operator *(
BigIntother)→BigInt - Multiplies
otherby this big integer. - operator +(
BigIntother)→BigInt - Adds
otherto this big integer. - operator -(
BigIntother)→BigInt - Subtracts
otherfrom this big integer. - operator /(
BigIntother)→double - Double division operator.
- operator<(
BigIntother)→bool - Whether this big integer is numerically smaller than
other. - operator<<(
intshiftAmount)→BigInt - Shift the bits of this integer to the left by
shiftAmount. - operator<=(
BigIntother)→bool - Whether
otheris numerically greater than this big integer. - operator ==(
Objectother)→bool - The equality operator.inherited
- operator >(
BigIntother)→bool - Whether this big integer is numerically greater than
other. - operator >=(
BigIntother)→bool - Whether
otheris numerically smaller than this big integer. - operator >>(
intshiftAmount)→BigInt - Shift the bits of this integer to the right by
shiftAmount. - operator ^(
BigIntother)→BigInt - Bit-wise exclusive-or operator.
- operator unary-(
)→BigInt - Return the negative value of this integer.
- operator |(
BigIntother)→BigInt - Bit-wise or operator.
- operator ~(
)→BigInt - The bit-wise negate operator.
- operator ~/(
BigIntother)→BigInt - Truncating integer division operator.