Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
struct System.​Numerics.​BigInteger
Assembly: System.Runtime.Numerics
Implemented Interfaces
- IBinaryInteger`1 (Inherits: IComparableIComparable<​BigInteger>IEquatable<​BigInteger>IFormattableIParsable<​BigInteger>ISpanFormattableISpanParsable<​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>IUtf8SpanFormattableIUtf8SpanParsable<​BigInteger>ISubtractionOperators<​BigInteger, BigInteger, BigInteger>IUnaryNegationOperators<​BigInteger, BigInteger>IUnaryPlusOperators<​BigInteger, BigInteger>IShiftOperators<​BigInteger, int, BigInteger>)
- ISignedNumber`1 (Inherits: INumberBase<​BigInteger>IEquatable<​BigInteger>IFormattableIParsable<​BigInteger>ISpanFormattableISpanParsable<​BigInteger>IUtf8SpanFormattableIUtf8SpanParsable<​BigInteger>IAdditionOperators<​BigInteger, BigInteger, BigInteger>IAdditiveIdentity<​BigInteger, BigInteger>IDecrementOperators<​BigInteger>IDivisionOperators<​BigInteger, BigInteger, BigInteger>IEqualityOperators<​BigInteger, BigInteger, bool>IIncrementOperators<​BigInteger>IMultiplicativeIdentity<​BigInteger, BigInteger>IMultiplyOperators<​BigInteger, BigInteger, BigInteger>ISubtractionOperators<​BigInteger, BigInteger, BigInteger>IUnaryNegationOperators<​BigInteger, BigInteger>IUnaryPlusOperators<​BigInteger, BigInteger>)
Represents an arbitrarily large signed integer.
Properties
public
bool
IsEven
Indicates whether the value of the current <see cref="T:System.Numerics.BigInteger" /> object is an even number.
public
bool
IsOne
Indicates whether the value of the current <see cref="T:System.Numerics.BigInteger" /> object is <see cref="P:System.Numerics.BigInteger.One" /> .
public
bool
IsPowerOfTwo
Indicates whether the value of the current <see cref="T:System.Numerics.BigInteger" /> object is a power of two.
public
bool
IsZero
Indicates whether the value of the current <see cref="T:System.Numerics.BigInteger" /> object is <see cref="P:System.Numerics.BigInteger.Zero" /> .
public static
BigInteger
MinusOne
Gets a value that represents the number negative one (-1).
public static
BigInteger
One
Gets a value that represents the number one (1).
public
int
Sign
Gets a number that indicates the sign (negative, positive, or zero) of the current <see cref="T:System.Numerics.BigInteger" /> object.
public static
BigInteger
Zero
Gets a value that represents the number 0 (zero).
Methods
public static
BigInteger
Abs​(BigInteger value)
Gets the absolute value of a <see cref="T:System.Numerics.BigInteger" /> object.
Returns The absolute value of <paramref name="value" /> .
value
A number.
public static
BigInteger
Add​(BigInteger left,
BigInteger right)
Adds two <see cref="T:System.Numerics.BigInteger" /> values and returns the result.
Returns The sum of <paramref name="left" /> and <paramref name="right" /> .
left
The first value to add.
right
The second value to add.
public static
BigInteger
Clamp​(BigInteger value,
BigInteger min,
BigInteger max)
Clamps a value to an inclusive minimum and maximum value.
Returns The result of clamping <paramref name="value" /> to the inclusive range of <paramref name="min" /> and <paramref name="max" /> .
value
The value to clamp.
min
The inclusive minimum to which <paramref name="value" /> should clamp.
max
The inclusive maximum to which <paramref name="value" /> should clamp.
public static
int
Compare​(BigInteger left,
BigInteger right)
Compares two <see cref="T:System.Numerics.BigInteger" /> values and returns an integer that indicates whether the first value is less than, equal to, or greater than the second value.
Returns A signed integer that indicates the relative values of <paramref name="left" /> and <paramref name="right" /> , as shown in the following table.
<list type="table">
<listheader>
<term> Value</term>
<description> Condition</description>
</listheader>
<item>
<term> Less than zero</term>
<description>
<paramref name="left" /> is less than <paramref name="right" />.</description>
</item>
<item>
<term> Zero</term>
<description>
<paramref name="left" /> equals <paramref name="right" />.</description>
</item>
<item>
<term> Greater than zero</term>
<description>
<paramref name="left" /> is greater than <paramref name="right" />.</description>
</item>
</list>
left
The first value to compare.
right
The second value to compare.
public
int
CompareTo​(long other)
Compares this instance to a signed 64-bit integer and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the signed 64-bit integer.
Returns A signed integer value that indicates the relationship of this instance to <paramref name="other" /> , as shown in the following table.
<list type="table">
<listheader>
<term> Return value</term>
<description> Description</description>
</listheader>
<item>
<term> Less than zero</term>
<description> The current instance is less than <paramref name="other" />.</description>
</item>
<item>
<term> Zero</term>
<description> The current instance equals <paramref name="other" />.</description>
</item>
<item>
<term> Greater than zero</term>
<description> The current instance is greater than <paramref name="other" />.</description>
</item>
</list>
other
The signed 64-bit integer to compare.
public
int
CompareTo​(BigInteger other)
Compares this instance to a second <see cref="T:System.Numerics.BigInteger" /> and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object.
Returns A signed integer value that indicates the relationship of this instance to <paramref name="other" /> , as shown in the following table.
<list type="table">
<listheader>
<term> Return value</term>
<description> Description</description>
</listheader>
<item>
<term> Less than zero</term>
<description> The current instance is less than <paramref name="other" />.</description>
</item>
<item>
<term> Zero</term>
<description> The current instance equals <paramref name="other" />.</description>
</item>
<item>
<term> Greater than zero</term>
<description> The current instance is greater than <paramref name="other" />.</description>
</item>
</list>
other
The object to compare.
public
int
CompareTo​(object obj)
Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object.
Returns A signed integer that indicates the relationship of the current instance to the <paramref name="obj" /> parameter, as shown in the following table.
<list type="table">
<listheader>
<term> Return value</term>
<description> Description</description>
</listheader>
<item>
<term> Less than zero</term>
<description> The current instance is less than <paramref name="obj" />.</description>
</item>
<item>
<term> Zero</term>
<description> The current instance equals <paramref name="obj" />.</description>
</item>
<item>
<term> Greater than zero</term>
<description> The current instance is greater than <paramref name="obj" />, or the <paramref name="obj" /> parameter is <see langword="null" />.</description>
</item>
</list>
obj
The object to compare.
public
int
CompareTo​(ulong other)
Compares this instance to an unsigned 64-bit integer and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the unsigned 64-bit integer.
Returns A signed integer that indicates the relative value of this instance and <paramref name="other" /> , as shown in the following table.
<list type="table">
<listheader>
<term>Return value</term>
<description>Description</description>
</listheader>
<item>
<term>Less than zero</term>
<description>The current instance is less than <paramref name="other" />.</description>
</item>
<item>
<term>Zero</term>
<description>The current instance equals <paramref name="other" />.</description>
</item>
<item>
<term>Greater than zero</term>
<description>The current instance is greater than <paramref name="other" />.</description>
</item>
</list>
other
The unsigned 64-bit integer to compare.
public static
BigInteger
CopySign​(BigInteger value,
BigInteger sign)
Copies the sign of a value to the sign of another value.
Returns A value with the magnitude of <paramref name="value" /> and the sign of <paramref name="sign" /> .
value
The value whose magnitude is used in the result.
sign
The value whose sign is used in the result.
public static
BigInteger
CreateChecked​(TOther value)
Creates an instance of the current type from a value, throwing an overflow exception for any values that fall outside the representable range of the current type.
Returns An instance of <typeparamref name="TSelf" /> created from <paramref name="value" /> .
value
The value that's used to create the instance of <typeparamref name="TSelf" /> .
public static
BigInteger
CreateSaturating​(TOther value)
Creates an instance of the current type from a value, saturating any values that fall outside the representable range of the current type.
Returns An instance of <typeparamref name="TSelf" /> created from <paramref name="value" /> , saturating if <paramref name="value" /> falls outside the representable range of <typeparamref name="TSelf" /> .
value
The value that's used to create the instance of <typeparamref name="TSelf" /> .
public static
BigInteger
CreateTruncating​(TOther value)
Creates an instance of the current type from a value, truncating any values that fall outside the representable range of the current type.
Returns An instance of <typeparamref name="TSelf" /> created from <paramref name="value" /> , truncating if <paramref name="value" /> falls outside the representable range of <typeparamref name="TSelf" /> .
value
The value that's used to create the instance of <typeparamref name="TSelf" /> .
public static
BigInteger
Divide​(BigInteger dividend,
BigInteger divisor)
Divides one <see cref="T:System.Numerics.BigInteger" /> value by another and returns the result.
Returns The quotient of the division.
dividend
The value to be divided.
divisor
The value to divide by.
DivRem​(BigInteger left,
BigInteger right)
Computes the quotient and remainder of two values.
Returns The quotient and remainder of <paramref name="left" /> divided-by <paramref name="right" /> .
left
The value that <paramref name="right" /> divides.
right
The value that divides <paramref name="left" /> .
public static
BigInteger
DivRem​(BigInteger dividend,
BigInteger divisor,
BigInteger& remainder)
public
bool
Equals​(long other)
Returns a value that indicates whether the current instance and a signed 64-bit integer have the same value.
Returns <see langword="true" /> if the signed 64-bit integer and the current instance have the same value; otherwise, <see langword="false" /> .
other
The signed 64-bit integer value to compare.
public
bool
Equals​(BigInteger other)
Returns a value that indicates whether the current instance and a specified <see cref="T:System.Numerics.BigInteger" /> object have the same value.
Returns <see langword="true" /> if this <see cref="T:System.Numerics.BigInteger" /> object and <paramref name="other" /> have the same value; otherwise, <see langword="false" /> .
other
The object to compare.
public
bool
Equals​(object obj)
Returns a value that indicates whether the current instance and a specified object have the same value.
Returns <see langword="true" /> if the <paramref name="obj" /> argument is a <see cref="T:System.Numerics.BigInteger" /> object, and its value is equal to the value of the current <see cref="T:System.Numerics.BigInteger" /> instance; otherwise, <see langword="false" /> .
obj
The object to compare.
public
bool
Equals​(ulong other)
Returns a value that indicates whether the current instance and an unsigned 64-bit integer have the same value.
Returns <see langword="true" /> if the current instance and the unsigned 64-bit integer have the same value; otherwise, <see langword="false" /> .
other
The unsigned 64-bit integer to compare.
public
long
GetBitLength​()
Gets the number of bits required for shortest two's complement representation of the current instance without the sign bit.
Returns The minimum non-negative number of bits in two's complement notation without the sign bit.
public
int
GetByteCount​(bool isUnsigned = false)
Gets the number of bytes that will be output by <see cref="M:System.Numerics.BigInteger.ToByteArray(System.Boolean,System.Boolean)" /> and <see cref="M:System.Numerics.BigInteger.TryWriteBytes(System.Span{System.Byte},System.Int32@,System.Boolean,System.Boolean)" /> .
Returns The number of bytes.
isUnsigned
<see langword="true" /> to use unsigned encoding; otherwise, <see langword="false" /> .
public
int
GetHashCode​()
Returns the hash code for the current <see cref="T:System.Numerics.BigInteger" /> object.
Returns A 32-bit signed integer hash code.
public static
BigInteger
GreatestCommonDivisor​(BigInteger left,
BigInteger right)
Finds the greatest common divisor of two <see cref="T:System.Numerics.BigInteger" /> values.
Returns The greatest common divisor of <paramref name="left" /> and <paramref name="right" /> .
left
The first value.
right
The second value.
public static
bool
IsEvenInteger​(BigInteger value)
Determines if a value represents an even integral number.
Returns <see langword="true" /> if <paramref name="value" /> is an even integer; otherwise, <see langword="false" /> .
value
The value to be checked.
Returns <see langword="true" /> if <paramref name="value" /> is negative; otherwise, <see langword="false" /> .
value
The value to be checked.
public static
bool
IsOddInteger​(BigInteger value)
Determines if a value represents an odd integral number.
Returns <see langword="true" /> if <paramref name="value" /> is an odd integer; otherwise, <see langword="false" /> .
value
The value to be checked.
Returns <see langword="true" /> if <paramref name="value" /> is positive; otherwise, <see langword="false" /> .
value
The value to be checked.
public static
bool
IsPow2​(BigInteger value)
Determines if a value is a power of two.
Returns <see langword="true" /> if <paramref name="value" /> is a power of two; otherwise, <see langword="false" /> .
value
The value to be checked.
public static
BigInteger
LeadingZeroCount​(BigInteger value)
Computes the number of leading zeros in a value.
Returns The number of leading zeros in <paramref name="value" /> .
value
The value whose leading zeroes are to be counted.
public static
double
Log​(BigInteger value)
Returns the natural (base <see langword="e" /> ) logarithm of a specified number.
Returns The natural (base <see langword="e" /> ) logarithm of <paramref name="value" /> , as shown in the table in the Remarks section.
value
The number whose logarithm is to be found.
public static
double
Log​(BigInteger value,
double baseValue)
Returns the logarithm of a specified number in a specified base.
Returns The base <paramref name="baseValue" /> logarithm of <paramref name="value" /> , as shown in the table in the Remarks section.
value
A number whose logarithm is to be found.
baseValue
The base of the logarithm.
public static
double
Log10​(BigInteger value)
Returns the base 10 logarithm of a specified number.
Returns The base 10 logarithm of <paramref name="value" /> , as shown in the table in the Remarks section.
value
A number whose logarithm is to be found.
Returns The log2 of <paramref name="value" /> .
value
The value whose log2 is to be computed.
public static
BigInteger
Max​(BigInteger left,
BigInteger right)
Returns the larger of two <see cref="T:System.Numerics.BigInteger" /> values.
Returns The <paramref name="left" /> or <paramref name="right" /> parameter, whichever is larger.
left
The first value to compare.
right
The second value to compare.
public static
BigInteger
MaxMagnitude​(BigInteger x,
BigInteger y)
Compares two values to compute which is greater.
Returns <paramref name="x" /> if it is greater than <paramref name="y" /> ; otherwise, <paramref name="y" /> .
x
The value to compare with <paramref name="y" /> .
y
The value to compare with <paramref name="x" /> .
public static
BigInteger
Min​(BigInteger left,
BigInteger right)
Returns the smaller of two <see cref="T:System.Numerics.BigInteger" /> values.
Returns The <paramref name="left" /> or <paramref name="right" /> parameter, whichever is smaller.
left
The first value to compare.
right
The second value to compare.
public static
BigInteger
MinMagnitude​(BigInteger x,
BigInteger y)
Compares two values to compute which is lesser.
Returns <paramref name="x" /> if it is less than <paramref name="y" /> ; otherwise, <paramref name="y" /> .
x
The value to compare with <paramref name="y" /> .
y
The value to compare with <paramref name="x" /> .
public static
BigInteger
ModPow​(BigInteger value,
BigInteger exponent,
BigInteger modulus)
Performs modulus division on a number raised to the power of another number.
Returns The remainder after dividing <paramref name="value" /> exponent by <paramref name="modulus" /> .
value
The number to raise to the <paramref name="exponent" /> power.
exponent
The exponent to raise <paramref name="value" /> by.
modulus
The number by which to divide <paramref name="value" /> raised to the <paramref name="exponent" /> power.
public static
BigInteger
Multiply​(BigInteger left,
BigInteger right)
Returns the product of two <see cref="T:System.Numerics.BigInteger" /> values.
Returns The product of the <paramref name="left" /> and <paramref name="right" /> parameters.
left
The first number to multiply.
right
The second number to multiply.
public static
BigInteger
Negate​(BigInteger value)
Negates a specified <see cref="T:System.Numerics.BigInteger" /> value.
Returns The result of the <paramref name="value" /> parameter multiplied by negative one (-1).
value
The value to negate.
public static
BigInteger
Parse​(ReadOnlySpan<​char> value,
Globalization.​NumberStyles style = 7,
IFormatProvider? provider = null)
Converts the representation of a number, contained in the specified read-only span of characters, in a specified style to its <see cref="T:System.Numerics.BigInteger" /> equivalent.
Returns A value that is equivalent to the number specified in the <paramref name="value" /> parameter.
value
A read-only span of characters that contains the number to convert.
style
A bitwise combination of the enumeration values that specify the permitted format of <paramref name="value" /> .
provider
An object that provides culture-specific formatting information about <paramref name="value" /> .
public static
BigInteger
Parse​(ReadOnlySpan<​char> s,
IFormatProvider? provider)
Parses a span of characters into a value.
Returns The result of parsing <paramref name="s" /> .
s
The span of characters to parse.
provider
An object that provides culture-specific formatting information about <paramref name="s" /> .
public static
BigInteger
Parse​(string value)
Converts the string representation of a number to its <see cref="T:System.Numerics.BigInteger" /> equivalent.
Returns A value that is equivalent to the number specified in the <paramref name="value" /> parameter.
value
A string that contains the number to convert.
public static
BigInteger
Parse​(string value,
Globalization.​NumberStyles style)
Converts the string representation of a number in a specified style to its <see cref="T:System.Numerics.BigInteger" /> equivalent.
Returns A value that is equivalent to the number specified in the <paramref name="value" /> parameter.
value
A string that contains a number to convert.
style
A bitwise combination of the enumeration values that specify the permitted format of <paramref name="value" /> .
public static
BigInteger
Parse​(string value,
Globalization.​NumberStyles style,
IFormatProvider? provider)
Converts the string representation of a number in a specified style and culture-specific format to its <see cref="T:System.Numerics.BigInteger" /> equivalent.
Returns A value that is equivalent to the number specified in the <paramref name="value" /> parameter.
value
A string that contains a number to convert.
style
A bitwise combination of the enumeration values that specify the permitted format of <paramref name="value" /> .
provider
An object that provides culture-specific formatting information about <paramref name="value" /> .
public static
BigInteger
Parse​(string value,
IFormatProvider? provider)
Converts the string representation of a number in a specified culture-specific format to its <see cref="T:System.Numerics.BigInteger" /> equivalent.
Returns A value that is equivalent to the number specified in the <paramref name="value" /> parameter.
value
A string that contains a number to convert.
provider
An object that provides culture-specific formatting information about <paramref name="value" /> .
public static
BigInteger
PopCount​(BigInteger value)
Computes the number of bits that are set in a value.
Returns The number of set bits in <paramref name="value" /> .
value
The value whose set bits are to be counted.
public static
BigInteger
Pow​(BigInteger value,
int exponent)
Raises a <see cref="T:System.Numerics.BigInteger" /> value to the power of a specified value.
Returns The result of raising <paramref name="value" /> to the <paramref name="exponent" /> power.
value
The number to raise to the <paramref name="exponent" /> power.
exponent
The exponent to raise <paramref name="value" /> by.
public static
BigInteger
Remainder​(BigInteger dividend,
BigInteger divisor)
Performs integer division on two <see cref="T:System.Numerics.BigInteger" /> values and returns the remainder.
Returns The remainder after dividing <paramref name="dividend" /> by <paramref name="divisor" /> .
dividend
The value to be divided.
divisor
The value to divide by.
public static
BigInteger
RotateLeft​(BigInteger value,
int rotateAmount)
Rotates a value left by a given amount.
Returns The result of rotating <paramref name="value" /> left by <paramref name="rotateAmount" /> .
value
The value that's rotated left by <paramref name="rotateAmount" /> .
rotateAmount
The amount by which <paramref name="value" /> is rotated left.
public static
BigInteger
RotateRight​(BigInteger value,
int rotateAmount)
Rotates a value right by a given amount.
Returns The result of rotating <paramref name="value" /> right by <paramref name="rotateAmount" /> .
value
The value that's rotated right by <paramref name="rotateAmount" /> .
rotateAmount
The amount by which <paramref name="value" /> is rotated right.
public static
BigInteger
Subtract​(BigInteger left,
BigInteger right)
Subtracts one <see cref="T:System.Numerics.BigInteger" /> value from another and returns the result.
Returns The result of subtracting <paramref name="right" /> from <paramref name="left" /> .
left
The value to subtract from (the minuend).
right
The value to subtract (the subtrahend).
public
byte[]
ToByteArray​()
Converts a <see cref="T:System.Numerics.BigInteger" /> value to a byte array.
Returns The value of the current <see cref="T:System.Numerics.BigInteger" /> object converted to an array of bytes.
public
byte[]
ToByteArray​(bool isUnsigned = false,
bool isBigEndian = false)
Returns the value of this <see cref="T:System.Numerics.BigInteger" /> as a byte array using the fewest number of bytes possible. If the value is zero, returns an array of one byte whose element is 0x00.
Returns The value of the current <see cref="T:System.Numerics.BigInteger" /> object converted to an array of bytes.
isUnsigned
<see langword="true" /> to use unsigned encoding; otherwise, <see langword="false" /> .
isBigEndian
<see langword="true" /> to write the bytes in a big-endian byte order; otherwise, <see langword="false" /> .
public
string
ToString​()
Converts the numeric value of the current <see cref="T:System.Numerics.BigInteger" /> object to its equivalent string representation.
Returns The string representation of the current <see cref="T:System.Numerics.BigInteger" /> value.
public
string
ToString​(IFormatProvider? provider)
Converts the numeric value of the current <see cref="T:System.Numerics.BigInteger" /> object to its equivalent string representation by using the specified culture-specific formatting information.
Returns The string representation of the current <see cref="T:System.Numerics.BigInteger" /> value in the format specified by the <paramref name="provider" /> parameter.
provider
An object that supplies culture-specific formatting information.
public
string
ToString​(string format)
Converts the numeric value of the current <see cref="T:System.Numerics.BigInteger" /> object to its equivalent string representation by using the specified format.
Returns The string representation of the current <see cref="T:System.Numerics.BigInteger" /> value in the format specified by the <paramref name="format" /> parameter.
format
A standard or custom numeric format string.
public
string
ToString​(string format,
IFormatProvider provider)
Converts the numeric value of the current <see cref="T:System.Numerics.BigInteger" /> object to its equivalent string representation by using the specified format and culture-specific format information.
Returns The string representation of the current <see cref="T:System.Numerics.BigInteger" /> value as specified by the <paramref name="format" /> and <paramref name="provider" /> parameters.
format
A standard or custom numeric format string.
provider
An object that supplies culture-specific formatting information.
public static
BigInteger
TrailingZeroCount​(BigInteger value)
Computes the number of trailing zeros in a value.
Returns The number of trailing zeros in <paramref name="value" /> .
value
The value whose trailing zeroes are to be counted.
public
bool
TryFormat​(Span<​char> destination,
Int32& charsWritten,
ReadOnlySpan<​char> format = null,
IFormatProvider? provider = null)
public static
bool
TryParse​(ReadOnlySpan<​char> value,
Globalization.​NumberStyles style,
IFormatProvider? provider,
BigInteger& result)
public static
bool
TryParse​(ReadOnlySpan<​char> s,
IFormatProvider? provider,
BigInteger& result)
public static
bool
TryParse​(ReadOnlySpan<​char> value,
BigInteger& result)
public static
bool
TryParse​(string value,
Globalization.​NumberStyles style,
IFormatProvider provider,
BigInteger& result)
public
bool
TryWriteBytes​(Span<​byte> destination,
Int32& bytesWritten,
bool isUnsigned = false,
bool isBigEndian = false)
protected
void
Finalize​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object