@@ -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"\u0020 greater 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"\u0020 greater 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"\u0020 greater 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 ) {
0 commit comments