public static int Compare(System.Numerics.BigInteger left, System.Numerics.BigInteger right) { throw null; }
public int CompareTo(long other) { throw null; }
public int CompareTo(System.Numerics.BigInteger other) { throw null; }
- public int CompareTo(object obj) { throw null; }
+ public int CompareTo(object? obj) { throw null; }
[System.CLSCompliantAttribute(false)]
public int CompareTo(ulong other) { throw null; }
public static System.Numerics.BigInteger Divide(System.Numerics.BigInteger dividend, System.Numerics.BigInteger divisor) { throw null; }
public static System.Numerics.BigInteger DivRem(System.Numerics.BigInteger dividend, System.Numerics.BigInteger divisor, out System.Numerics.BigInteger remainder) { throw null; }
public bool Equals(long other) { throw null; }
public bool Equals(System.Numerics.BigInteger other) { throw null; }
- public override bool Equals(object obj) { throw null; }
+ public override bool Equals(object? obj) { throw null; }
[System.CLSCompliantAttribute(false)]
public bool Equals(ulong other) { throw null; }
public int GetByteCount(bool isUnsigned = false) { throw null; }
public static System.Numerics.BigInteger operator -(System.Numerics.BigInteger left, System.Numerics.BigInteger right) { throw null; }
public static System.Numerics.BigInteger operator -(System.Numerics.BigInteger value) { throw null; }
public static System.Numerics.BigInteger operator +(System.Numerics.BigInteger value) { throw null; }
- public static System.Numerics.BigInteger Parse(System.ReadOnlySpan<char> value, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, System.IFormatProvider provider = null) { throw null; }
+ public static System.Numerics.BigInteger Parse(System.ReadOnlySpan<char> value, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, System.IFormatProvider? provider = null) { throw null; }
public static System.Numerics.BigInteger Parse(string value) { throw null; }
public static System.Numerics.BigInteger Parse(string value, System.Globalization.NumberStyles style) { throw null; }
- public static System.Numerics.BigInteger Parse(string value, System.Globalization.NumberStyles style, System.IFormatProvider provider) { throw null; }
- public static System.Numerics.BigInteger Parse(string value, System.IFormatProvider provider) { throw null; }
+ public static System.Numerics.BigInteger Parse(string value, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; }
+ public static System.Numerics.BigInteger Parse(string value, System.IFormatProvider? provider) { throw null; }
public static System.Numerics.BigInteger Pow(System.Numerics.BigInteger value, int exponent) { throw null; }
public static System.Numerics.BigInteger Remainder(System.Numerics.BigInteger dividend, System.Numerics.BigInteger divisor) { throw null; }
public static System.Numerics.BigInteger Subtract(System.Numerics.BigInteger left, System.Numerics.BigInteger right) { throw null; }
public byte[] ToByteArray() { throw null; }
public byte[] ToByteArray(bool isUnsigned = false, bool isBigEndian = false) { throw null; }
public override string ToString() { throw null; }
- public string ToString(System.IFormatProvider provider) { throw null; }
- public string ToString(string format) { throw null; }
- public string ToString(string format, System.IFormatProvider provider) { throw null; }
- public bool TryFormat(System.Span<char> destination, out int charsWritten, System.ReadOnlySpan<char> format = default(System.ReadOnlySpan<char>), System.IFormatProvider provider = null) { throw null; }
- public static bool TryParse(System.ReadOnlySpan<char> value, System.Globalization.NumberStyles style, System.IFormatProvider provider, out System.Numerics.BigInteger result) { throw null; }
+ public string ToString(System.IFormatProvider? provider) { throw null; }
+ public string ToString(string? format) { throw null; }
+ public string ToString(string? format, System.IFormatProvider? provider) { throw null; }
+ public bool TryFormat(System.Span<char> destination, out int charsWritten, System.ReadOnlySpan<char> format = default(System.ReadOnlySpan<char>), System.IFormatProvider? provider = null) { throw null; }
+ public static bool TryParse(System.ReadOnlySpan<char> value, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Numerics.BigInteger result) { throw null; }
public static bool TryParse(System.ReadOnlySpan<char> value, out System.Numerics.BigInteger result) { throw null; }
- public static bool TryParse(string value, System.Globalization.NumberStyles style, System.IFormatProvider provider, out System.Numerics.BigInteger result) { throw null; }
- public static bool TryParse(string value, out System.Numerics.BigInteger result) { throw null; }
+ public static bool TryParse(string? value, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.Numerics.BigInteger result) { throw null; }
+ public static bool TryParse(string? value, out System.Numerics.BigInteger result) { throw null; }
public bool TryWriteBytes(System.Span<byte> destination, out int bytesWritten, bool isUnsigned = false, bool isBigEndian = false) { throw null; }
}
public partial struct Complex : System.IEquatable<System.Numerics.Complex>, System.IFormattable
public static System.Numerics.Complex Divide(System.Numerics.Complex dividend, double divisor) { throw null; }
public static System.Numerics.Complex Divide(System.Numerics.Complex dividend, System.Numerics.Complex divisor) { throw null; }
public bool Equals(System.Numerics.Complex value) { throw null; }
- public override bool Equals(object obj) { throw null; }
+ public override bool Equals(object? obj) { throw null; }
public static System.Numerics.Complex Exp(System.Numerics.Complex value) { throw null; }
public static System.Numerics.Complex FromPolarCoordinates(double magnitude, double phase) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Numerics.Complex Tan(System.Numerics.Complex value) { throw null; }
public static System.Numerics.Complex Tanh(System.Numerics.Complex value) { throw null; }
public override string ToString() { throw null; }
- public string ToString(System.IFormatProvider provider) { throw null; }
- public string ToString(string format) { throw null; }
- public string ToString(string format, System.IFormatProvider provider) { throw null; }
+ public string ToString(System.IFormatProvider? provider) { throw null; }
+ public string ToString(string? format) { throw null; }
+ public string ToString(string? format, System.IFormatProvider? provider) { throw null; }
}
}
// For values int.MinValue < n <= int.MaxValue, the value is stored in sign
// and _bits is null. For all other values, sign is +1 or -1 and the bits are in _bits
internal readonly int _sign; // Do not rename (binary serialization)
- internal readonly uint[] _bits; // Do not rename (binary serialization)
+ internal readonly uint[]? _bits; // Do not rename (binary serialization)
// We have to make a choice of how to represent int.MinValue. This is the one
// value that fits in an int, but whose negation does not fit in an int.
AssertValid();
}
- internal BigInteger(int n, uint[] rgu)
+ internal BigInteger(int n, uint[]? rgu)
{
_sign = n;
_bits = rgu;
return Parse(value, style, NumberFormatInfo.CurrentInfo);
}
- public static BigInteger Parse(string value, IFormatProvider provider)
+ public static BigInteger Parse(string value, IFormatProvider? provider)
{
return Parse(value, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
}
- public static BigInteger Parse(string value, NumberStyles style, IFormatProvider provider)
+ public static BigInteger Parse(string value, NumberStyles style, IFormatProvider? provider)
{
return BigNumber.ParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider));
}
- public static bool TryParse(string value, out BigInteger result)
+ public static bool TryParse(string? value, out BigInteger result)
{
return TryParse(value, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
}
- public static bool TryParse(string value, NumberStyles style, IFormatProvider provider, out BigInteger result)
+ public static bool TryParse(string? value, NumberStyles style, IFormatProvider? provider, out BigInteger result)
{
return BigNumber.TryParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider), out result);
}
- public static BigInteger Parse(ReadOnlySpan<char> value, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
+ public static BigInteger Parse(ReadOnlySpan<char> value, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null)
{
return BigNumber.ParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider));
}
return BigNumber.TryParseBigInteger(value, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
}
- public static bool TryParse(ReadOnlySpan<char> value, NumberStyles style, IFormatProvider provider, out BigInteger result)
+ public static bool TryParse(ReadOnlySpan<char> value, NumberStyles style, IFormatProvider? provider, out BigInteger result)
{
return BigNumber.TryParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider), out result);
}
return s_bnZeroInt;
}
+ Debug.Assert(dividend._bits != null);
+
if (trivialDivisor)
{
uint rest;
return new BigInteger(bits, (dividend._sign < 0) ^ (divisor._sign < 0));
}
+ Debug.Assert(divisor._bits != null);
+
if (dividend._bits.Length < divisor._bits.Length)
{
remainder = dividend;
if (trivialLeft)
{
+ Debug.Assert(right._bits != null);
return left._sign != 0
? BigIntegerCalculator.Gcd(right._bits, NumericsHelpers.Abs(left._sign))
: new BigInteger(right._bits, false);
if (trivialRight)
{
+ Debug.Assert(left._bits != null);
return right._sign != 0
? BigIntegerCalculator.Gcd(left._bits, NumericsHelpers.Abs(right._sign))
: new BigInteger(left._bits, false);
}
+ Debug.Assert(left._bits != null && right._bits != null);
+
if (BigIntegerCalculator.Compare(left._bits, right._bits) < 0)
{
return GreatestCommonDivisor(right._bits, left._bits);
if (trivialModulus)
{
uint bits = trivialValue && trivialExponent ? BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), NumericsHelpers.Abs(exponent._sign), NumericsHelpers.Abs(modulus._sign)) :
- trivialValue ? BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), exponent._bits, NumericsHelpers.Abs(modulus._sign)) :
- trivialExponent ? BigIntegerCalculator.Pow(value._bits, NumericsHelpers.Abs(exponent._sign), NumericsHelpers.Abs(modulus._sign)) :
- BigIntegerCalculator.Pow(value._bits, exponent._bits, NumericsHelpers.Abs(modulus._sign));
+ trivialValue ? BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), exponent._bits!, NumericsHelpers.Abs(modulus._sign)) :
+ trivialExponent ? BigIntegerCalculator.Pow(value._bits!, NumericsHelpers.Abs(exponent._sign), NumericsHelpers.Abs(modulus._sign)) :
+ BigIntegerCalculator.Pow(value._bits!, exponent._bits!, NumericsHelpers.Abs(modulus._sign));
return value._sign < 0 && !exponent.IsEven ? -1 * bits : bits;
}
else
{
- uint[] bits = trivialValue && trivialExponent ? BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), NumericsHelpers.Abs(exponent._sign), modulus._bits) :
- trivialValue ? BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), exponent._bits, modulus._bits) :
- trivialExponent ? BigIntegerCalculator.Pow(value._bits, NumericsHelpers.Abs(exponent._sign), modulus._bits) :
- BigIntegerCalculator.Pow(value._bits, exponent._bits, modulus._bits);
+ uint[] bits = trivialValue && trivialExponent ? BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), NumericsHelpers.Abs(exponent._sign), modulus._bits!) :
+ trivialValue ? BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), exponent._bits!, modulus._bits!) :
+ trivialExponent ? BigIntegerCalculator.Pow(value._bits!, NumericsHelpers.Abs(exponent._sign), modulus._bits!) :
+ BigIntegerCalculator.Pow(value._bits!, exponent._bits!, modulus._bits!);
return new BigInteger(bits, value._sign < 0 && !exponent.IsEven);
}
uint[] bits = trivialValue
? BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), NumericsHelpers.Abs(exponent))
- : BigIntegerCalculator.Pow(value._bits, NumericsHelpers.Abs(exponent));
+ : BigIntegerCalculator.Pow(value._bits!, NumericsHelpers.Abs(exponent));
return new BigInteger(bits, value._sign < 0 && (exponent & 1) != 0);
}
return hash;
}
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
AssertValid();
return _bits[cuDiff - 1] < other._bits[cuDiff - 1] ? -_sign : _sign;
}
- public int CompareTo(object obj)
+ public int CompareTo(object? obj)
{
if (obj == null)
return 1;
public byte[] ToByteArray(bool isUnsigned = false, bool isBigEndian = false)
{
int ignored = 0;
- return TryGetBytes(GetBytesMode.AllocateArray, default, isUnsigned, isBigEndian, ref ignored);
+ return TryGetBytes(GetBytesMode.AllocateArray, default, isUnsigned, isBigEndian, ref ignored)!;
}
/// <summary>
/// If <paramref name="mode"/>==<see cref="GetBytesMode.Span"/>, non-null if the span was long enough, null if there wasn't enough room.
/// </returns>
/// <exception cref="OverflowException">If <paramref name="isUnsigned"/> is <c>true</c> and <see cref="Sign"/> is negative.</exception>
- private byte[] TryGetBytes(GetBytesMode mode, Span<byte> destination, bool isUnsigned, bool isBigEndian, ref int bytesWritten)
+ private byte[]? TryGetBytes(GetBytesMode mode, Span<byte> destination, bool isUnsigned, bool isBigEndian, ref int bytesWritten)
{
Debug.Assert(mode == GetBytesMode.AllocateArray || mode == GetBytesMode.Count || mode == GetBytesMode.Span, $"Unexpected mode {mode}.");
Debug.Assert(mode == GetBytesMode.Span || destination.IsEmpty, $"If we're not in span mode, we shouldn't have been passed a destination.");
byte highByte;
int nonZeroDwordIndex = 0;
uint highDword;
- uint[] bits = _bits;
+ uint[]? bits = _bits;
if (bits == null)
{
highByte = (byte)((sign < 0) ? 0xff : 0x00);
return BigNumber.FormatBigInteger(this, null, NumberFormatInfo.CurrentInfo);
}
- public string ToString(IFormatProvider provider)
+ public string ToString(IFormatProvider? provider)
{
return BigNumber.FormatBigInteger(this, null, NumberFormatInfo.GetInstance(provider));
}
- public string ToString(string format)
+ public string ToString(string? format)
{
return BigNumber.FormatBigInteger(this, format, NumberFormatInfo.CurrentInfo);
}
- public string ToString(string format, IFormatProvider provider)
+ public string ToString(string? format, IFormatProvider? provider)
{
return BigNumber.FormatBigInteger(this, format, NumberFormatInfo.GetInstance(provider));
}
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider provider = null) // TODO: change format to ReadOnlySpan<char>
+ public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null) // TODO: change format to ReadOnlySpan<char>
{
return BigNumber.TryFormatBigInteger(this, format, NumberFormatInfo.GetInstance(provider), destination, out charsWritten);
}
- private static BigInteger Add(uint[] leftBits, int leftSign, uint[] rightBits, int rightSign)
+ private static BigInteger Add(uint[]? leftBits, int leftSign, uint[]? rightBits, int rightSign)
{
bool trivialLeft = leftBits == null;
bool trivialRight = rightBits == null;
if (trivialLeft)
{
+ Debug.Assert(rightBits != null);
uint[] bits = BigIntegerCalculator.Add(rightBits, NumericsHelpers.Abs(leftSign));
return new BigInteger(bits, leftSign < 0);
}
if (trivialRight)
{
+ Debug.Assert(leftBits != null);
uint[] bits = BigIntegerCalculator.Add(leftBits, NumericsHelpers.Abs(rightSign));
return new BigInteger(bits, leftSign < 0);
}
+ Debug.Assert(leftBits != null && rightBits != null);
+
if (leftBits.Length < rightBits.Length)
{
uint[] bits = BigIntegerCalculator.Add(rightBits, leftBits);
return Subtract(left._bits, left._sign, right._bits, right._sign);
}
- private static BigInteger Subtract(uint[] leftBits, int leftSign, uint[] rightBits, int rightSign)
+ private static BigInteger Subtract(uint[]? leftBits, int leftSign, uint[]? rightBits, int rightSign)
{
bool trivialLeft = leftBits == null;
bool trivialRight = rightBits == null;
if (trivialLeft)
{
+ Debug.Assert(rightBits != null);
uint[] bits = BigIntegerCalculator.Subtract(rightBits, NumericsHelpers.Abs(leftSign));
return new BigInteger(bits, leftSign >= 0);
}
if (trivialRight)
{
+ Debug.Assert(leftBits != null);
uint[] bits = BigIntegerCalculator.Subtract(leftBits, NumericsHelpers.Abs(rightSign));
return new BigInteger(bits, leftSign < 0);
}
+ Debug.Assert(leftBits != null && rightBits != null);
+
if (BigIntegerCalculator.Compare(leftBits, rightBits) < 0)
{
uint[] bits = BigIntegerCalculator.Subtract(rightBits, leftBits);
value.AssertValid();
int sign = value._sign;
- uint[] bits = value._bits;
+ uint[]? bits = value._bits;
if (bits == null)
return sign;
if (trivialLeft)
{
+ Debug.Assert(right._bits != null);
uint[] bits = BigIntegerCalculator.Multiply(right._bits, NumericsHelpers.Abs(left._sign));
return new BigInteger(bits, (left._sign < 0) ^ (right._sign < 0));
}
if (trivialRight)
{
+ Debug.Assert(left._bits != null);
uint[] bits = BigIntegerCalculator.Multiply(left._bits, NumericsHelpers.Abs(right._sign));
return new BigInteger(bits, (left._sign < 0) ^ (right._sign < 0));
}
+ Debug.Assert(left._bits != null && right._bits != null);
+
if (left._bits == right._bits)
{
uint[] bits = BigIntegerCalculator.Square(left._bits);
if (trivialDivisor)
{
+ Debug.Assert(dividend._bits != null);
uint[] bits = BigIntegerCalculator.Divide(dividend._bits, NumericsHelpers.Abs(divisor._sign));
return new BigInteger(bits, (dividend._sign < 0) ^ (divisor._sign < 0));
}
+ Debug.Assert(dividend._bits != null && divisor._bits != null);
+
if (dividend._bits.Length < divisor._bits.Length)
{
return s_bnZeroInt;
if (trivialDivisor)
{
+ Debug.Assert(dividend._bits != null);
uint remainder = BigIntegerCalculator.Remainder(dividend._bits, NumericsHelpers.Abs(divisor._sign));
return dividend._sign < 0 ? -1 * remainder : remainder;
}
+ Debug.Assert(dividend._bits != null && divisor._bits != null);
+
if (dividend._bits.Length < divisor._bits.Length)
{
return dividend;
using System.Buffers;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
}
- internal static bool TryValidateParseStyleInteger(NumberStyles style, out ArgumentException e)
+ internal static bool TryValidateParseStyleInteger(NumberStyles style, [NotNullWhen(false)] out ArgumentException? e)
{
// Check for undefined flags
if ((style & InvalidNumberStyles) != 0)
return true;
}
- internal static bool TryParseBigInteger(string value, NumberStyles style, NumberFormatInfo info, out BigInteger result)
+ internal static bool TryParseBigInteger(string? value, NumberStyles style, NumberFormatInfo info, out BigInteger result)
{
if (value == null)
{
unsafe
{
result = BigInteger.Zero;
- ArgumentException e;
+ ArgumentException? e;
if (!TryValidateParseStyleInteger(style, out e))
throw e; // TryParse still throws ArgumentException on invalid NumberStyles
internal static BigInteger ParseBigInteger(ReadOnlySpan<char> value, NumberStyles style, NumberFormatInfo info)
{
- ArgumentException e;
+ ArgumentException? e;
if (!TryValidateParseStyleInteger(style, out e))
throw e;
return (char)0; // Custom format
}
- private static string FormatBigIntegerToHex(bool targetSpan, BigInteger value, char format, int digits, NumberFormatInfo info, Span<char> destination, out int charsWritten, out bool spanSuccess)
+ private static string? FormatBigIntegerToHex(bool targetSpan, BigInteger value, char format, int digits, NumberFormatInfo info, Span<char> destination, out int charsWritten, out bool spanSuccess)
{
Debug.Assert(format == 'x' || format == 'X');
// Get the bytes that make up the BigInteger.
- byte[] arrayToReturnToPool = null;
+ byte[]? arrayToReturnToPool = null;
Span<byte> bits = stackalloc byte[64]; // arbitrary threshold
if (!value.TryWriteOrCountBytes(bits, out int bytesWrittenOrNeeded))
{
}
}
- internal static string FormatBigInteger(BigInteger value, string format, NumberFormatInfo info)
+ internal static string FormatBigInteger(BigInteger value, string? format, NumberFormatInfo info)
{
- return FormatBigInteger(targetSpan: false, value, format, format, info, default, out _, out _);
+ return FormatBigInteger(targetSpan: false, value, format, format, info, default, out _, out _)!;
}
internal static bool TryFormatBigInteger(BigInteger value, ReadOnlySpan<char> format, NumberFormatInfo info, Span<char> destination, out int charsWritten)
return spanSuccess;
}
- private static string FormatBigInteger(
+ private static string? FormatBigInteger(
bool targetSpan, BigInteger value,
- string formatString, ReadOnlySpan<char> formatSpan,
+ string? formatString, ReadOnlySpan<char> formatSpan,
NumberFormatInfo info, Span<char> destination, out int charsWritten, out bool spanSuccess)
{
Debug.Assert(formatString == null || formatString.Length == formatSpan.Length);