Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3a85f20
Convert Number.BigInteger.cs from uint limbs to nuint limbs
stephentoub Mar 17, 2026
95f6d3c
Convert BigInteger internal representation from uint to nuint limbs
stephentoub Mar 17, 2026
7a8770c
Fix SubWithBorrow sign-extension bug on 32-bit and update stale comments
stephentoub Mar 17, 2026
5255f85
Use branchless underflow detection in SubtractDivisor
stephentoub Mar 17, 2026
bf3328d
Fuse two's complement conversion with bitwise AND/OR/XOR
stephentoub Mar 17, 2026
71968ac
Cache PowersOf1e9 table for repeated ToString/Parse calls
stephentoub Mar 17, 2026
2fd9896
Tune Burnikel-Ziegler division threshold for 64-bit limbs
stephentoub Mar 17, 2026
2109128
Add property-based validation tests and fix BitwiseAnd sign bug
stephentoub Mar 18, 2026
defa53d
Add edge-case tests for sign combos, SIMD boundaries, and coverage gaps
stephentoub Mar 18, 2026
2b0b385
Add Montgomery multiplication for ModPow with odd moduli
stephentoub Mar 18, 2026
3333cec
Add tests for Barrett+FastReducer with even large moduli
stephentoub Mar 18, 2026
2c9b356
Add sliding window exponentiation and separate squaring thresholds
stephentoub Mar 18, 2026
1323037
Avoid array copy in GCD when one operand is zero
stephentoub Mar 18, 2026
bf16170
Optimize GCD LehmerCore and DivRem to avoid Int128/UInt128 overhead
stephentoub Mar 18, 2026
16024df
Fix ToString Naive loop regression by processing 32-bit halves
stephentoub Mar 18, 2026
c09c5ff
Fix small-operand, GCD LehmerCore, and ToByteArray regressions
stephentoub Mar 18, 2026
c3fc756
Add unrolled Mul1/MulAdd1/SubMul1 primitives for multiply and divisio…
stephentoub Mar 18, 2026
52dc799
Replace Unsafe.Add with span indexing using bounds hints for JIT elision
stephentoub Mar 19, 2026
db7bb90
Use hardware intrinsics for BigMul, DivRem, and AddWithCarry primitives
stephentoub Mar 19, 2026
2990b90
Revert _sign from nint to int to eliminate small-value regressions
stephentoub Mar 19, 2026
60a0281
Use ulong arithmetic in PowCore when modulus fits in uint
stephentoub Mar 19, 2026
3dbb09e
Clean up formatting / style
stephentoub Mar 19, 2026
d480a31
Fix SubtractSelf callers to restore borrow==0 postcondition
stephentoub Mar 19, 2026
69bdfb5
Address PR feedback
stephentoub Mar 20, 2026
3c7b88c
Address feedback
stephentoub Mar 20, 2026
23ee9c7
Fix GetSignBitsIfValid XML doc to clarify 'valid hex digit and consid…
stephentoub Mar 20, 2026
79c944d
Add comment explaining nuint[] for base-1e9 intermediate representation
stephentoub Mar 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/libraries/Common/src/System/Number.Formatting.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ internal static char ParseFormatSpecifier(ReadOnlySpan<char> format, out int dig

internal static unsafe void NumberToString<TChar>(ref ValueListBuilder<TChar> vlb, ref NumberBuffer number, char format, int nMaxDigits, NumberFormatInfo info) where TChar : unmanaged, IUtfChar<TChar>
{
Debug.Assert(sizeof(TChar) == sizeof(char) || sizeof(TChar) == sizeof(byte));
Debug.Assert(sizeof(TChar) is sizeof(char) or sizeof(byte));

number.CheckConsistency();
bool isCorrectlyRounded = (number.Kind == NumberBufferKind.FloatingPoint);
Expand Down Expand Up @@ -290,7 +290,7 @@ internal static unsafe void NumberToString<TChar>(ref ValueListBuilder<TChar> vl

internal static unsafe void NumberToStringFormat<TChar>(ref ValueListBuilder<TChar> vlb, ref NumberBuffer number, ReadOnlySpan<char> format, NumberFormatInfo info) where TChar : unmanaged, IUtfChar<TChar>
{
Debug.Assert(sizeof(TChar) == sizeof(char) || sizeof(TChar) == sizeof(byte));
Debug.Assert(sizeof(TChar) is sizeof(char) or sizeof(byte));

number.CheckConsistency();

Expand Down Expand Up @@ -684,7 +684,7 @@ internal static unsafe void NumberToStringFormat<TChar>(ref ValueListBuilder<TCh
vlb.Append(TChar.CastFrom(ch));
if (src < format.Length)
{
if (pFormat[src] == '+' || pFormat[src] == '-')
if (pFormat[src] is '+' or '-')
{
AppendUnknownChar(ref vlb, pFormat[src++]);
}
Expand Down Expand Up @@ -713,7 +713,7 @@ internal static unsafe void NumberToStringFormat<TChar>(ref ValueListBuilder<TCh

private static unsafe void FormatCurrency<TChar>(ref ValueListBuilder<TChar> vlb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info) where TChar : unmanaged, IUtfChar<TChar>
{
Debug.Assert(sizeof(TChar) == sizeof(char) || sizeof(TChar) == sizeof(byte));
Debug.Assert(sizeof(TChar) is sizeof(char) or sizeof(byte));

string fmt = number.IsNegative ?
s_negCurrencyFormats[info.CurrencyNegativePattern] :
Expand Down Expand Up @@ -747,7 +747,7 @@ private static unsafe void FormatFixed<TChar>(
int nMaxDigits, int[]? groupDigits,
ReadOnlySpan<TChar> sDecimal, ReadOnlySpan<TChar> sGroup) where TChar : unmanaged, IUtfChar<TChar>
{
Debug.Assert(sizeof(TChar) == sizeof(char) || sizeof(TChar) == sizeof(byte));
Debug.Assert(sizeof(TChar) is sizeof(char) or sizeof(byte));

int digPos = number.Scale;
byte* dig = number.DigitsPtr;
Expand Down Expand Up @@ -862,7 +862,7 @@ private static unsafe void FormatFixed<TChar>(
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe void AppendUnknownChar<TChar>(ref ValueListBuilder<TChar> vlb, char ch) where TChar : unmanaged, IUtfChar<TChar>
{
Debug.Assert(sizeof(TChar) == sizeof(char) || sizeof(TChar) == sizeof(byte));
Debug.Assert(sizeof(TChar) is sizeof(char) or sizeof(byte));

if (sizeof(TChar) == sizeof(char) || char.IsAscii(ch))
{
Expand All @@ -883,7 +883,7 @@ static void AppendNonAsciiBytes(ref ValueListBuilder<TChar> vlb, char ch)

private static unsafe void FormatNumber<TChar>(ref ValueListBuilder<TChar> vlb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info) where TChar : unmanaged, IUtfChar<TChar>
{
Debug.Assert(sizeof(TChar) == sizeof(char) || sizeof(TChar) == sizeof(byte));
Debug.Assert(sizeof(TChar) is sizeof(char) or sizeof(byte));

string fmt = number.IsNegative ?
s_negNumberFormats[info.NumberNegativePattern] :
Expand All @@ -910,7 +910,7 @@ private static unsafe void FormatNumber<TChar>(ref ValueListBuilder<TChar> vlb,

private static unsafe void FormatScientific<TChar>(ref ValueListBuilder<TChar> vlb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info, char expChar) where TChar : unmanaged, IUtfChar<TChar>
{
Debug.Assert(sizeof(TChar) == sizeof(char) || sizeof(TChar) == sizeof(byte));
Debug.Assert(sizeof(TChar) is sizeof(char) or sizeof(byte));

byte* dig = number.DigitsPtr;

Expand All @@ -932,7 +932,7 @@ private static unsafe void FormatScientific<TChar>(ref ValueListBuilder<TChar> v

private static unsafe void FormatExponent<TChar>(ref ValueListBuilder<TChar> vlb, NumberFormatInfo info, int value, char expChar, int minDigits, bool positiveSign) where TChar : unmanaged, IUtfChar<TChar>
{
Debug.Assert(sizeof(TChar) == sizeof(char) || sizeof(TChar) == sizeof(byte));
Debug.Assert(sizeof(TChar) is sizeof(char) or sizeof(byte));

vlb.Append(TChar.CastFrom(expChar));

Expand All @@ -956,7 +956,7 @@ private static unsafe void FormatExponent<TChar>(ref ValueListBuilder<TChar> vlb

private static unsafe void FormatGeneral<TChar>(ref ValueListBuilder<TChar> vlb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info, char expChar, bool suppressScientific) where TChar : unmanaged, IUtfChar<TChar>
{
Debug.Assert(sizeof(TChar) == sizeof(char) || sizeof(TChar) == sizeof(byte));
Debug.Assert(sizeof(TChar) is sizeof(char) or sizeof(byte));

int digPos = number.Scale;
bool scientific = false;
Expand Down Expand Up @@ -1010,7 +1010,7 @@ private static unsafe void FormatGeneral<TChar>(ref ValueListBuilder<TChar> vlb,

private static unsafe void FormatPercent<TChar>(ref ValueListBuilder<TChar> vlb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info) where TChar : unmanaged, IUtfChar<TChar>
{
Debug.Assert(sizeof(TChar) == sizeof(char) || sizeof(TChar) == sizeof(byte));
Debug.Assert(sizeof(TChar) is sizeof(char) or sizeof(byte));

string fmt = number.IsNegative ?
s_negPercentFormats[info.PercentNegativePattern] :
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Number.NumberBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public NumberBuffer(NumberBufferKind kind, Span<byte> digits)
public void CheckConsistency()
{
#if DEBUG
Debug.Assert((Kind == NumberBufferKind.Integer) || (Kind == NumberBufferKind.Decimal) || (Kind == NumberBufferKind.FloatingPoint));
Debug.Assert(Kind is NumberBufferKind.Integer or NumberBufferKind.Decimal or NumberBufferKind.FloatingPoint);
Debug.Assert(Digits[0] != '0', "Leading zeros should never be stored in a Number");

int numDigits;
Expand All @@ -89,7 +89,7 @@ public void CheckConsistency()
//
public override string ToString()
{
StringBuilder sb = new StringBuilder();
StringBuilder sb = new();

sb.Append('[');
sb.Append('"');
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/System/Number.Parsing.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ internal enum ParsingStatus
Overflow
}

private static bool IsSpaceReplacingChar(uint c) => (c == '\u00a0') || (c == '\u202f');
private static bool IsSpaceReplacingChar(uint c) => c is '\u00a0' or '\u202f';

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static uint NormalizeSpaceReplacingChar(uint c) => IsSpaceReplacingChar(c) ? '\u0020' : c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<ItemGroup>
<Compile Include="System\ThrowHelper.cs" />
<Compile Include="System\Numerics\BigIntegerCalculator.AddSub.cs" />
<Compile Include="System\Numerics\BigIntegerCalculator.Bitwise.cs" />
<Compile Include="System\Numerics\BigInteger.RentedBuffer.cs" />
<Compile Include="System\Numerics\BigIntegerCalculator.DivRem.cs" />
<Compile Include="System\Numerics\BigIntegerCalculator.FastReducer.cs" />
<Compile Include="System\Numerics\BigIntegerCalculator.GcdInv.cs" />
Expand Down
Loading
Loading