Skip to content

Commit 14843e4

Browse files
committed
Version 1.7.4
2 parents 7fd42c3 + 5c5676c commit 14843e4

12 files changed

Lines changed: 632 additions & 246 deletions

File tree

Numbers.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ Version 1.7.0
2222
- Added Log1P and ExpM1 methods to EDecimal and EFloat
2323
- Added 'long' overloads to several arithmetic methods
2424
- 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
25-
>
25+
>

Numbers/PeterO/Numbers/EDecimal.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,8 +1398,8 @@ public static EDecimal FromString(byte[] bytes, EContext ctx) {
13981398
/// <param name='bytes'>A sequence that represents a number.</param>
13991399
/// <param name='offset'>An index starting at 0 showing where the
14001400
/// desired portion of <paramref name='bytes'/> begins.</param>
1401-
/// <param name='length'>The length, in code units, of the desired
1402-
/// portion of <paramref name='bytes'/> (but not more than <paramref
1401+
/// <param name='length'>The length, in bytes, of the desired portion
1402+
/// of <paramref name='bytes'/> (but not more than <paramref
14031403
/// name='bytes'/> 's length).</param>
14041404
/// <returns>An arbitrary-precision decimal number with the same value
14051405
/// as the given sequence of bytes (interpreted as text).</returns>

Numbers/PeterO/Numbers/EInteger.cs

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,53 @@ public static EInteger FromBytes(byte[] bytes, bool littleEndian) {
286286
return FromBytes(bytes, 0, bytes.Length, littleEndian);
287287
}
288288

289-
private static EInteger FromBytes(
289+
/// <summary>Initializes an arbitrary-precision integer from a portion
290+
/// of an array of bytes. The portion of the byte array is encoded
291+
/// using the following rules:
292+
/// <list>
293+
/// <item>Positive numbers have the first byte's highest bit cleared,
294+
/// and negative numbers have the bit set.</item>
295+
/// <item>The last byte contains the lowest 8-bits, the next-to-last
296+
/// contains the next lowest 8 bits, and so on. For example, the number
297+
/// 300 can be encoded as <c>0x01, 0x2C</c> and 200 as <c>0x00,
298+
/// 0xC8</c>. (Note that the second example contains a set high bit in
299+
/// <c>0xC8</c>, so an additional 0 is added at the start to ensure
300+
/// it's interpreted as positive.)</item>
301+
/// <item>To encode negative numbers, take the absolute value of the
302+
/// number, subtract by 1, encode the number into bytes, and toggle
303+
/// each bit of each byte. Any further bits that appear beyond the most
304+
/// significant bit of the number will be all ones. For example, the
305+
/// number -450 can be encoded as <c>0xfe, 0x70</c> and -52869 as
306+
/// <c>0xff, 0x31, 0x7B</c>. (Note that the second example contains a
307+
/// cleared high bit in <c>0x31, 0x7B</c>, so an additional 0xff is
308+
/// added at the start to ensure it's interpreted as
309+
/// negative.)</item></list>
310+
/// <para>For little-endian, the byte order is reversed from the byte
311+
/// order just discussed.</para></summary>
312+
/// <param name='bytes'>A byte array consisting of the two's-complement
313+
/// form (see
314+
/// <see cref='PeterO.Numbers.EDecimal'>"Forms of numbers"</see> ) of
315+
/// the arbitrary-precision integer to create. The byte array is
316+
/// encoded using the rules given in the FromBytes(bytes, offset,
317+
/// length, littleEndian) overload.</param>
318+
/// <param name='offset'>An index starting at 0 showing where the
319+
/// desired portion of <paramref name='bytes'/> begins.</param>
320+
/// <param name='length'>The length, in bytes, of the desired portion
321+
/// of <paramref name='bytes'/> (but not more than <paramref
322+
/// name='bytes'/> 's length).</param>
323+
/// <param name='littleEndian'>If true, the byte order is
324+
/// little-endian, or least-significant-byte first. If false, the byte
325+
/// order is big-endian, or most-significant-byte first.</param>
326+
/// <returns>An arbitrary-precision integer. Returns 0 if the byte
327+
/// array's length is 0.</returns>
328+
/// <exception cref='ArgumentNullException'>The parameter <paramref
329+
/// name='bytes'/> is null.</exception>
330+
/// <exception cref='ArgumentException'>Either <paramref
331+
/// name='offset'/> or <paramref name='length'/> is less than 0 or
332+
/// greater than <paramref name='bytes'/> 's length, or <paramref
333+
/// name='bytes'/> 's length minus <paramref name='offset'/> is less
334+
/// than <paramref name='length'/>.</exception>
335+
public static EInteger FromBytes(
290336
byte[] bytes,
291337
int offset,
292338
int length,
@@ -2910,7 +2956,8 @@ public EInteger Gcd(EInteger bigintSecond) {
29102956
if (thisValue.Equals(EInteger.One)) {
29112957
return thisValue;
29122958
}
2913-
if (Math.Max(thisValue.wordCount, bigintSecond.wordCount) > 250) {
2959+
if (Math.Max(thisValue.wordCount, bigintSecond.wordCount) > 12) {
2960+
// if (Math.Max(thisValue.wordCount, bigintSecond.wordCount) > 250) {
29142961
return SubquadraticGCD(thisValue, bigintSecond);
29152962
} else {
29162963
return BaseGcd(thisValue, bigintSecond);
@@ -3120,7 +3167,7 @@ private static EInteger BL(EInteger eia) {
31203167
private static int LBL(long mantlong) {
31213168
#if DEBUG
31223169
if (mantlong < Int64.MinValue + 1) {
3123-
throw new ArgumentException("\"mantlong\" (" + mantlong + ") is not" +
3170+
throw new InvalidOperationException("\"mantlong\" (" + mantlong + ") is not" +
31243171
"\u0020greater or equal to " + Int64.MinValue + 1);
31253172
}
31263173
#endif
@@ -3131,11 +3178,11 @@ private static int LBL(long mantlong) {
31313178
private static long[] LHalfGCD(long longa, long longb) {
31323179
#if DEBUG
31333180
if (longa < 0) {
3134-
throw new ArgumentException("\"longa\" (" + longa + ") is not" +
3181+
throw new InvalidOperationException("\"longa\" (" + longa + ") is not" +
31353182
"\u0020greater or equal to 0");
31363183
}
31373184
if (longb < 0) {
3138-
throw new ArgumentException("\"longb\" (" + longb + ") is not" +
3185+
throw new InvalidOperationException("\"longb\" (" + longb + ") is not" +
31393186
"\u0020greater or equal to 0");
31403187
}
31413188
#endif
@@ -3293,15 +3340,12 @@ private static EInteger[] SlowSgcd(EInteger eia, EInteger eib) {
32933340

32943341
// Implements Niels Moeller's Half-GCD algorithm from 2008
32953342
private static EInteger[] HalfGCD(EInteger eia, EInteger eib) {
3296-
#if DEBUG
32973343
if (eia.Sign < 0) {
3298-
throw new ArgumentException("doesn't satisfy !eia.IsNegative");
3344+
throw new InvalidOperationException("doesn't satisfy !eia.IsNegative");
32993345
}
33003346
if (eib.Sign < 0) {
3301-
throw new ArgumentException("doesn't satisfy !eib.IsNegative");
3347+
throw new InvalidOperationException("doesn't satisfy !eib.IsNegative");
33023348
}
3303-
#endif
3304-
33053349
EInteger oeia = eia;
33063350
EInteger oeib = eib;
33073351
if (eia.IsZero || eib.IsZero) {

Numbers/PeterO/Numbers/FastIntegerFixed.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public override bool Equals(object obj) {
8989
return this.smallValue == fi.smallValue;
9090
case IntegerMode.LargeValue:
9191
return this.largeValue.Equals(fi.largeValue);
92-
default: return true;
92+
default:
93+
return true;
9394
}
9495
}
9596

@@ -148,8 +149,7 @@ public FastInteger ToFastInteger() {
148149
}
149150

150151
public FastIntegerFixed Increment() {
151-
if (this.integerMode == IntegerMode.SmallValue && this.smallValue !=
152-
Int32.MaxValue) {
152+
if (this.integerMode == IntegerMode.SmallValue && this.smallValue != Int32.MaxValue) {
153153
return FromInt32(this.smallValue + 1);
154154
} else {
155155
return Add(this, FastIntegerFixed.One);

0 commit comments

Comments
 (0)