Skip to content

Commit

Permalink
Version 1.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroupc committed Aug 8, 2020
2 parents 7fd42c3 + 5c5676c commit 14843e4
Show file tree
Hide file tree
Showing 12 changed files with 632 additions and 246 deletions.
2 changes: 1 addition & 1 deletion Numbers.nuspec
Expand Up @@ -22,4 +22,4 @@ Version 1.7.0
- Added Log1P and ExpM1 methods to EDecimal and EFloat
- Added 'long' overloads to several arithmetic methods
- Added implication and equivalence (Imp/Eqv) methods and an nth-root method to EInteger</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 targetFramework='.NETStandard1.0' /><group targetFramework='.NETFramework2.0' /><group targetFramework='.NETFramework4.0' /></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/PeterO/Numbers/EDecimal.cs
Expand Up @@ -1398,8 +1398,8 @@ public sealed partial class EDecimal : IComparable<EDecimal>,
/// <param name='bytes'>A sequence that represents a number.</param>
/// <param name='offset'>An index starting at 0 showing where the
/// desired portion of <paramref name='bytes'/> begins.</param>
/// <param name='length'>The length, in code units, of the desired
/// portion of <paramref name='bytes'/> (but not more than <paramref
/// <param name='length'>The length, in bytes, of the desired portion
/// of <paramref name='bytes'/> (but not more than <paramref
/// name='bytes'/> 's length).</param>
/// <returns>An arbitrary-precision decimal number with the same value
/// as the given sequence of bytes (interpreted as text).</returns>
Expand Down
64 changes: 54 additions & 10 deletions Numbers/PeterO/Numbers/EInteger.cs
Expand Up @@ -286,7 +286,53 @@ public sealed partial class EInteger : IComparable<EInteger>,
return FromBytes(bytes, 0, bytes.Length, littleEndian);
}

private static EInteger FromBytes(
/// <summary>Initializes an arbitrary-precision integer from a portion
/// of an array of bytes. The portion of the byte array is encoded
/// using the following rules:
/// <list>
/// <item>Positive numbers have the first byte's highest bit cleared,
/// and negative numbers have the bit set.</item>
/// <item>The last byte contains the lowest 8-bits, the next-to-last
/// contains the next lowest 8 bits, and so on. For example, the number
/// 300 can be encoded as <c>0x01, 0x2C</c> and 200 as <c>0x00,
/// 0xC8</c>. (Note that the second example contains a set high bit in
/// <c>0xC8</c>, so an additional 0 is added at the start to ensure
/// it's interpreted as positive.)</item>
/// <item>To encode negative numbers, take the absolute value of the
/// number, subtract by 1, encode the number into bytes, and toggle
/// each bit of each byte. Any further bits that appear beyond the most
/// significant bit of the number will be all ones. For example, the
/// number -450 can be encoded as <c>0xfe, 0x70</c> and -52869 as
/// <c>0xff, 0x31, 0x7B</c>. (Note that the second example contains a
/// cleared high bit in <c>0x31, 0x7B</c>, so an additional 0xff is
/// added at the start to ensure it's interpreted as
/// negative.)</item></list>
/// <para>For little-endian, the byte order is reversed from the byte
/// order just discussed.</para></summary>
/// <param name='bytes'>A byte array consisting of the two's-complement
/// form (see
/// <see cref='PeterO.Numbers.EDecimal'>"Forms of numbers"</see> ) of
/// the arbitrary-precision integer to create. The byte array is
/// encoded using the rules given in the FromBytes(bytes, offset,
/// length, littleEndian) overload.</param>
/// <param name='offset'>An index starting at 0 showing where the
/// desired portion of <paramref name='bytes'/> begins.</param>
/// <param name='length'>The length, in bytes, of the desired portion
/// of <paramref name='bytes'/> (but not more than <paramref
/// name='bytes'/> 's length).</param>
/// <param name='littleEndian'>If true, the byte order is
/// little-endian, or least-significant-byte first. If false, the byte
/// order is big-endian, or most-significant-byte first.</param>
/// <returns>An arbitrary-precision integer. Returns 0 if the byte
/// array's length is 0.</returns>
/// <exception cref='ArgumentNullException'>The parameter <paramref
/// name='bytes'/> is null.</exception>
/// <exception cref='ArgumentException'>Either <paramref
/// name='offset'/> or <paramref name='length'/> is less than 0 or
/// greater than <paramref name='bytes'/> 's length, or <paramref
/// name='bytes'/> 's length minus <paramref name='offset'/> is less
/// than <paramref name='length'/>.</exception>
public static EInteger FromBytes(
byte[] bytes,
int offset,
int length,
Expand Down Expand Up @@ -2910,7 +2956,8 @@ public sealed partial class EInteger : IComparable<EInteger>,
if (thisValue.Equals(EInteger.One)) {
return thisValue;
}
if (Math.Max(thisValue.wordCount, bigintSecond.wordCount) > 250) {
if (Math.Max(thisValue.wordCount, bigintSecond.wordCount) > 12) {
// if (Math.Max(thisValue.wordCount, bigintSecond.wordCount) > 250) {
return SubquadraticGCD(thisValue, bigintSecond);
} else {
return BaseGcd(thisValue, bigintSecond);
Expand Down Expand Up @@ -3120,7 +3167,7 @@ public sealed partial class EInteger : IComparable<EInteger>,
private static int LBL(long mantlong) {
#if DEBUG
if (mantlong < Int64.MinValue + 1) {
throw new ArgumentException("\"mantlong\" (" + mantlong + ") is not" +
throw new InvalidOperationException("\"mantlong\" (" + mantlong + ") is not" +
"\u0020greater or equal to " + Int64.MinValue + 1);
}
#endif
Expand All @@ -3131,11 +3178,11 @@ public sealed partial class EInteger : IComparable<EInteger>,
private static long[] LHalfGCD(long longa, long longb) {
#if DEBUG
if (longa < 0) {
throw new ArgumentException("\"longa\" (" + longa + ") is not" +
throw new InvalidOperationException("\"longa\" (" + longa + ") is not" +
"\u0020greater or equal to 0");
}
if (longb < 0) {
throw new ArgumentException("\"longb\" (" + longb + ") is not" +
throw new InvalidOperationException("\"longb\" (" + longb + ") is not" +
"\u0020greater or equal to 0");
}
#endif
Expand Down Expand Up @@ -3293,15 +3340,12 @@ public sealed partial class EInteger : IComparable<EInteger>,

// Implements Niels Moeller's Half-GCD algorithm from 2008
private static EInteger[] HalfGCD(EInteger eia, EInteger eib) {
#if DEBUG
if (eia.Sign < 0) {
throw new ArgumentException("doesn't satisfy !eia.IsNegative");
throw new InvalidOperationException("doesn't satisfy !eia.IsNegative");
}
if (eib.Sign < 0) {
throw new ArgumentException("doesn't satisfy !eib.IsNegative");
throw new InvalidOperationException("doesn't satisfy !eib.IsNegative");
}
#endif

EInteger oeia = eia;
EInteger oeib = eib;
if (eia.IsZero || eib.IsZero) {
Expand Down
6 changes: 3 additions & 3 deletions Numbers/PeterO/Numbers/FastIntegerFixed.cs
Expand Up @@ -89,7 +89,8 @@ private enum IntegerMode : byte {
return this.smallValue == fi.smallValue;
case IntegerMode.LargeValue:
return this.largeValue.Equals(fi.largeValue);
default: return true;
default:
return true;
}
}

Expand Down Expand Up @@ -148,8 +149,7 @@ private enum IntegerMode : byte {
}

public FastIntegerFixed Increment() {
if (this.integerMode == IntegerMode.SmallValue && this.smallValue !=
Int32.MaxValue) {
if (this.integerMode == IntegerMode.SmallValue && this.smallValue != Int32.MaxValue) {
return FromInt32(this.smallValue + 1);
} else {
return Add(this, FastIntegerFixed.One);
Expand Down

0 comments on commit 14843e4

Please sign in to comment.