BigInt class - dart:core library (original) (raw)
An arbitrarily large integer value.
Big integers are signed and can have an arbitrary number of significant digits, only limited by memory.
To create a big integer from the provided number, use BigInt.from.
var bigInteger = BigInt.from(-1); // -1
bigInteger = BigInt.from(0.9999); // 0
bigInteger = BigInt.from(-10.99); // -10
bigInteger = BigInt.from(0x7FFFFFFFFFFFFFFF); // 9223372036854775807
bigInteger = BigInt.from(1e+30); // 1000000000000000019884624838656
To parse a large integer value from a string, use parse or tryParse.
var value = BigInt.parse('0x1ffffffffffffffff'); // 36893488147419103231
value = BigInt.parse('12345678901234567890'); // 12345678901234567890
To check whether a big integer can be represented as an int without losing precision, use isValidInt.
print(bigNumber.isValidInt); // false
To convert a big integer into an int, use toInt. To convert a big integer into an double, use toDouble.
var bigValue = BigInt.from(10).pow(3);
print(bigValue.isValidInt); // true
print(bigValue.toInt()); // 1000
print(bigValue.toDouble()); // 1000.0
See also:
- int: An integer number.
- double: A double-precision floating point number.
- num: The super class for int and double.
- Numbers inA tour of the Dart language.
Implemented types
Constructors
BigInt.from(num value)
Creates a big integer from the provided value
number.
factory
Properties
Returns the minimum number of bits required to store this big integer.
no setter
The hash code for this object.
no setterinherited
Whether this big integer is even.
no setter
Whether this number is negative.
no setter
Whether this big integer is odd.
no setter
Whether this big integer can be represented as an int
without losing precision.
no setter
A representation of the runtime type of the object.
no setterinherited
Returns the sign of this big integer.
no setter
Methods
Returns the absolute value of this integer.
Compares this to other
.
override
Returns the greatest common divisor of this big integer and other
.
modInverse(BigInt modulus)→ BigInt
Returns the modular multiplicative inverse of this big integer modulo modulus
.
modPow(BigInt exponent, BigInt modulus)→ BigInt
Returns this integer to the power of exponent
modulo modulus
.
noSuchMethod(Invocation invocation)→ dynamic
Invoked when a nonexistent method or property is accessed.
inherited
Returns this
to the power of exponent
.
remainder(BigInt other)→ BigInt
Returns the remainder of the truncating division of this
by other
.
Returns this BigInt as a double.
Returns this BigInt as an int.
toRadixString(int radix)→ String
Converts this BigInt to a string representation in the given radix
.
Returns the least significant width
bits of this integer, extending the highest retained bit to the sign. This is the same as truncating the value to fit in width
bits using an signed 2-s complement representation. The returned value has the same bit value in all positions higher than width
.
Returns a String-representation of this integer.
override
toUnsigned(int width)→ BigInt
Returns the least significant width
bits of this big integer as a non-negative number (i.e. unsigned representation). The returned value has zeros in all bit positions higher than width
.
Operators
operator %(BigInt other)→ BigInt
Euclidean modulo operator.
operator &(BigInt other)→ BigInt
Bit-wise and operator.
operator *(BigInt other)→ BigInt
Multiplies other
by this big integer.
operator +(BigInt other)→ BigInt
Adds other
to this big integer.
operator -(BigInt other)→ BigInt
Subtracts other
from this big integer.
operator /(BigInt other)→ double
Double division operator.
operator <(BigInt other)→ bool
Whether this big integer is numerically smaller than other
.
operator <<(int shiftAmount)→ BigInt
Shift the bits of this integer to the left by shiftAmount
.
operator <=(BigInt other)→ bool
Whether other
is numerically greater than this big integer.
operator ==(Object other)→ bool
The equality operator.
inherited
operator >(BigInt other)→ bool
Whether this big integer is numerically greater than other
.
operator >=(BigInt other)→ bool
Whether other
is numerically smaller than this big integer.
operator >>(int shiftAmount)→ BigInt
Shift the bits of this integer to the right by shiftAmount
.
operator ^(BigInt other)→ BigInt
Bit-wise exclusive-or operator.
Return the negative value of this integer.
operator |(BigInt other)→ BigInt
Bit-wise or operator.
operator ~()→ BigInt
The bit-wise negate operator.
operator ~/(BigInt other)→ BigInt
Truncating integer division operator.
Static Properties
A big integer with the numerical value 1.
no setter
A big integer with the numerical value 2.
no setter
A big integer with the numerical value 0.
no setter
Static Methods
parse(String source, {int? radix})→ BigInt
Parses source
as a, possibly signed, integer literal and returns its value.
tryParse(String source, {int? radix})→ BigInt?
Parses source
as a, possibly signed, integer literal and returns its value.