Skip to content

Commit

Permalink
version 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroupc committed Mar 20, 2020
1 parent 732e48a commit 0547603
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 115 deletions.
25 changes: 10 additions & 15 deletions Numbers.nuspec
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
<package
><metadata><version>1.5.1</version><id>PeterO.Numbers</id><requireLicenseAcceptance>false</requireLicenseAcceptance><releaseNotes>Version 1.5.1
><metadata><version>1.6.0</version><id>PeterO.Numbers</id><requireLicenseAcceptance>false</requireLicenseAcceptance><releaseNotes>Version 1.6.0

- Fix bugs in EDecimal.FromString and ERational.FromString involving substrings containing negative numbers.

Version 1.5.0

- Major performance improvements in certain number parsing and generating methods, including the FromString methods of EInteger, EDecimal, EFloat, and ERational, and the ToEFloat method of EDecimal, especially where they take an arithmetic context (EContext) that specifies a limited precision and exponent range.
- There were also performance improvements in digit count calculation and in rounding many-digit-long numbers.
- Add int overloads to EDecimal.Pow and EFloat.Pow.
- Add int overloads to several ERational methods.
- Add CompareTo overloads and CompareToValue (which implements current CompareTo) in EDecimal, EFloat, and ERational. In a future version, CompareTo&apos;s behavior might change to CompareToTotal in each of these classes. Also certain CompareTo* methods now have consistent behavior when they receive a null argument.
- ETrapException now has an Errors property that holds all errors that occur at the same time as the primary error.
- Fixed edge cases when ToShortestString might return an incorrect result.
- Fixed bug when some ETrapExceptions aren&apos;t thrown as they should.
- Other bug fixes.</releaseNotes><summary></summary><license type='expression'>CC0-1.0</license><projectUrl>https://github.com/peteroupc/Numbers</projectUrl><authors>Peter Occil</authors><description>A C# library that supports arbitrary-precision binary and decimal floating-point numbers and rational numbers with arbitrary-precision components, and supports arithmetic with these numbers.</description><owners>Peter Occil</owners><title>Arbitrary-Precision Number Library</title><tags>numbers arithmetic decimal math</tags><dependencies><group /></dependencies></metadata><files><file src='Numbers/bin/Release/netstandard1.0/Numbers.dll' target='/lib/netstandard1.0' /><file src='Numbers/bin/Release/netstandard1.0/Numbers.xml' target='/lib/netstandard1.0' /><file src='Numbers20/bin/Release/Numbers.dll' target='/lib/net20' /><file src='Numbers20/bin/Release/Numbers.xml' target='/lib/net20' /><file src='Numbers40/bin/Release/Numbers.dll' target='/lib/net40' /><file src='Numbers40/bin/Release/Numbers.xml' target='/lib/net40' /></files></package
>
- Numerous performance improvements in the EInteger, EDecimal, EFloat, and ERational classes. Among them is the use of caches for small EInteger, EDecimal, and EFloat values, and faster multiplication algorithms for large EIntegers.
- Correctness fixes to the Log() methods in EDecimal and EFloat
- New LogN() method in EDecimal and EFloat
- New methods in EInteger, including FromBytes, GetDigitCountAsEInteger, and DivRem(long)
- New ToSizedEInteger/ToSizedEIntegerIfExact/IsInteger methods in EDecimal, EFloat, and ERational
- New Create overloads in EFloat and ERational
- New Min and Max methods in EInteger and ERational
- Bug fixes</releaseNotes><summary></summary><license type='expression'>CC0-1.0</license><projectUrl>https://github.com/peteroupc/Numbers</projectUrl><authors>Peter Occil</authors><description>A C# library that supports arbitrary-precision binary and decimal floating-point numbers and rational numbers with arbitrary-precision components, and supports arithmetic with these numbers.</description><owners>Peter Occil</owners><title>Arbitrary-Precision Number Library</title><tags>numbers arithmetic decimal math</tags><dependencies><group /></dependencies></metadata><files><file src='Numbers/bin/Release/netstandard1.0/Numbers.dll' target='/lib/netstandard1.0' /><file src='Numbers/bin/Release/netstandard1.0/Numbers.xml' target='/lib/netstandard1.0' /><file src='Numbers20/bin/Release/Numbers.dll' target='/lib/net20' /><file src='Numbers20/bin/Release/Numbers.xml' target='/lib/net20' /><file src='Numbers40/bin/Release/Numbers.dll' target='/lib/net40' /><file src='Numbers40/bin/Release/Numbers.xml' target='/lib/net40' /></files></package
>
4 changes: 2 additions & 2 deletions Numbers/Numbers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ Version 1.6.0
<DebugType>full</DebugType>
<CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet></PropertyGroup>
<PropertyGroup Condition=' &apos;$(Configuration)|$(Platform)&apos; == &apos;Release|AnyCPU&apos; '>
<DebugType/>
<DebugType>none</DebugType>
<DocumentationFile>bin\Release\netstandard1.0\Numbers.xml</DocumentationFile>

<CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet></PropertyGroup>
<ItemGroup>

<AdditionalFiles Include='stylecop.json'/><AdditionalFiles Include='rules.ruleset'/><PackageReference Include='StyleCop.Analyzers' PrivateAssets='All' Version='1.2.0-beta.113'/><PackageReference Include='Microsoft.CodeAnalysis.FxCopAnalyzers' PrivateAssets='All' Version='2.9.8'/></ItemGroup>
<PropertyGroup/><PropertyGroup/> </Project>
<PropertyGroup/><PropertyGroup/> </Project>
17 changes: 13 additions & 4 deletions Numbers/PeterO/Numbers/DigitShiftAccumulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ public bool TruncateRightExact(FastInteger fastint) {
return (this.bitLeftmost | this.bitsAfterLeftmost) == 0;
}
if (!this.isSmall && !this.shiftedBigInt.CanFitInInt64()) {
if (this.shiftedBigInt == null) throw new InvalidOperationException();
#if DEBUG
if (this.shiftedBigInt == null) {
throw new InvalidOperationException();
}
#endif
int a = fastint.ToInt32();
if (a > 10) {
this.ShiftRightBig(10, true, true);
Expand Down Expand Up @@ -423,12 +427,16 @@ private void UpdateKnownLength(FastInteger digitsShiftedFast) {
}

private void ShiftRightBig(int digits, bool truncate, bool simple) {
if (this.shiftedBigInt == null) throw new InvalidOperationException();
#if DEBUG
if (this.shiftedBigInt == null) {
throw new InvalidOperationException();
}
#endif
if (digits <= 0) {
return;
}
// DebugUtility.Log("ShiftRightBig "+digits+" "+truncate+" "+
// simple+" "+this);
// simple+" "+this);
if (this.shiftedBigInt.IsZero) {
this.discardedDigitCount = this.discardedDigitCount ?? new
FastInteger(0);
Expand Down Expand Up @@ -585,7 +593,8 @@ private void ShiftRightBig(int digits, bool truncate, bool simple) {
EInteger[] divrem1 = sbi.DivRem(NumberUtility.FindPowerOfTen(
digits - 1));
EInteger[] divrem2 = divrem1[0].DivRem(10);
// DebugUtility.Log("divrem " + (// divrem1[0]) + " " + divrem1[1] + " / " + divrem2[0] + " " + (divrem2[1]));
// DebugUtility.Log("divrem " + (// divrem1[0]) + " " + divrem1[1] + " / " +
// divrem2[0] + " " + (divrem2[1]));
this.bitsAfterLeftmost |= this.bitLeftmost;
this.bitsAfterLeftmost |= divrem1[1].IsZero ? 0 : 1;
this.bitLeftmost = divrem2[1].ToInt32Checked();
Expand Down
37 changes: 28 additions & 9 deletions Numbers/PeterO/Numbers/EInteger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4372,7 +4372,7 @@ public EInteger Remainder(EInteger divisor) {
/// Thus, for negative values, the arbitrary-precision integer is
/// sign-extended.</summary>
/// <param name='eshift'>The number of bits to shift. Can be negative,
/// in which case this is the same as shiftLeft with the absolute value
/// in which case this is the same as ShiftLeft with the absolute value
/// of this parameter.</param>
/// <returns>An arbitrary-precision integer.</returns>
/// <exception cref='ArgumentNullException'>The parameter <paramref
Expand All @@ -4399,7 +4399,7 @@ public EInteger ShiftRight(EInteger eshift) {
/// value of 2 multiplies it by 4, a value of 3 by 8, a value of 4 by
/// 16, and so on.</summary>
/// <param name='eshift'>The number of bits to shift. Can be negative,
/// in which case this is the same as shiftRight with the absolute
/// in which case this is the same as ShiftRight with the absolute
/// value of this parameter.</param>
/// <returns>An arbitrary-precision integer.</returns>
/// <exception cref='ArgumentNullException'>The parameter <paramref
Expand Down Expand Up @@ -4437,18 +4437,37 @@ public EInteger ShiftLeft(int numberBits) {
this.ShiftRight(1).ShiftRight(Int32.MaxValue) :
this.ShiftRight(-numberBits);
}
var numWords = (int)this.wordCount;
int numWords = this.wordCount;
var shiftWords = (int)(numberBits >> 4);
var shiftBits = (int)(numberBits & 15);
if (!this.negative) {
var ret = new short[numWords + BitsToWords((int)numberBits)];
// Determine shifted integer's word count in advance;
// it's more cache-friendly to do so because the
// unshifted word has less memory
int lastWordBL = NumberUtility.BitLength(
(int)(this.words[this.wordCount - 1]) & 0xffff);
lastWordBL += shiftBits;
var newWordCount = 0;
if (lastWordBL <= 16) {
// New bit count is such that an additional word
// is not needed
newWordCount = numWords + shiftWords;
} else {
newWordCount = numWords + BitsToWords(numberBits);
}
var ret = new short[newWordCount];
Array.Copy(this.words, 0, ret, shiftWords, numWords);
ShiftWordsLeftByBits(
ret,
(int)shiftWords,
numWords + BitsToWords(shiftBits),
shiftWords,
newWordCount - shiftWords,
shiftBits);
return new EInteger(CountWords(ret), ret, false);
#if DEBUG
if (newWordCount <= 0 || ret[newWordCount - 1] == 0) {
throw new InvalidOperationException();
}
#endif
return new EInteger(newWordCount, ret, false);
} else {
var ret = new short[numWords + BitsToWords((int)numberBits)];
Array.Copy(this.words, ret, numWords);
Expand Down Expand Up @@ -8567,7 +8586,7 @@ private static void SchoolbookSquare(
private static short ShiftWordsLeftByBits(
short[] r,
int rstart,
int n,
int count,
int shiftBits) {
#if DEBUG
if (shiftBits >= 16) {
Expand All @@ -8579,7 +8598,7 @@ private static short ShiftWordsLeftByBits(
if (shiftBits != 0) {
int sb16 = 16 - shiftBits;
int rs = rstart;
for (var i = 0; i < n; ++i, ++rs) {
for (var i = 0; i < count; ++i, ++rs) {
u = r[rs];
r[rs] = unchecked((short)((u << shiftBits) | carry));
carry = (u & ShortMask) >> sb16;
Expand Down
6 changes: 3 additions & 3 deletions Numbers20/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Reflection;
[assembly: System.CLSCompliant(true)]
[assembly: AssemblyInformationalVersion("1.5.1")]
[assembly: AssemblyVersion("1.5.1.0")]
[assembly: AssemblyFileVersion("1.5.1.0")]
[assembly: AssemblyInformationalVersion("1.6.0")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyProduct("Arbitrary-Precision Number Library")]
[assembly: AssemblyTitle("Arbitrary-Precision Number Library")]
[assembly: AssemblyDescription("A C# library that supports arbitrary-pre" +
Expand Down
6 changes: 3 additions & 3 deletions Numbers40/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Reflection;
[assembly: System.CLSCompliant(true)]
[assembly: AssemblyInformationalVersion("1.5.1")]
[assembly: AssemblyVersion("1.5.1.0")]
[assembly: AssemblyFileVersion("1.5.1.0")]
[assembly: AssemblyInformationalVersion("1.6.0")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyProduct("Arbitrary-Precision Number Library")]
[assembly: AssemblyTitle("Arbitrary-Precision Number Library")]
[assembly: AssemblyDescription("A C# library that supports arbitrary-pre" +
Expand Down
Loading

0 comments on commit 0547603

Please sign in to comment.