BigInteger class

A wrapper class for arbitrary precision integers.

This class wraps Dart's BigInt and provides Java-like functionality similar to Java's BigInteger class.

Example usage:

BigInteger a = BigInteger("123456789012345678901234567890");
BigInteger b = BigInteger.fromInt(42);
BigInteger sum = a + b;

print(sum.toString()); // Very large number
print(a.isProbablePrime()); // Primality test
Implemented types

Constructors

BigInteger(String value, [int radix = 10])
Creates a BigInteger from a string representation.
factory
BigInteger.fromBigInt(BigInt value)
Creates a BigInteger from a BigInt value.
factory
BigInteger.fromInt(int value)
Creates a BigInteger from an int value.
factory

Properties

bitLength → int
Returns the number of bits in this BigInteger.
no setter
hashCode → int
Returns the hash code for this BigInteger.
no setteroverride
isEven → bool
Returns true if this BigInteger is even.
no setter
isNegative → bool
Returns true if this BigInteger is negative.
no setter
isOdd → bool
Returns true if this BigInteger is odd.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
value → BigInt
Returns the wrapped BigInt value.
no setter

Methods

abs() → BigInteger
Returns the absolute value of this BigInteger.
compareTo(BigInteger other) → int
Compares this BigInteger with another.
override
gcd(BigInteger other) → BigInteger
Returns the greatest common divisor of this and other.
isProbablePrime([int certainty = 10]) → bool
Returns true if this BigInteger is probably prime.
modInverse(BigInteger modulus) → BigInteger
Returns the modular multiplicative inverse of this BigInteger.
modPow(BigInteger exponent, BigInteger modulus) → BigInteger
Returns the modular exponentiation of this BigInteger.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pow(int exponent) → BigInteger
Returns this BigInteger raised to the power of the exponent.
toDouble() → double
Converts to double (may lose precision).
toInt() → int
Converts to int (may throw if too large).
toRadixString([int? radix]) → String
Returns a string representation in the specified radix.
toString() → String
Returns a string representation of this BigInteger.
override
toUnsigned(int bitLength) → BigInteger
Returns the value of this BigInteger masked to an unsigned representation with the given bitLength.

Operators

operator %(BigInteger other) → BigInteger
operator &(BigInteger other) → BigInteger
Bitwise operators
operator *(BigInteger other) → BigInteger
operator +(BigInteger other) → BigInteger
Arithmetic operators
operator -(BigInteger other) → BigInteger
operator <(BigInteger other) → bool
Comparison operators
operator <<(int shiftAmount) → BigInteger
operator <=(BigInteger other) → bool
operator ==(Object other) → bool
Returns true if this BigInteger equals the specified object.
override
operator >(BigInteger other) → bool
operator >=(BigInteger other) → bool
operator >>(int shiftAmount) → BigInteger
operator ^(BigInteger other) → BigInteger
operator unary-() → BigInteger
Returns the negation of this BigInteger.
operator |(BigInteger other) → BigInteger
operator ~() → BigInteger
operator ~/(BigInteger other) → BigInteger

Static Properties

ONE → BigInteger
This creates a BigInteger with value 1.
final
TEN → BigInteger
This creates a BigInteger with value 10.
final
TWO → BigInteger
This creates a BigInteger with value 2.
final
ZERO → BigInteger
This creates a BigInteger with value 0.
final