BigInteger Structure

Represents a positive integer of arbitrary size.

Definition

Namespace: Extreme.Mathematics
Assembly: Extreme.Numerics (in Extreme.Numerics.dll) Version: 8.1.23
C#
[SerializableAttribute]
public readonly struct BigInteger : IComparable, 
	IFormattable, IConvertible, IEquatable<BigInteger>, IComparable<BigInteger>, 
	IEquatable<int>, IComparable<int>
Inheritance
Object  →  ValueType  →  BigInteger
Implements
IComparable, IComparable<BigInteger>, IComparable<Int32>, IConvertible, IEquatable<BigInteger>, IEquatable<Int32>, IFormattable

Remarks

Use the BigInteger structure to represent positive integers that may be too large to fit into the built-in integer types. The BigInteger structure can exactly represent numbers up to about 646 million decimal digits.

Big integers can be constructed in a variety of ways, including from other numerical types and from strings. Implicit (widening) conversions are available for all built-in unsigned integer types. Explicit conversions from signed integer types as well as Single, Double and Decimal are also available.

The BigInteger structure provides methods for all the common operations on integers. Overloaded versions of the major arithmetic operators are provided for languages that support them. For languages that don't support operator overloading, equivalent static methods are supplied.

When performing a binary operation, if one of the operands is a BigInteger, then the other operand is required to also be an integral type. Prior to performing the operation, if the other operand is not a BigInteger, it is converted to BigInteger.

The BigInteger type supports generic arithmetic. The associated arithmetic type implements IEuclideanRingOperations<T>, which means it supports addition, subtraction, multiplication and integer division with remainder.

Constructors

BigInteger(Byte[]) Constructs a new BigInteger from a byte array containing a two's complement representation of the number.
BigInteger(Decimal) Constructs a new BigInteger for a Decimal value.
BigInteger(Double) Constructs a new BigInteger.
BigInteger(Int32) Constructs a new BigInteger.
BigInteger(Int64) Constructs a new BigInteger.
BigInteger(UInt32) Constructs a new BigInteger.
BigInteger(UInt32[]) Constructs a new BigInteger from raw data.
BigInteger(UInt64) Constructs a new BigInteger.
BigInteger(Int32, Byte[]) Constructs a new BigInteger from a sign and a byte array.

Properties

BitCount Gets the number of bits in the number.
DecimalDigitCount Gets the number of decimal digits in the number.
IsEven Gets whether the number is even.
IsOdd Gets whether the number is odd.
IsOne Gets whether the number equals 1.
IsPowerOfTwo Gets whether the number is a power of two..
IsZero Gets whether the number is zero.
Sign Gets the sign of this BigInteger: -1, 0, or 1.

Methods

Abs Returns the absolute value of a number.
Add Returns the sum of two BigInteger numbers.
BinomialCoefficients Enumerates over the binomial coefficients of a specified degree.
Compare Compares two numbers.
CompareTo(BigInteger) Compares a number to another number.
CompareTo(Int32) Compares a number to another number.
CompareTo(Int64) Compares a number to another number.
Divide Divides one BigInteger by another and returns the result.
DivRem Computes the quotient and remainder of two BigInteger numbers.
Equals(BigInteger) Tests whether a number equals another number.
Equals(Int32) Tests whether a number equals another number.
Equals(Object) Returns a value indicating whether this instance is equal to a specified object.
(Overrides ValueType.Equals(Object))
ExtendedGreatestCommonDivisor Returns the greatest common divisor (GCD) of two BigInteger numbers.
Factorial Gets the factorial of a number.
Factorial2 Gets the double factorial of a number.
GetHashCode Returns the hash code for this instance.
(Overrides ValueType.GetHashCode())
GetTypeGets the Type of the current instance.
(Inherited from Object)
GreatestCommonDivisor Returns the greatest common divisor (GCD) of two BigInteger numbers.
IsPseudoPrime Uses the Rabin-Miller test to determine if a number is pseudo-prime.
LeastCommonMultiple Returns the least common multiple (LCM) of two BigInteger numbers.
LeftShift Shifts the bits to the left, padding the right with zeros.
Max Returns the largest of two numbers.
Min Returns the smallest of two numbers.
Mod Returns the remainder after dividing one BigInteger by another and returns the result.
ModularInverse Computes the modular inverse of an integer with respect to the specified modulus.
ModularPow(BigInteger, BigInteger, BigInteger) Raises a number to a power modulo another number.
ModularPow(BigInteger, Int32, BigInteger) Raises a number to a power modulo another number.
Modulus Returns the remainder after dividing one BigInteger by another and returns the result.
Multiply(BigInteger, BigInteger) Returns the product of two BigInteger numbers.
Multiply(BigInteger, Int32) Returns the product of a BigInteger number and an integer.
Multiply(BigInteger, UInt32) Returns the product of a BigInteger number and an unsigned integer.
Multiply(Int32, BigInteger) Returns the product of an integer and a BigInteger number.
Multiply(UInt32, BigInteger) Returns the product of an unsigned integer and a BigInteger number.
Negate Returns a BigInteger with the opposite sign.
Parse(String) Converts the string representation of a number to its BigInteger equivalent.
Parse(String, NumberStyles) Converts the string representation of a number in a specified style to its BigInteger equivalent.
Parse(String, IFormatProvider) Converts the string representation of a number in a specified culture-specific format to its BigInteger equivalent.
Parse(String, NumberStyles, IFormatProvider) Converts the string representation of a number in a specified style and culture-specific format to its BigInteger equivalent.
Pow(BigInteger, Int32) Raises a number to the specified power and returns the result as a BigInteger number.
Pow(Int32, Int32) Raises a number to the specified power and returns the result as a BigInteger number.
Random Returns a random BigInteger number with the specified number of bits.
RightShift(BigInteger, Int32) Shifts the bits to the right, discarding bits on the right.
RightShift(BigInteger, Int32, RoundingMode) Shifts the bits to the right with rounding.
Sqrt Computes the integer square root of a number.
Square Returns the square of a BigInteger number.
Subtract Returns the difference between two BigInteger numbers.
ToByteArray Converts a BigInteger value to a byte array.
ToString() Returns a string representation of the number.
(Overrides ValueType.ToString())
ToString(Int32) Returns a string representation of the integer in the specified radix base.
ToString(String) Formats the value of the current instance using the specified format.
ToString(String, IFormatProvider) Formats the value of the current instance using the specified format.
TryParse(String, BigInteger) Converts the string representation of a number to its BigInteger equivalent. A return value indicates whether the conversion succeeded or failed.
TryParse(String, NumberStyles, IFormatProvider, BigInteger) Converts the string representation of a number in a specified style and culture-specific format to its BigInteger equivalent. A return value indicates whether the conversion succeeded or failed.
Xor Computes the bitwise exclusive or of two BigInteger values.

Operators

Addition(BigInteger, BigInteger) Returns the sum of two BigInteger numbers.
BitwiseAnd(BigInteger, BigInteger) Computes the bitwise and of two BigInteger values.
BitwiseOr(BigInteger, BigInteger) Computes the bitwise and of two BigInteger values.
Division(BigInteger, BigInteger) Divides one BigInteger by another and returns the result.
Division(BigInteger, Int32) Divides one BigInteger by another and returns the result.
Equality(BigInteger, BigInteger) Returns whether a BigInteger is equal to another and returns the result.
Equality(BigInteger, Int32) Returns whether a BigInteger is equal to an integer.
Equality(Int32, BigInteger) Returns whether a BigInteger is equal to an integer.
ExclusiveOr(BigInteger, BigInteger) Computes the bitwise exclusive or of two BigInteger values.
Explicit(BigInteger to Byte) Converts a BigInteger to a Byte value.
Explicit(BigInteger to Decimal) Converts a BigInteger to a Decimal number.
Explicit(BigInteger to Double) Converts a BigInteger to a double-precision floating-point number.
Explicit(BigInteger to Int16) Converts a BigInteger to a Int16 value.
Explicit(BigInteger to Int32) Converts a BigInteger to a Int32 value.
Explicit(BigInteger to Int64) Converts a BigInteger to a long integer.
Explicit(BigInteger to SByte) Converts a BigInteger to a SByte value.
Explicit(BigInteger to Single) Converts a BigInteger to a single-precision floating-point number.
Explicit(BigInteger to UInt16) Converts a BigInteger to a UInt16 value.
Explicit(BigInteger to UInt32) Converts a BigInteger to an unsigned integer.
Explicit(BigInteger to UInt64) Converts a BigInteger to a long unsigned integer.
Explicit(Decimal to BigInteger) Converts a Decimal number to a BigInteger value.
Explicit(Double to BigInteger) Converts a double-precision floating-point number to a BigInteger value.
Explicit(Single to BigInteger) Converts a single-precision floating-point number to a BigInteger value.
Exponent(BigInteger, Int32) Represents the exponentiation operator.
Exponentiation(BigInteger, Int32) Represents the exponentiation operator.
GreaterThan(BigInteger, BigInteger) Returns whether a BigInteger is greater than another and returns the result.
GreaterThan(BigInteger, Int32) Returns whether an integer is greater than a BigInteger.
GreaterThan(Int32, BigInteger) Returns whether an integer is greater than a BigInteger.
GreaterThanOrEqual(BigInteger, BigInteger) Returns whether a BigInteger is greater than or equal to another and returns the result.
GreaterThanOrEqual(BigInteger, Int32) Returns whether an integer is greater than or equal to a BigInteger.
GreaterThanOrEqual(Int32, BigInteger) Returns whether an integer is greater than or equal to a BigInteger.
Implicit(Byte to BigInteger) Converts a Byte value to a BigInteger number.
Implicit(Int16 to BigInteger) Converts a 16 bit signed integer to a BigInteger value.
Implicit(Int32 to BigInteger) Converts a 32 bit signed integer to a BigInteger value.
Implicit(Int64 to BigInteger) Converts a 64 bit signed integer to a BigInteger value.
Implicit(SByte to BigInteger) Converts a signed byte to a BigInteger value.
Implicit(UInt16 to BigInteger) Converts a 16 bit unsigned integer to a BigInteger value.
Implicit(UInt32 to BigInteger) Converts a 32 bit unsigned integer to a BigInteger value.
Implicit(UInt64 to BigInteger) Converts a 64 bit unsigned integer to a BigInteger value.
Inequality(BigInteger, BigInteger) Returns whether a BigInteger is not equal to another and returns the result.
Inequality(BigInteger, Int32) Returns whether a BigInteger is not equal to an integer.
Inequality(Int32, BigInteger) Returns whether a BigInteger is not equal to an integer.
LeftShift(BigInteger, Int32) Shifts the bits to the left, padding the right with zeros.
LessThan(BigInteger, BigInteger) Returns whether a BigInteger is less than another and returns the result.
LessThan(BigInteger, Int32) Returns whether an integer is less than a BigInteger.
LessThan(Int32, BigInteger) Returns whether an integer is less than a BigInteger.
LessThanOrEqual(BigInteger, BigInteger) Returns whether a BigInteger is less than or equal to another and returns the result.
LessThanOrEqual(BigInteger, Int32) Returns whether an integer is less than or equal to a BigInteger.
LessThanOrEqual(Int32, BigInteger) Returns whether an integer is less than or equal to a BigInteger.
Modulus(BigInteger, BigInteger) Returns the remainder after dividing one BigInteger by another and returns the result.
Multiply(BigInteger, BigInteger) Returns the product of two BigInteger numbers.
Multiply(BigInteger, UInt32) Returns the product of a BigInteger number and an unsigned integer.
Multiply(Int32, BigInteger) Returns the product of an integer and a BigInteger number.
Multiply(UInt32, BigInteger) Returns the product of an unsigned integer and a BigInteger number.
OnesComplement(BigInteger) Returns the one's complement of a BigInteger.
RightShift(BigInteger, Int32) Shifts the bits to the right, discarding bits on the right.
Subtraction(BigInteger, BigInteger) Returns the difference between two BigInteger numbers.
UnaryNegation(BigInteger) Returns a BigInteger with the opposite sign.
UnaryPlus(BigInteger) Returns the value of a BigInteger.

Fields

MaxValue The largest possible BigInteger.
MinusOne The number -1 as a BigInteger.
MinValue The smallest possible BigInteger.
One The number one as a BigInteger.
Zero The number zero as a BigInteger.

See Also