From 77daa1a1b3aab5dba05893b7e3c216ff266823e2 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Mon, 17 Sep 2018 14:29:49 -0700 Subject: [PATCH] Fixing some naming conventions and removing dead code. --- .../shared/System/Number.BigInteger.cs | 32 +++++++++++----------- .../shared/System/Number.Formatting.cs | 2 +- .../shared/System/Number.Grisu3.cs | 14 +++++----- src/classlibnative/bcltype/number.cpp | 3 -- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Number.BigInteger.cs b/src/System.Private.CoreLib/shared/System/Number.BigInteger.cs index 877030c..4d3e887 100644 --- a/src/System.Private.CoreLib/shared/System/Number.BigInteger.cs +++ b/src/System.Private.CoreLib/shared/System/Number.BigInteger.cs @@ -15,7 +15,7 @@ namespace System { private const int MaxBlockCount = 35; - private static readonly uint[] Pow10UInt32Table = new uint[] + private static readonly uint[] s_Pow10UInt32Table = new uint[] { 1, // 10^0 10, // 10^1 @@ -27,7 +27,7 @@ namespace System 10000000, // 10^7 }; - private static readonly int[] Pow10BigNumTableIndices = new int[] + private static readonly int[] s_s_Pow10BigNumTableIndices = new int[] { 0, // 10^8 2, // 10^16 @@ -37,7 +37,7 @@ namespace System 33, // 10^256 }; - private static readonly uint[] Pow10BigNumTable = new uint[] + private static readonly uint[] s_Pow10BigNumTable = new uint[] { // 10^8 1, // _length @@ -123,7 +123,7 @@ namespace System 0x00000000, }; - private static readonly uint[] MultiplyDeBruijnBitPosition = new uint[] + private static readonly uint[] s_MultiplyDeBruijnBitPosition = new uint[] { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 @@ -161,7 +161,7 @@ namespace System mask |= (mask >> 16); uint index = (mask * 0x07C4ACDD) >> 27; - return MultiplyDeBruijnBitPosition[(int)(index)]; + return s_MultiplyDeBruijnBitPosition[(int)(index)]; } public static int Compare(ref BigInteger lhs, ref BigInteger rhs) @@ -367,7 +367,7 @@ namespace System Debug.Assert(unchecked((uint)(maxResultLength)) <= MaxBlockCount); // Zero out result internal blocks. - Buffer.ZeroMemory((byte*)(result._blocks.GetPointer()), (MaxBlockCount * sizeof(uint))); + Buffer.ZeroMemory((byte*)(result._blocks.GetPointer()), (maxResultLength * sizeof(uint))); int smallIndex = 0; int resultStartIndex = 0; @@ -412,33 +412,33 @@ namespace System public static void Pow10(uint exponent, ref BigInteger result) { - // We leverage two arrays - Pow10UInt32Table and Pow10BigNumTable to speed up the Pow10 calculation. + // We leverage two arrays - s_Pow10UInt32Table and s_Pow10BigNumTable to speed up the Pow10 calculation. // - // Pow10UInt32Table stores the results of 10^0 to 10^7. - // Pow10BigNumTable stores the results of 10^8, 10^16, 10^32, 10^64, 10^128 and 10^256. + // s_Pow10UInt32Table stores the results of 10^0 to 10^7. + // s_Pow10BigNumTable stores the results of 10^8, 10^16, 10^32, 10^64, 10^128 and 10^256. // // For example, let's say exp = 0b111111. We can split the exp to two parts, one is small exp, // which 10^smallExp can be represented as uint, another part is 10^bigExp, which must be represented as BigNum. // So the result should be 10^smallExp * 10^bigExp. // - // Calculating 10^smallExp is simple, we just lookup the 10^smallExp from Pow10UInt32Table. + // Calculating 10^smallExp is simple, we just lookup the 10^smallExp from s_Pow10UInt32Table. // But here's a bad news: although uint can represent 10^9, exp 9's binary representation is 1001. // That means 10^(1011), 10^(1101), 10^(1111) all cannot be stored as uint, we cannot easily say something like: - // "Any bits <= 3 is small exp, any bits > 3 is big exp". So instead of involving 10^8, 10^9 to Pow10UInt32Table, - // consider 10^8 and 10^9 as a bigNum, so they fall into Pow10BigNumTable. Now we can have a simple rule: + // "Any bits <= 3 is small exp, any bits > 3 is big exp". So instead of involving 10^8, 10^9 to s_Pow10UInt32Table, + // consider 10^8 and 10^9 as a bigNum, so they fall into s_Pow10BigNumTable. Now we can have a simple rule: // "Any bits <= 3 is small exp, any bits > 3 is big exp". // // For 0b111111, we first calculate 10^(smallExp), which is 10^(7), now we can shift right 3 bits, prepare to calculate the bigExp part, // the exp now becomes 0b000111. // - // Apparently the lowest bit of bigExp should represent 10^8 because we have already shifted 3 bits for smallExp, so Pow10BigNumTable[0] = 10^8. + // Apparently the lowest bit of bigExp should represent 10^8 because we have already shifted 3 bits for smallExp, so s_Pow10BigNumTable[0] = 10^8. // Now let's shift exp right 1 bit, the lowest bit should represent 10^(8 * 2) = 10^16, and so on... // - // That's why we just need the values of Pow10BigNumTable be power of 2. + // That's why we just need the values of s_Pow10BigNumTable be power of 2. // // More details of this implementation can be found at: https://github.com/dotnet/coreclr/pull/12894#discussion_r128890596 - BigInteger temp1 = new BigInteger(Pow10UInt32Table[exponent & 0x7]); + BigInteger temp1 = new BigInteger(s_Pow10UInt32Table[exponent & 0x7]); ref BigInteger lhs = ref temp1; BigInteger temp2 = new BigInteger(0); @@ -453,7 +453,7 @@ namespace System if ((exponent & 1) != 0) { // Multiply into the next temporary - ref BigInteger rhs = ref *(BigInteger*)(Unsafe.AsPointer(ref Pow10BigNumTable[Pow10BigNumTableIndices[index]])); + ref BigInteger rhs = ref *(BigInteger*)(Unsafe.AsPointer(ref s_Pow10BigNumTable[s_s_Pow10BigNumTableIndices[index]])); Multiply(ref lhs, ref rhs, ref product); // Swap to the next temporary diff --git a/src/System.Private.CoreLib/shared/System/Number.Formatting.cs b/src/System.Private.CoreLib/shared/System/Number.Formatting.cs index c397748..1343686 100644 --- a/src/System.Private.CoreLib/shared/System/Number.Formatting.cs +++ b/src/System.Private.CoreLib/shared/System/Number.Formatting.cs @@ -2290,7 +2290,7 @@ SkipRounding: { number.precision = precision; - if (double.GetExponent(value) == 0x7FF) + if (!double.IsFinite(value)) { number.scale = double.IsNaN(value) ? ScaleNAN : ScaleINF; number.sign = double.IsNegative(value); diff --git a/src/System.Private.CoreLib/shared/System/Number.Grisu3.cs b/src/System.Private.CoreLib/shared/System/Number.Grisu3.cs index 5e9a444..7d991a6 100644 --- a/src/System.Private.CoreLib/shared/System/Number.Grisu3.cs +++ b/src/System.Private.CoreLib/shared/System/Number.Grisu3.cs @@ -24,7 +24,7 @@ namespace System private const uint Ten8 = 100000000; private const uint Ten9 = 1000000000; - private static readonly short[] CachedPowerBinaryExponents = new short[] + private static readonly short[] s_CachedPowerBinaryExponents = new short[] { -1220, -1193, @@ -115,7 +115,7 @@ namespace System 1066, }; - private static readonly short[] CachedPowerDecimalExponents = new short[] + private static readonly short[] s_CachedPowerDecimalExponents = new short[] { PowerMinDecimalExponent, -340, @@ -206,7 +206,7 @@ namespace System PowerMaxDecimalExponent, }; - private static readonly uint[] CachedPowerOfTen = new uint[] + private static readonly uint[] s_CachedPowerOfTen = new uint[] { 1, // 10^0 10, // 10^1 @@ -220,7 +220,7 @@ namespace System 1000000000, // 10^9 }; - private static readonly ulong[] CachedPowerSignificands = new ulong[] + private static readonly ulong[] s_CachedPowerSignificands = new ulong[] { 0xFA8FD5A0081C0288, 0xBAAEE17FA23EBF76, @@ -545,8 +545,8 @@ namespace System private static void CachedPower(int k, out DiyFp cmk, out int decimalExponent) { int index = ((PowerOffset + k - 1) / PowerDecimalExponentDistance) + 1; - cmk = new DiyFp(CachedPowerSignificands[index], CachedPowerBinaryExponents[index]); - decimalExponent = CachedPowerDecimalExponents[index]; + cmk = new DiyFp(s_CachedPowerSignificands[index], s_CachedPowerBinaryExponents[index]); + decimalExponent = s_CachedPowerDecimalExponents[index]; } private static bool DigitGen(ref DiyFp mp, int precision, char* digits, out int length, out int k) @@ -582,7 +582,7 @@ namespace System // - When requested digit count >= 11, p1 is not be able to exhaust the count as 10^(11 - 1) > uint.MaxValue >= p1. // - When p1 < 10^(count - 1), p1 is not be able to exhaust the count. // - Otherwise, p1 may have chance to exhaust the count. - if ((p2 == 0) && ((precision >= 11) || (p1 < CachedPowerOfTen[precision - 1]))) + if ((p2 == 0) && ((precision >= 11) || (p1 < s_CachedPowerOfTen[precision - 1]))) { length = 0; k = 0; diff --git a/src/classlibnative/bcltype/number.cpp b/src/classlibnative/bcltype/number.cpp index 433a918..8fe62eb 100644 --- a/src/classlibnative/bcltype/number.cpp +++ b/src/classlibnative/bcltype/number.cpp @@ -12,9 +12,6 @@ typedef wchar_t wchar; -#define SCALE_NAN 0x80000000 -#define SCALE_INF 0x7FFFFFFF - /*=========================================================== Portable NumberToDouble implementation -------------------------------------- -- 2.7.4