diff --git a/src/libraries/Common/src/System/Number.Parsing.Common.cs b/src/libraries/Common/src/System/Number.Parsing.Common.cs index ac8684a27bf7f..72a89f62ea567 100644 --- a/src/libraries/Common/src/System/Number.Parsing.Common.cs +++ b/src/libraries/Common/src/System/Number.Parsing.Common.cs @@ -299,7 +299,7 @@ private static bool TrailingZeros(ReadOnlySpan value, int index) => // For compatibility, we need to allow trailing zeros at the end of a number string value.Slice(index).IndexOfAnyExcept('\0') < 0; - internal static bool IsWhite(int ch) => ch == 0x20 || (uint)(ch - 0x09) <= (0x0D - 0x09); + private static bool IsWhite(int ch) => ch == 0x20 || (uint)(ch - 0x09) <= (0x0D - 0x09); private static bool IsDigit(int ch) => ((uint)ch - '0') <= 9; diff --git a/src/libraries/System.Runtime.Numerics/src/System.Runtime.Numerics.csproj b/src/libraries/System.Runtime.Numerics/src/System.Runtime.Numerics.csproj index 189679860ded9..4956f67d19be4 100644 --- a/src/libraries/System.Runtime.Numerics/src/System.Runtime.Numerics.csproj +++ b/src/libraries/System.Runtime.Numerics/src/System.Runtime.Numerics.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigNumber.cs b/src/libraries/System.Runtime.Numerics/src/System/Number.BigInteger.cs similarity index 98% rename from src/libraries/System.Runtime.Numerics/src/System/Numerics/BigNumber.cs rename to src/libraries/System.Runtime.Numerics/src/System/Number.BigInteger.cs index af0fd8a4cd802..e3f2827495a91 100644 --- a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigNumber.cs +++ b/src/libraries/System.Runtime.Numerics/src/System/Number.BigInteger.cs @@ -274,12 +274,13 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Numerics; using System.Runtime.InteropServices; using System.Text; -namespace System.Numerics +namespace System { - internal static class BigNumber + internal static partial class Number { private const NumberStyles InvalidNumberStyles = ~(NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingSign @@ -289,13 +290,6 @@ internal static class BigNumber private static ReadOnlySpan UInt32PowersOfTen => new uint[] { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; - internal enum ParsingStatus - { - OK, - Failed, - Overflow - } - [DoesNotReturn] internal static void ThrowOverflowOrFormatException(ParsingStatus status) => throw GetException(status); @@ -360,9 +354,9 @@ internal static unsafe ParsingStatus TryParseBigIntegerNumber(ReadOnlySpan fixed (byte* ptr = buffer) // NumberBuffer expects pinned span { - Number.NumberBuffer number = new Number.NumberBuffer(Number.NumberBufferKind.Integer, buffer); + NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, buffer); - if (!Number.TryStringToNumber(value, style, ref number, info)) + if (!TryStringToNumber(value, style, ref number, info)) { result = default; ret = ParsingStatus.Failed; @@ -406,7 +400,7 @@ internal static ParsingStatus TryParseBigIntegerHexNumberStyle(ReadOnlySpan= 0; whiteIndex--) { - if (!Number.IsWhite(value[whiteIndex])) + if (!IsWhite(value[whiteIndex])) break; } @@ -538,7 +532,7 @@ internal static ParsingStatus TryParseBigIntegerHexNumberStyle(ReadOnlySpan stackBuffer = stackalloc uint[BigIntegerCalculator.StackAllocThreshold]; Span currentBuffer = stackBuffer; @@ -662,7 +656,7 @@ bool ProcessChunk(ReadOnlySpan chunkDigits, ref Span currentBuffer) } } - ParsingStatus DivideAndConquer(ref Number.NumberBuffer number, out BigInteger result) + ParsingStatus DivideAndConquer(ref NumberBuffer number, out BigInteger result) { Span currentBuffer; int[]? arrayFromPoolForMultiplier = null; diff --git a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs b/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs index 21390d384c7b6..f354f871a5521 100644 --- a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs +++ b/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs @@ -691,7 +691,7 @@ public static bool TryParse([NotNullWhen(true)] string? value, NumberStyles styl public static BigInteger Parse(ReadOnlySpan value, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null) { - return BigNumber.ParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider)); + return Number.ParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider)); } public static bool TryParse(ReadOnlySpan value, out BigInteger result) @@ -701,7 +701,7 @@ public static bool TryParse(ReadOnlySpan value, out BigInteger result) public static bool TryParse(ReadOnlySpan value, NumberStyles style, IFormatProvider? provider, out BigInteger result) { - return BigNumber.TryParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider), out result) == BigNumber.ParsingStatus.OK; + return Number.TryParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider), out result) == Number.ParsingStatus.OK; } public static int Compare(BigInteger left, BigInteger right) @@ -1570,22 +1570,22 @@ private int WriteTo(Span buffer) public override string ToString() { - return BigNumber.FormatBigInteger(this, null, NumberFormatInfo.CurrentInfo); + return Number.FormatBigInteger(this, null, NumberFormatInfo.CurrentInfo); } public string ToString(IFormatProvider? provider) { - return BigNumber.FormatBigInteger(this, null, NumberFormatInfo.GetInstance(provider)); + return Number.FormatBigInteger(this, null, NumberFormatInfo.GetInstance(provider)); } public string ToString([StringSyntax(StringSyntaxAttribute.NumericFormat)] string? format) { - return BigNumber.FormatBigInteger(this, format, NumberFormatInfo.CurrentInfo); + return Number.FormatBigInteger(this, format, NumberFormatInfo.CurrentInfo); } public string ToString([StringSyntax(StringSyntaxAttribute.NumericFormat)] string? format, IFormatProvider? provider) { - return BigNumber.FormatBigInteger(this, format, NumberFormatInfo.GetInstance(provider)); + return Number.FormatBigInteger(this, format, NumberFormatInfo.GetInstance(provider)); } private string DebuggerDisplay @@ -1645,7 +1645,7 @@ private string DebuggerDisplay public bool TryFormat(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.NumericFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) { - return BigNumber.TryFormatBigInteger(this, format, NumberFormatInfo.GetInstance(provider), destination, out charsWritten); + return Number.TryFormatBigInteger(this, format, NumberFormatInfo.GetInstance(provider), destination, out charsWritten); } private static BigInteger Add(ReadOnlySpan leftBits, int leftSign, ReadOnlySpan rightBits, int rightSign) diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs index 533d3c623df4d..a2306851c2816 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs @@ -490,7 +490,7 @@ public static void ToString_InvalidFormat_ThrowsFormatException() Assert.Throws(() => b.ToString("E1000000000")); Assert.Throws(() => b.ToString("E000001000000000")); - // Check ParseFormatSpecifier in BigNumber.cs with `G` format + // Check ParseFormatSpecifier in Number.BigInteger.cs with `G` format Assert.Throws(() => b.ToString("G" + int.MaxValue.ToString())); Assert.Throws(() => b.ToString("G" + intMaxPlus1String)); Assert.Throws(() => b.ToString("G4772185890")); @@ -510,7 +510,7 @@ public static void ToString_ValidLargeFormat() b.ToString("E999999999"); // Should not throw b.ToString("E00000999999999"); // Should not throw - // Check ParseFormatSpecifier in BigNumber.cs with `G` format + // Check ParseFormatSpecifier in Number.BigInteger.cs with `G` format b.ToString("G999999999"); // Should not throw b.ToString("G00000999999999"); // Should not throw }