Skip to content

Commit

Permalink
code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroupc committed Feb 2, 2025
1 parent 563b450 commit 915733f
Show file tree
Hide file tree
Showing 60 changed files with 2,848 additions and 2,767 deletions.
5 changes: 0 additions & 5 deletions Numbers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test20", "Test20\Test20.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test40", "Test40\Test40.csproj", "{00EB31B6-A805-4EFB-A64B-9F8176B2A1CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrimProgram", "TrimProgram\TrimProgram.csproj", "{2737f981-8aaf-414d-aaaf-56d7804bfcce}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -74,10 +73,6 @@ Global
{00EB31B6-A805-4EFB-A64B-9F8176B2A1CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00EB31B6-A805-4EFB-A64B-9F8176B2A1CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00EB31B6-A805-4EFB-A64B-9F8176B2A1CC}.Release|Any CPU.Build.0 = Release|Any CPU
{2737f981-8aaf-414d-aaaf-56d7804bfcce}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2737f981-8aaf-414d-aaaf-56d7804bfcce}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2737f981-8aaf-414d-aaaf-56d7804bfcce}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2737f981-8aaf-414d-aaaf-56d7804bfcce}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 3 additions & 3 deletions Numbers/Numbers.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk='Microsoft.NET.Sdk'>

<PropertyGroup>
<TargetFrameworks>netstandard2.0; net9.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0; net6.0</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>1.9</Version>
Expand Down Expand Up @@ -47,7 +47,7 @@ Version 1.8
<PropertyGroup Condition=' &apos;$(Configuration)&apos;==&apos;Release&apos; '>
<DebugType>none</DebugType>
<DocumentationFile>bin\Release\netstandard2.0\Numbers.xml</DocumentationFile>
<AssemblyOriginatorKeyFile>PeterO.snk</AssemblyOriginatorKeyFile>
<PublicSign>true</PublicSign><AssemblyOriginatorKeyFile>PeterO.snk</AssemblyOriginatorKeyFile>
<CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet></PropertyGroup>

<ItemGroup>
Expand All @@ -56,4 +56,4 @@ Version 1.8
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<AdditionalFiles Include='stylecop.json'/><AdditionalFiles Include='rules.ruleset'/><PackageReference Include='StyleCop.Analyzers' PrivateAssets='All' Version='1.2.0-beta.354'/><!-- PackageReference Include='Microsoft.CodeAnalysis.NetAnalyzers' PrivateAssets='All' Version='9.0.0-preview.24454.1' --></ItemGroup></Project>
<AdditionalFiles Include='stylecop.json'/><AdditionalFiles Include='rules.ruleset'/><PackageReference Include='StyleCop.Analyzers' PrivateAssets='All' Version='1.2.0-beta.354'/><PackageReference Include='Microsoft.CodeAnalysis.NetAnalyzers' PrivateAssets='All' Version='9.0.0-preview.24454.1'/></ItemGroup></Project>
28 changes: 14 additions & 14 deletions Numbers/PeterO/DebugUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Any copyright to this work is released to the Public Domain.
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
// Use directives rather than the Conditional attribute,
// to avoid the chance of logging statements leaking in release builds
// to avoid the chance of logging statements leaking in release builds
#if DEBUGLOG
namespace PeterO {
internal static class DebugUtility {
Expand All @@ -29,13 +29,13 @@ private static MethodInfo GetTypeMethod(
Type t,
string name,
Type[] parameters) {
#if NET40 || NET20
return t.GetMethod(name, new[] { parameter });
#else
{
#if NET40 || NET20
return t.GetMethod(name, new[] { parameter });
#else
{
return t?.GetRuntimeMethod(name, parameters);
}
#endif
#endif
}

// [RequiresUnreferencedCode("Do not use in AOT or reflection-free
Expand All @@ -48,20 +48,20 @@ public static void Log(string str) {
wr = writer;
}
if (wr != null) {
#if !NET20 && !NET40
#if !NET20 && !NET40
System.Diagnostics.Debug.WriteLine(str);
#endif
#endif
wr(str);
return;
} else {
#if !NET20 && !NET40
#if !NET20 && !NET40
System.Diagnostics.Debug.WriteLine(str);
return;
#else
{
throw new NotSupportedException("System.Console not found");
}
#endif
#else
{
throw new NotSupportedException("System.Console not found");
}
#endif
}
}
Type[] types = new[] { typeof(string) };
Expand Down
26 changes: 13 additions & 13 deletions Numbers/PeterO/Numbers/BitShiftAccumulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public FastInteger GetDigitLength() {
}

public FastInteger OverestimateDigitLength() {
return this.GetDigitLength();
return this.GetDigitLength();
}

private static void VerifyKnownLength() {
Expand All @@ -55,7 +55,7 @@ public void ShiftToDigits(
}
if (preShift != null && preShift.Sign > 0) {
this.knownBitLength = this.knownBitLength ?? this.CalcKnownBitLength();
// DebugUtility.Log("bits=" + bits + " pre=" + preShift + " known=" +
// Console.WriteLine("bits=" + bits + " pre=" + preShift + " known=" +
// (//kbl) + " [" + this.shiftedBigInt + "]");
if (this.knownBitLength.CompareTo(bits) <= 0) {
// Known digit length is already small enough
Expand All @@ -67,7 +67,7 @@ public void ShiftToDigits(
} else {
FastInteger bitDiff = this.knownBitLength.Copy()
.Subtract(bits);
// DebugUtility.Log("bitDiff=" + bitDiff);
// Console.WriteLine("bitDiff=" + bitDiff);
int cmp = bitDiff.CompareTo(preShift);
if (cmp <= 0) {
// NOTE: For BitShiftAccumulator, truncating and shifting
Expand Down Expand Up @@ -123,7 +123,7 @@ public FastInteger ShiftedIntFast
public int ShiftedIntMod(int mod) {
if (mod < 1) {
throw new ArgumentException("mod (" + mod +
") is not greater or equal to 1");
") is not greater or equal to 1");
}
switch (mod) {
case 1:
Expand Down Expand Up @@ -263,7 +263,7 @@ private void ShiftRightBig(int bits) {
// the last one is set
this.bitsAfterLeftmost |= 1;
this.bitLeftmost = this.shiftedBigInt.GetSignedBit(bs - 1) ? 1 :
0;
0;
} else if (lowestSetBit.CompareTo(bs - 1) > 0) {
// Means all discarded bits are zero
this.bitLeftmost = 0;
Expand All @@ -277,7 +277,7 @@ private void ShiftRightBig(int bits) {
// the last one is set
this.bitsAfterLeftmost |= 1;
this.bitLeftmost = this.shiftedBigInt.GetSignedBit(bs - 1) ? 1 :
0;
0;
} else if (lowestSet > bs - 1) {
// Means all discarded bits are zero
this.bitLeftmost = 0;
Expand Down Expand Up @@ -314,12 +314,12 @@ private FastInteger CalcKnownBitLength() {
return new FastInteger(kb);
}
if (this.shiftedBigInt.IsZero) {
{ return new FastInteger(1);
{ return new FastInteger(1);
}
}
}
long sbe = this.shiftedBigInt.GetSignedBitLengthAsInt64();
return (sbe < Int32.MaxValue) ? new FastInteger((int)sbe) :
FastInteger.FromBig(this.shiftedBigInt.GetSignedBitLengthAsEInteger());
FastInteger.FromBig(this.shiftedBigInt.GetSignedBitLengthAsEInteger());
}

private void ShiftBigToBits(int bits) {
Expand Down Expand Up @@ -368,7 +368,7 @@ private void ShiftBigToBits(int bits) {
// the last one is set
this.bitsAfterLeftmost |= 1;
this.bitLeftmost = this.shiftedBigInt.GetSignedBit(bs - 1) ? 1 :
0;
0;
} else if (lowestSetBit.CompareTo(bs - 1) > 0) {
// Means all discarded bits are zero
this.bitLeftmost = 0;
Expand All @@ -382,7 +382,7 @@ private void ShiftBigToBits(int bits) {
// the last one is set
this.bitsAfterLeftmost |= 1;
this.bitLeftmost = this.shiftedBigInt.GetSignedBit(bs - 1) ? 1 :
0;
0;
} else if (lowestSet > bs - 1) {
// Means all discarded bits are zero
this.bitLeftmost = 0;
Expand Down Expand Up @@ -441,7 +441,7 @@ private void ShiftRightSmall(int bits) {
this.bitsAfterLeftmost |= this.bitLeftmost;
// Get the bottommost shift minus 1 bits
this.bitsAfterLeftmost |= (shift > 1 && (this.shiftedSmall <<
(SmallBitLength - shift + 1)) != 0) ? 1 : 0;
(SmallBitLength - shift + 1)) != 0) ? 1 : 0;
// Get the bit just above that bit
this.bitLeftmost = (int)((this.shiftedSmall >> (shift - 1)) & 0x01);
this.shiftedSmall >>= shift;
Expand Down Expand Up @@ -483,7 +483,7 @@ private void ShiftSmallToBits(int bits) {
this.bitsAfterLeftmost |= this.bitLeftmost;
// Get the bottommost shift minus 1 bits
this.bitsAfterLeftmost |= (shift > 1 && (this.shiftedSmall <<
(SmallBitLength - shift + 1)) != 0) ? 1 : 0;
(SmallBitLength - shift + 1)) != 0) ? 1 : 0;
// Get the bit just above that bit
this.bitLeftmost = (int)((this.shiftedSmall >> (shift - 1)) & 0x01);
this.bitsAfterLeftmost = (this.bitsAfterLeftmost != 0) ? 1 : 0;
Expand Down
Loading

0 comments on commit 915733f

Please sign in to comment.