BigInteger Structure

Represents an integer of arbitrary size.

Definition

Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 9.0.4
C#
[SerializableAttribute]
public readonly struct BigInteger : IComparable, 
	IFormattable, IConvertible, IEquatable<BigInteger>, IComparable<BigInteger>, 
	IEquatable<int>, IComparable<int>, IBinaryInteger<BigInteger>, 
	IParsable<BigInteger>, ISpanFormattable, ISpanParsable<BigInteger>, 
	IAdditionOperators<BigInteger, BigInteger, BigInteger>, IAdditiveIdentity<BigInteger, BigInteger>, 
	IBinaryNumber<BigInteger>, IBitwiseOperators<BigInteger, BigInteger, BigInteger>, 
	IComparisonOperators<BigInteger, BigInteger, bool>, IEqualityOperators<BigInteger, BigInteger, bool>, 
	IDecrementOperators<BigInteger>, IDivisionOperators<BigInteger, BigInteger, BigInteger>, 
	IIncrementOperators<BigInteger>, IModulusOperators<BigInteger, BigInteger, BigInteger>, 
	IMultiplicativeIdentity<BigInteger, BigInteger>, IMultiplyOperators<BigInteger, BigInteger, BigInteger>, 
	INumber<BigInteger>, INumberBase<BigInteger>, IUtf8SpanFormattable, 
	IUtf8SpanParsable<BigInteger>, ISubtractionOperators<BigInteger, BigInteger, BigInteger>, 
	IUnaryNegationOperators<BigInteger, BigInteger>, IUnaryPlusOperators<BigInteger, BigInteger>, 
	IShiftOperators<BigInteger, int, BigInteger>, ISignedNumber<BigInteger>
Inheritance
Object  →  ValueType  →  BigInteger
Implements
IComparable, IComparable<BigInteger>, IComparable<Int32>, IConvertible, IEquatable<BigInteger>, IEquatable<Int32>, IFormattable, IParsable<BigInteger>, ISpanFormattable, ISpanParsable<BigInteger>, IUtf8SpanFormattable, IUtf8SpanParsable<BigInteger>, IAdditionOperators<BigInteger, BigInteger, BigInteger>, IAdditiveIdentity<BigInteger, BigInteger>, IBinaryInteger<BigInteger>, IBinaryNumber<BigInteger>, IBitwiseOperators<BigInteger, BigInteger, BigInteger>, IComparisonOperators<BigInteger, BigInteger, Boolean>, IDecrementOperators<BigInteger>, IDivisionOperators<BigInteger, BigInteger, BigInteger>, IEqualityOperators<BigInteger, BigInteger, Boolean>, IIncrementOperators<BigInteger>, IModulusOperators<BigInteger, BigInteger, BigInteger>, IMultiplicativeIdentity<BigInteger, BigInteger>, IMultiplyOperators<BigInteger, BigInteger, BigInteger>, INumber<BigInteger>, INumberBase<BigInteger>, IShiftOperators<BigInteger, Int32, BigInteger>, ISignedNumber<BigInteger>, ISubtractionOperators<BigInteger, BigInteger, BigInteger>, IUnaryNegationOperators<BigInteger, BigInteger>, IUnaryPlusOperators<BigInteger, BigInteger>

Remarks

Use the BigInteger structure to represent 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.

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(Int128) Constructs a new BigInteger.
BigInteger(Int32) Constructs a new BigInteger.
BigInteger(Int64) Constructs a new BigInteger.
BigInteger(UInt128) 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.
Limbs 
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.
ClampClamps a value to an inclusive minimum and maximum value.
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.
CopySignCopies the sign of a value to the sign of another value.
Divide Divides one BigInteger by another and returns the result.
DivRem(BigInteger, BigInteger)Computes the quotient and remainder of two values.
DivRem(BigInteger, BigInteger, BigInteger) 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 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.
IsBitSet 
IsNegativeDetermines if a value represents a negative real number.
IsPositiveDetermines if a value represents zero or a positive real number.
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.
Log2Computes the log2 of a value.
Max Returns the largest of two numbers.
MaxMagnitudeCompares two values to compute which has the greater magnitude.
Min Returns the smallest of two numbers.
MinMagnitudeCompares two values to compute which has the lesser magnitude.
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(ReadOnlySpan<Char>, IFormatProvider)Parses a span of characters into a value.
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(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)Parses a span of characters into a value.
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(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.
TryFormatTries to format the value of the current instance into the provided span of characters.
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(ReadOnlySpan<Char>, IFormatProvider, BigInteger)Tries to parse a span of characters into a value.
TryParse(String, IFormatProvider, BigInteger)Tries to parse a string into a value.
TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, BigInteger)Tries to parse a span of characters into a value.
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.
Addition(BigInteger, Int32) Returns the sum of a BigInteger and a 32 bit integer.
Addition(Int32, BigInteger) Returns the sum of a 32 bit integer and a BigInteger.
BitwiseAnd(BigInteger, BigInteger) Computes the bitwise and of two BigInteger values.
BitwiseOr(BigInteger, BigInteger) Computes the bitwise and of two BigInteger values.
Decrement(BigInteger)Decrements a value.
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(Int128 to BigInteger) Converts a 128 bit signed integer to a BigInteger value.
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(UInt128 to BigInteger) Converts a 128 bit unsigned integer 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.
Increment(BigInteger)Increments a 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, 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.
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.
Subtraction(BigInteger, Int32) 
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