2362N/A * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Portions Copyright (c) 1995 Colin Plumb. All rights reserved. 0N/A * Immutable arbitrary-precision integers. All operations behave as if 0N/A * BigIntegers were represented in two's-complement notation (like Java's 0N/A * primitive integer types). BigInteger provides analogues to all of Java's 0N/A * primitive integer operators, and all relevant methods from java.lang.Math. 0N/A * Additionally, BigInteger provides operations for modular arithmetic, GCD 0N/A * calculation, primality testing, prime generation, bit manipulation, 0N/A * and a few other miscellaneous operations. 0N/A * <p>Semantics of arithmetic operations exactly mimic those of Java's integer 0N/A * arithmetic operators, as defined in <i>The Java Language Specification</i>. 0N/A * For example, division by zero throws an {@code ArithmeticException}, and 0N/A * division of a negative by a positive yields a negative (or zero) remainder. 0N/A * All of the details in the Spec concerning overflow are ignored, as 0N/A * BigIntegers are made as large as necessary to accommodate the results of an 0N/A * <p>Semantics of shift operations extend those of Java's shift operators 0N/A * to allow for negative shift distances. A right-shift with a negative 0N/A * shift distance results in a left shift, and vice-versa. The unsigned 0N/A * right shift operator ({@code >>>}) is omitted, as this operation makes 0N/A * little sense in combination with the "infinite word size" abstraction 0N/A * provided by this class. 0N/A * <p>Semantics of bitwise logical operations exactly mimic those of Java's 0N/A * bitwise integer operators. The binary operators ({@code and}, 0N/A * {@code or}, {@code xor}) implicitly perform sign extension on the shorter 0N/A * of the two operands prior to performing the operation. 0N/A * <p>Comparison operations perform signed integer comparisons, analogous to 0N/A * those performed by Java's relational and equality operators. 0N/A * <p>Modular arithmetic operations are provided to compute residues, perform 0N/A * exponentiation, and compute multiplicative inverses. These methods always 0N/A * return a non-negative result, between {@code 0} and {@code (modulus - 1)}, 0N/A * <p>Bit operations operate on a single bit of the two's-complement 0N/A * representation of their operand. If necessary, the operand is sign- 0N/A * extended so that it contains the designated bit. None of the single-bit 0N/A * operations can produce a BigInteger with a different sign from the 0N/A * BigInteger being operated on, as they affect only a single bit, and the 0N/A * "infinite word size" abstraction provided by this class ensures that there 0N/A * are infinitely many "virtual sign bits" preceding each BigInteger. 0N/A * <p>For the sake of brevity and clarity, pseudo-code is used throughout the 0N/A * descriptions of BigInteger methods. The pseudo-code expression 0N/A * {@code (i + j)} is shorthand for "a BigInteger whose value is 0N/A * that of the BigInteger {@code i} plus that of the BigInteger {@code j}." 0N/A * The pseudo-code expression {@code (i == j)} is shorthand for 0N/A * "{@code true} if and only if the BigInteger {@code i} represents the same 0N/A * value as the BigInteger {@code j}." Other pseudo-code expressions are 0N/A * interpreted similarly. 0N/A * <p>All methods and constructors in this class throw 0N/A * {@code NullPointerException} when passed 0N/A * a null object reference for any input parameter. 0N/A * @author Josh Bloch 0N/A * @author Michael McCloskey 0N/A * The signum of this BigInteger: -1 for negative, 0 for zero, or 0N/A * 1 for positive. Note that the BigInteger zero <i>must</i> have 0N/A * a signum of 0. This is necessary to ensures that there is exactly one 0N/A * representation for each BigInteger value. 0N/A * The magnitude of this BigInteger, in <i>big-endian</i> order: the 0N/A * zeroth element of this array is the most-significant int of the 0N/A * magnitude. The magnitude must be "minimal" in that the most-significant 0N/A * int ({@code mag[0]}) must be non-zero. This is necessary to 0N/A * ensure that there is exactly one representation for each BigInteger 0N/A * value. Note that this implies that the BigInteger zero has a 0N/A * zero-length mag array. 0N/A // These "redundant fields" are initialized with recognizable nonsense 0N/A // values, and cached the first time they are needed (or never, if they 1246N/A * One plus the bitCount of this BigInteger. Zeros means unitialized. 1246N/A * @deprecated Deprecated since logical value is offset from stored 1246N/A * value and correction factor is applied in accessor method. 1246N/A * One plus the bitLength of this BigInteger. Zeros means unitialized. 0N/A * (either value is acceptable). 1246N/A * @deprecated Deprecated since logical value is offset from stored 1246N/A * value and correction factor is applied in accessor method. 1246N/A * Two plus the lowest set bit of this BigInteger, as returned by 0N/A * @see #getLowestSetBit 1246N/A * @deprecated Deprecated since logical value is offset from stored 1246N/A * value and correction factor is applied in accessor method. 1246N/A * Two plus the index of the lowest-order int in the magnitude of this 1246N/A * BigInteger that contains a nonzero int, or -2 (either value is acceptable). 1246N/A * The least significant int has int-number 0, the next int in order of 1246N/A * increasing significance has int-number 1, and so forth. 1246N/A * @deprecated Deprecated since logical value is offset from stored 1246N/A * value and correction factor is applied in accessor method. 0N/A * This mask is used to obtain the value of an int as if it were unsigned. 0N/A * Translates a byte array containing the two's-complement binary 0N/A * representation of a BigInteger into a BigInteger. The input array is 0N/A * assumed to be in <i>big-endian</i> byte-order: the most significant 0N/A * byte is in the zeroth element. 0N/A * @param val big-endian two's-complement binary representation of 0N/A * @throws NumberFormatException {@code val} is zero bytes long. 0N/A * This private constructor translates an int array containing the 0N/A * two's-complement binary representation of a BigInteger into a 0N/A * BigInteger. The input array is assumed to be in <i>big-endian</i> 0N/A * int-order: the most significant int is in the zeroth element. 0N/A * Translates the sign-magnitude representation of a BigInteger into a 0N/A * BigInteger. The sign is represented as an integer signum value: -1 for 0N/A * negative, 0 for zero, or 1 for positive. The magnitude is a byte array 0N/A * in <i>big-endian</i> byte-order: the most significant byte is in the 0N/A * zeroth element. A zero-length magnitude array is permissible, and will 0N/A * result in a BigInteger value of 0, whether signum is -1, 0 or 1. 0N/A * @param signum signum of the number (-1 for negative, 0 for zero, 1 0N/A * @param magnitude big-endian binary representation of the magnitude of 0N/A * @throws NumberFormatException {@code signum} is not one of the three 0N/A * legal values (-1, 0, and 1), or {@code signum} is 0 and 0N/A * {@code magnitude} contains one or more non-zero bytes. 0N/A * A constructor for internal use that translates the sign-magnitude 0N/A * representation of a BigInteger into a BigInteger. It checks the 0N/A * arguments and copies the magnitude so this constructor would be 0N/A * safe for external use. 0N/A * Translates the String representation of a BigInteger in the 0N/A * specified radix into a BigInteger. The String representation 0N/A * consists of an optional minus or plus sign followed by a 0N/A * sequence of one or more digits in the specified radix. The 0N/A * character-to-digit mapping is provided by {@code 0N/A * Character.digit}. The String may not contain any extraneous 0N/A * characters (whitespace, for example). 0N/A * @param val String representation of BigInteger. 0N/A * @param radix radix to be used in interpreting {@code val}. 0N/A * @throws NumberFormatException {@code val} is not a valid representation 0N/A * of a BigInteger in the specified radix, or {@code radix} is 0N/A * outside the range from {@link Character#MIN_RADIX} to 0N/A * {@link Character#MAX_RADIX}, inclusive. 0N/A * @see Character#digit 0N/A // Check for at most one leading sign 0N/A // No leading sign character or at most one leading sign character 0N/A // Skip leading zeros and compute number of digits in magnitude 0N/A // Pre-allocate array of expected size. May be too large but can 0N/A // never be too small. Typically exact. 0N/A // Process first (potentially short) digit group 0N/A // Process remaining digit groups 0N/A // Required for cases where the array was overallocated. 0N/A // Constructs a new BigInteger using a char array with radix=10 0N/A // Check for leading minus sign 0N/A // Skip leading zeros and compute number of digits in magnitude 0N/A // Pre-allocate array of expected size 0N/A // Process first (potentially short) digit group 0N/A // Process remaining digit groups 0N/A // Create an integer with the digits between the two indexes 0N/A // Assumes start < end. The result may be negative, but it 0N/A // is to be treated as an unsigned value. 0N/A // bitsPerDigit in the given radix times 1024 0N/A // Rounded up to avoid underallocation. 0N/A 1024,
1624,
2048,
2378,
2648,
2875,
3072,
3247,
3402,
3543,
3672,
0N/A 3790,
3899,
4001,
4096,
4186,
4271,
4350,
4426,
4498,
4567,
4633,
0N/A 4696,
4756,
4814,
4870,
4923,
4975,
5025,
5074,
5120,
5166,
5210,
0N/A // Multiply x array times word y in place, and add word z 0N/A // Perform the multiplication word by word 0N/A for (
int i =
len-
1; i >=
0; i--) {
0N/A // Perform the addition 0N/A for (
int i =
len-
2; i >=
0; i--) {
0N/A * Translates the decimal String representation of a BigInteger into a 0N/A * BigInteger. The String representation consists of an optional minus 0N/A * sign followed by a sequence of one or more decimal digits. The 0N/A * character-to-digit mapping is provided by {@code Character.digit}. 0N/A * The String may not contain any extraneous characters (whitespace, for 0N/A * @param val decimal String representation of BigInteger. 0N/A * @throws NumberFormatException {@code val} is not a valid representation 0N/A * @see Character#digit 0N/A * Constructs a randomly generated BigInteger, uniformly distributed over 1794N/A * the range 0 to (2<sup>{@code numBits}</sup> - 1), inclusive. 0N/A * The uniformity of the distribution assumes that a fair source of random 0N/A * bits is provided in {@code rnd}. Note that this constructor always 0N/A * constructs a non-negative BigInteger. 0N/A * @param numBits maximum bitLength of the new BigInteger. 0N/A * @param rnd source of randomness to be used in computing the new 0N/A * @throws IllegalArgumentException {@code numBits} is negative. 0N/A // Generate random bytes and mask out any excess bits 0N/A * Constructs a randomly generated positive BigInteger that is probably 0N/A * prime, with the specified bitLength. 0N/A * <p>It is recommended that the {@link #probablePrime probablePrime} 0N/A * method be used in preference to this constructor unless there 0N/A * is a compelling need to specify a certainty. 0N/A * @param bitLength bitLength of the returned BigInteger. 0N/A * @param certainty a measure of the uncertainty that the caller is 0N/A * willing to tolerate. The probability that the new BigInteger 0N/A * represents a prime number will exceed 0N/A * (1 - 1/2<sup>{@code certainty}</sup>). The execution time of 0N/A * this constructor is proportional to the value of this parameter. 0N/A * @param rnd source of random bits used to select candidates to be 0N/A * tested for primality. 0N/A * @throws ArithmeticException {@code bitLength < 2}. 0N/A // The cutoff of 95 was chosen empirically for best performance 0N/A // Minimum size in bits that the requested prime number has 0N/A // before we use the large prime number generating algorithms 0N/A // Certainty required to meet the spec of probablePrime 0N/A * Returns a positive BigInteger that is probably prime, with the 0N/A * specified bitLength. The probability that a BigInteger returned 0N/A * by this method is composite does not exceed 2<sup>-100</sup>. 0N/A * @param bitLength bitLength of the returned BigInteger. 0N/A * @param rnd source of random bits used to select candidates to be 0N/A * tested for primality. 0N/A * @return a BigInteger of {@code bitLength} bits that is probably prime 0N/A * @throws ArithmeticException {@code bitLength < 2}. 0N/A // The cutoff of 95 was chosen empirically for best performance 0N/A * Find a random number of the specified bitLength that is probably prime. 0N/A * This method is used for smaller primes, its performance degrades on 0N/A * larger bitlengths. 0N/A * This method assumes bitLength > 1. 0N/A // Construct a candidate 0N/A // Do cheap "pre-test" if applicable 0N/A if ((r%
3==
0) || (r%
5==
0) || (r%
7==
0) || (r%
11==
0) ||
0N/A (r%
13==
0) || (r%
17==
0) || (r%
19==
0) || (r%
23==
0) ||
0N/A (r%
29==
0) || (r%
31==
0) || (r%
37==
0) || (r%
41==
0))
0N/A continue;
// Candidate is composite; try another 0N/A // All candidates of bitLength 2 and 3 are prime by this point 0N/A // Do expensive test if we survive pre-test (or it's inapplicable) 0N/A * Find a random number of the specified bitLength that is probably prime. 0N/A * This method is more appropriate for larger bitlengths since it uses 0N/A * a sieve to eliminate most composites before using a more expensive 0N/A // Use a sieve length likely to contain the next prime number 0N/A * Returns the first integer greater than this {@code BigInteger} that 0N/A * is probably prime. The probability that the number returned by this 0N/A * method is composite does not exceed 2<sup>-100</sup>. This method will 0N/A * never skip over a prime when searching: if it returns {@code p}, there 0N/A * is no prime {@code q} such that {@code this < q < p}. 0N/A * @return the first integer greater than this {@code BigInteger} that 0N/A * is probably prime. 0N/A * @throws ArithmeticException {@code this < 0}. 0N/A // Handle trivial cases 0N/A // Fastpath for small numbers 0N/A // Ensure an odd number 0N/A // Do cheap "pre-test" if applicable 0N/A if ((r%
3==
0) || (r%
5==
0) || (r%
7==
0) || (r%
11==
0) ||
0N/A (r%
13==
0) || (r%
17==
0) || (r%
19==
0) || (r%
23==
0) ||
0N/A (r%
29==
0) || (r%
31==
0) || (r%
37==
0) || (r%
41==
0)) {
0N/A continue;
// Candidate is composite; try another 0N/A // All candidates of bitLength 2 and 3 are prime by this point 0N/A // The expensive test 0N/A // Start at previous even number 0N/A // Looking for the next large prime 0N/A * Returns {@code true} if this BigInteger is probably prime, 0N/A * {@code false} if it's definitely composite. 0N/A * This method assumes bitLength > 2. 0N/A * @param certainty a measure of the uncertainty that the caller is 0N/A * willing to tolerate: if the call returns {@code true} 0N/A * the probability that this BigInteger is prime exceeds 0N/A * {@code (1 - 1/2<sup>certainty</sup>)}. The execution time of 0N/A * this method is proportional to the value of this parameter. 0N/A * @return {@code true} if this BigInteger is probably prime, 0N/A * {@code false} if it's definitely composite. 0N/A // The relationship between the certainty and the number of rounds 0N/A // we perform is given in the draft standard ANSI X9.80, "PRIME 0N/A // NUMBER GENERATION, PRIMALITY TESTING, AND PRIMALITY CERTIFICATES". 0N/A * Returns true iff this BigInteger is a Lucas-Lehmer probable prime. 0N/A * The following assumptions are made: 0N/A * This BigInteger is a positive, odd number. 0N/A // 5, -7, 9, -11, ... 0N/A * Computes Jacobi(p,n). 0N/A * Assumes n positive, odd, n>=3. 0N/A // Algorithm and comments adapted from Colin Plumb's C library. 0N/A j = -j;
// 3 (011) or 7 (111) mod 8 0N/A // Get rid of factors of 2 in p 0N/A while ((p &
3) ==
0)
0N/A if (((u ^ (u>>
1)) &
2) !=
0)
0N/A j = -j;
// 3 (011) or 5 (101) mod 8 0N/A // Then, apply quadratic reciprocity 0N/A if ((p & u &
2) !=
0)
// p = u = 3 (mod 4)? 0N/A // And reduce u mod p 0N/A // Now compute Jacobi(u,p), u < p 0N/A while ((u &
3) ==
0)
0N/A if (((p ^ (p>>
1)) &
2) !=
0)
0N/A j = -j;
// 3 (011) or 5 (101) mod 8 0N/A // Now both u and p are odd, so use quadratic reciprocity 0N/A int t = u; u = p; p = t;
0N/A if ((u & p &
2) !=
0)
// u = p = 3 (mod 4)? 0N/A // Now u >= p, so it can be reduced 0N/A * Returns true iff this BigInteger passes the specified number of 0N/A * Miller-Rabin tests. This test is taken from the DSA spec (NIST FIPS 0N/A * The following assumptions are made: 0N/A * This BigInteger is a positive, odd number greater than 2. 0N/A // Find a and m such that m is odd and this == 1 + 2**a * m 0N/A // Generate a uniform random on (1, this) 1246N/A * This internal constructor differs from its public cousin 0N/A * with the arguments reversed in two ways: it assumes that its 0N/A * arguments are correct, and it doesn't copy the magnitude array. 0N/A * This private constructor is for internal use and assumes that its 0N/A * arguments are correct. 0N/A //Static Factory Methods 0N/A * Returns a BigInteger whose value is equal to that of the 0N/A * specified {@code long}. This "static factory method" is 0N/A * provided in preference to a ({@code long}) constructor 0N/A * because it allows for reuse of frequently used BigIntegers. 0N/A * @param val value of the BigInteger to return. 0N/A * @return a BigInteger with the specified value. 0N/A // If -MAX_CONSTANT < val < MAX_CONSTANT, return stashed constant 0N/A * Constructs a BigInteger with the specified value, which may not be zero. 0N/A * Returns a BigInteger with the given two's complement representation. 0N/A * Assumes that the input array will not be modified (the returned 0N/A * BigInteger will reference the input array if feasible). 0N/A * Initialize static constant array when class is loaded. 0N/A * The BigInteger constant zero. 0N/A * The BigInteger constant one. 0N/A * The BigInteger constant two. (Not exported.) 0N/A * The BigInteger constant ten. 0N/A // Arithmetic Operations 0N/A * Returns a BigInteger whose value is {@code (this + val)}. 0N/A * @param val value to be added to this BigInteger. 0N/A * @return {@code this + val} 0N/A * Adds the contents of the int arrays x and y. This method allocates 0N/A * a new int array to hold the answer and returns a reference to that 0N/A private static int[]
add(
int[] x,
int[] y) {
0N/A // If x is shorter, swap the two arrays 0N/A // Add common parts of both numbers 0N/A // Copy remainder of longer number while carry propagation is required 0N/A // Copy remainder of longer number 0N/A // Grow result if necessary 0N/A * Returns a BigInteger whose value is {@code (this - val)}. 0N/A * @param val value to be subtracted from this BigInteger. 0N/A * @return {@code this - val} 0N/A * Subtracts the contents of the second int arrays (little) from the 0N/A * first (big). The first int array (big) must represent a larger number 0N/A * than the second. This method allocates the space necessary to hold the 0N/A // Subtract common parts of both numbers 0N/A // Subtract remainder of longer number while borrow propagates 0N/A // Copy remainder of longer number 0N/A * Returns a BigInteger whose value is {@code (this * val)}. 0N/A * @param val value to be multiplied by this BigInteger. 0N/A * @return {@code this * val} 1246N/A * Package private methods used by BigDecimal code to multiply a BigInteger 1246N/A * with a long. Assumes v is not equal to INFLATED. 1246N/A long dh = v >>>
32;
// higher order bits 0N/A * Multiplies int arrays x and y to the specified lengths and places 1246N/A * the result into z. There will be no leading zeros in the resultant array. 0N/A * Returns a BigInteger whose value is {@code (this<sup>2</sup>)}. 0N/A * @return {@code this<sup>2</sup>} 0N/A * Squares the contents of the int array x. The result is placed into the 0N/A * int array z. The contents of x are not changed. 0N/A * The algorithm used here is adapted from Colin Plumb's C library. 0N/A * Technique: Consider the partial products in the multiplication 0N/A * of "abcde" by itself: 0N/A * ================== 0N/A * Note that everything above the main diagonal: 0N/A * ae be ce de = (abcd) * e 0N/A * ad bd cd = (abc) * d 0N/A * is a copy of everything below the main diagonal: 0N/A * Thus, the sum is 2 * (off the diagonal) + diagonal. 0N/A * This is accumulated beginning with the diagonal (which 0N/A * consist of the squares of the digits of the input), which is then 0N/A * divided by two, the off-diagonal added, and multiplied by two 0N/A * again. The low bit is simply a copy of the low bit of the 0N/A * input, so it doesn't need special care. 0N/A // Store the squares, right shifted one bit (i.e., divided by 2) 0N/A for (
int j=
0, i=
0; j<
len; j++) {
0N/A // Add in off-diagonal sums 0N/A // Shift back up and set low bit 0N/A * Returns a BigInteger whose value is {@code (this / val)}. 0N/A * @param val value by which this BigInteger is to be divided. 0N/A * @return {@code this / val} 1794N/A * @throws ArithmeticException if {@code val} is zero. 0N/A * Returns an array of two BigIntegers containing {@code (this / val)} 0N/A * followed by {@code (this % val)}. 0N/A * @param val value by which this BigInteger is to be divided, and the 0N/A * remainder computed. 0N/A * @return an array of two BigIntegers: the quotient {@code (this / val)} 0N/A * is the initial element, and the remainder {@code (this % val)} 0N/A * is the final element. 1794N/A * @throws ArithmeticException if {@code val} is zero. 0N/A * Returns a BigInteger whose value is {@code (this % val)}. 0N/A * @param val value by which this BigInteger is to be divided, and the 0N/A * remainder computed. 0N/A * @return {@code this % val} 1794N/A * @throws ArithmeticException if {@code val} is zero. 0N/A * Returns a BigInteger whose value is <tt>(this<sup>exponent</sup>)</tt>. 0N/A * Note that {@code exponent} is an integer rather than a BigInteger. 0N/A * @param exponent exponent to which this BigInteger is to be raised. 0N/A * @return <tt>this<sup>exponent</sup></tt> 0N/A * @throws ArithmeticException {@code exponent} is negative. (This would 0N/A * cause the operation to yield a non-integer value.) 0N/A // Perform exponentiation using repeated squaring trick 0N/A * Returns a BigInteger whose value is the greatest common divisor of 0N/A * {@code abs(this)} and {@code abs(val)}. Returns 0 if 0N/A * {@code this==0 && val==0}. 0N/A * @param val value with which the GCD is to be computed. 0N/A * @return {@code GCD(abs(this), abs(val))} 1246N/A * Package private method to return bit length for an integer. 0N/A * Left shift int array a up to len by n bits. Returns the array that 0N/A * results from the shift since space may have to be reallocated. 0N/A // If shift can be done without recopy, do so 0N/A }
else {
// Array must be resized 0N/A // shifts a up to len right n bits assumes no leading zeros, 0<n<32 0N/A for (
int i=
len-
1, c=a[i]; i>
0; i--) {
0N/A a[i] = (c <<
n2) | (b >>> n);
0N/A // shifts a up to len left n bits assumes no leading zeros, 0<=n<32 0N/A for (
int i=
0, c=a[i], m=i+
len-
1; i<m; i++) {
0N/A a[i] = (b << n) | (c >>>
n2);
0N/A * Calculate bitlength of contents of the first len elements an int array, 0N/A * assuming there are no leading zero ints. 0N/A * Returns a BigInteger whose value is the absolute value of this 0N/A * @return {@code abs(this)} 0N/A * Returns a BigInteger whose value is {@code (-this)}. 0N/A * @return {@code -this} 0N/A * Returns the signum function of this BigInteger. 0N/A * @return -1, 0 or 1 as the value of this BigInteger is negative, zero or 0N/A // Modular Arithmetic Operations 0N/A * Returns a BigInteger whose value is {@code (this mod m}). This method 0N/A * differs from {@code remainder} in that it always returns a 0N/A * <i>non-negative</i> BigInteger. 0N/A * @param m the modulus. 0N/A * @return {@code this mod m} 1794N/A * @throws ArithmeticException {@code m} ≤ 0 0N/A * Returns a BigInteger whose value is 0N/A * <tt>(this<sup>exponent</sup> mod m)</tt>. (Unlike {@code pow}, this 0N/A * method permits negative exponents.) 0N/A * @param exponent the exponent. 0N/A * @param m the modulus. 0N/A * @return <tt>this<sup>exponent</sup> mod m</tt> 1794N/A * @throws ArithmeticException {@code m} ≤ 0 or the exponent is 1794N/A * negative and this BigInteger is not <i>relatively 0N/A * Even modulus. Tear it into an "odd part" (m1) and power of two 0N/A * (m2), exponentiate mod m1, manually exponentiate mod m2, and 0N/A * use Chinese Remainder Theorem to combine results. 0N/A // Tear m apart into odd part (m1) and power of 2 (m2) 0N/A // Calculate new base from m1 0N/A // Caculate (base ** exponent) mod m1. 0N/A // Calculate (this ** exponent) mod m2 0N/A // Combine results using Chinese Remainder Theorem 0N/A * Returns a BigInteger whose value is x to the power of y mod z. 0N/A * Assumes: z is odd && x < z. 0N/A * The algorithm is adapted from Colin Plumb's C library. 0N/A * The window algorithm: 0N/A * The idea is to keep a running product of b1 = n^(high-order bits of exp) 0N/A * and then keep appending exponent bits to it. The following patterns 0N/A * apply to a 3-bit window (k = 3): 0N/A * To append 0: square 0N/A * To append 1: square, multiply by n^1 0N/A * To append 10: square, multiply by n^1, square 0N/A * To append 11: square, square, multiply by n^3 0N/A * To append 100: square, multiply by n^1, square, square 0N/A * To append 101: square, square, square, multiply by n^5 0N/A * To append 110: square, square, multiply by n^3, square 0N/A * To append 111: square, square, square, multiply by n^7 0N/A * Since each pattern involves only one multiply, the longer the pattern 0N/A * the better, except that a 0 (no multiplies) can be appended directly. 0N/A * We precompute a table of odd powers of n, up to 2^k, and can then 0N/A * multiply k bits of exponent at a time. Actually, assuming random 0N/A * exponents, there is on average one zero bit between needs to 0N/A * multiply (1/2 of the time there's none, 1/4 of the time there's 1, 0N/A * 1/8 of the time, there's 2, 1/32 of the time, there's 3, etc.), so 0N/A * you have to do one multiply per k+1 bits of exponent. 0N/A * The loop walks down the exponent, squaring the result buffer as 0N/A * it goes. There is a wbits+1 bit lookahead buffer, buf, that is 0N/A * filled with the upcoming exponent bits. (What is read after the 0N/A * end of the exponent is unimportant, but it is filled with zero here.) 0N/A * When the most-significant bit of this buffer becomes set, i.e. 0N/A * (buf & tblmask) != 0, we have to decide what pattern to multiply 0N/A * by, and when to do it. We decide, remember to do it in future 0N/A * after a suitable number of squarings have passed (e.g. a pattern 0N/A * of "100" in the buffer requires that we multiply by n^1 immediately; 0N/A * a pattern of "110" calls for multiplying by n^3 after one more 0N/A * squaring), clear the buffer, and continue. 0N/A * When we start, there is one more optimization: the result buffer 0N/A * is implcitly one, so squaring it or multiplying by it can be 0N/A * optimized away. Further, if we start with a pattern like "100" 0N/A * in the lookahead window, rather than placing n into the buffer 0N/A * and then starting to square it, we have already computed n^2 0N/A * to compute the odd-powers table, so we can place that into 0N/A * the buffer and save a squaring. 0N/A * This means that if you have a k-bit window, to compute n^z, 0N/A * where z is the high k bits of the exponent, 1/2 of the time 0N/A * it requires no squarings. 1/4 of the time, it requires 1 0N/A * squaring, ... 1/2^(k-1) of the time, it reqires k-2 squarings. 0N/A * And the remaining 1/2^(k-1) of the time, the top k bits are a 0N/A * 1 followed by k-1 0 bits, so it again only requires k-2 0N/A * squarings, not k-1. The average of these is 1. Add that 0N/A * to the one squaring we have to do to compute the table, 0N/A * and you'll see that a k-bit window saves k-2 squarings 0N/A * as well as reducing the multiplies. (It actually doesn't 0N/A * hurt in the case k = 1, either.) 0N/A // Special case for exponent of one 0N/A // Special case for base of zero 0N/A // Select an appropriate window size 0N/A // if exponent is 65537 (0x10001), use minimum window size 0N/A // Calculate appropriate table size 0N/A // Allocate table for precomputed odd powers of base in Montgomery form 0N/A // Compute the modular inverse 0N/A // Convert base to Montgomery form 0N/A // Pad table[0] with leading zeros so its length is at least modLen 0N/A // Set b to the square of the base 0N/A // Set t to high half of b 0N/A // Fill in the table with odd powers of the base 0N/A // Pre load the window that slides over the exponent 0N/A // The first iteration, which is hoisted out of the main loop 0N/A // Advance the window 0N/A // Examine the window for pending multiplies 0N/A t = a; a = b; b = t;
0N/A t = a; a = b; b = t;
0N/A // Convert result out of Montgomery form and return 0N/A * Montgomery reduce n, modulo mod. This reduces modulo mod and divides 0N/A * by 2^(32*mlen). Adapted from Colin Plumb's C library. 0N/A * Returns -1, 0 or +1 as big-endian unsigned int array arg1 is less than, 0N/A * equal to, or greater than arg2 up to length len. 0N/A * Subtracts two numbers of same length, returning borrow. 0N/A private static int subN(
int[] a,
int[] b,
int len) {
0N/A * Multiply an array by one word k and add to result, return the carry 0N/A for (
int j=
len-
1; j >=
0; j--) {
0N/A * Add one word to the number a mlen words into a. Return the resulting 0N/A if ((t >>>
32) ==
0)
0N/A * Returns a BigInteger whose value is (this ** exponent) mod (2**p) 0N/A * Perform exponentiation using repeated squaring trick, chopping off 0N/A * high order bits as indicated by modulus. 0N/A * Returns a BigInteger whose value is this mod(2**p). 0N/A * Assumes that this {@code BigInteger >= 0} and {@code p > 0}. 0N/A // Copy remaining ints of mag 0N/A // Mask out any excess bits 0N/A * Returns a BigInteger whose value is {@code (this}<sup>-1</sup> {@code mod m)}. 0N/A * @param m the modulus. 0N/A * @return {@code this}<sup>-1</sup> {@code mod m}. 1794N/A * @throws ArithmeticException {@code m} ≤ 0, or this BigInteger 0N/A * has no multiplicative inverse mod m (that is, this BigInteger 0N/A * is not <i>relatively prime</i> to m). 0N/A // Calculate (this mod m) 0N/A * Returns a BigInteger whose value is {@code (this << n)}. 0N/A * The shift distance, {@code n}, may be negative, in which case 0N/A * this method performs a right shift. 0N/A * (Computes <tt>floor(this * 2<sup>n</sup>)</tt>.) 0N/A * @param n shift distance, in bits. 0N/A * @return {@code this << n} 1785N/A * @throws ArithmeticException if the shift distance is {@code 0N/A * Returns a BigInteger whose value is {@code (this >> n)}. Sign 0N/A * extension is performed. The shift distance, {@code n}, may be 0N/A * negative, in which case this method performs a left shift. 0N/A * (Computes <tt>floor(this / 2<sup>n</sup>)</tt>.) 0N/A * @param n shift distance, in bits. 0N/A * @return {@code this >> n} 1785N/A * @throws ArithmeticException if the shift distance is {@code 0N/A // Special case: entire contents shifted off the end 0N/A // Find out whether any one-bits were shifted off the end. 0N/A // Bitwise Operations 0N/A * Returns a BigInteger whose value is {@code (this & val)}. (This 0N/A * method returns a negative BigInteger if and only if this and val are 0N/A * @param val value to be AND'ed with this BigInteger. 0N/A * @return {@code this & val} 0N/A * Returns a BigInteger whose value is {@code (this | val)}. (This method 0N/A * returns a negative BigInteger if and only if either this or val is 0N/A * @param val value to be OR'ed with this BigInteger. 0N/A * @return {@code this | val} 0N/A * Returns a BigInteger whose value is {@code (this ^ val)}. (This method 0N/A * returns a negative BigInteger if and only if exactly one of this and 0N/A * val are negative.) 0N/A * @param val value to be XOR'ed with this BigInteger. 0N/A * @return {@code this ^ val} 0N/A * Returns a BigInteger whose value is {@code (~this)}. (This method 0N/A * returns a negative value if and only if this BigInteger is 0N/A * @return {@code ~this} 0N/A * Returns a BigInteger whose value is {@code (this & ~val)}. This 0N/A * method, which is equivalent to {@code and(val.not())}, is provided as 0N/A * a convenience for masking operations. (This method returns a negative 0N/A * BigInteger if and only if {@code this} is negative and {@code val} is 0N/A * @param val value to be complemented and AND'ed with this BigInteger. 0N/A * @return {@code this & ~val} 0N/A // Single Bit Operations 0N/A * Returns {@code true} if and only if the designated bit is set. 0N/A * (Computes {@code ((this & (1<<n)) != 0)}.) 0N/A * @param n index of bit to test. 0N/A * @return {@code true} if and only if the designated bit is set. 0N/A * @throws ArithmeticException {@code n} is negative. 0N/A * Returns a BigInteger whose value is equivalent to this BigInteger 0N/A * with the designated bit set. (Computes {@code (this | (1<<n))}.) 0N/A * @param n index of bit to set. 0N/A * @return {@code this | (1<<n)} 0N/A * @throws ArithmeticException {@code n} is negative. 0N/A * Returns a BigInteger whose value is equivalent to this BigInteger 0N/A * with the designated bit cleared. 0N/A * (Computes {@code (this & ~(1<<n))}.) 0N/A * @param n index of bit to clear. 0N/A * @return {@code this & ~(1<<n)} 0N/A * @throws ArithmeticException {@code n} is negative. 0N/A * Returns a BigInteger whose value is equivalent to this BigInteger 0N/A * with the designated bit flipped. 0N/A * (Computes {@code (this ^ (1<<n))}.) 0N/A * @param n index of bit to flip. 0N/A * @return {@code this ^ (1<<n)} 0N/A * @throws ArithmeticException {@code n} is negative. 0N/A * Returns the index of the rightmost (lowest-order) one bit in this 0N/A * BigInteger (the number of zero bits to the right of the rightmost 0N/A * one bit). Returns -1 if this BigInteger contains no one bits. 0N/A * (Computes {@code (this==0? -1 : log2(this & -this))}.) 0N/A * @return index of the rightmost one bit in this BigInteger. 1246N/A if (
lsb == -
2) {
// lowestSetBit not initialized yet 0N/A // Search for lowest order nonzero int 0N/A // Miscellaneous Bit Operations 0N/A * Returns the number of bits in the minimal two's-complement 0N/A * representation of this BigInteger, <i>excluding</i> a sign bit. 0N/A * For positive BigIntegers, this is equivalent to the number of bits in 0N/A * the ordinary binary representation. (Computes 0N/A * {@code (ceil(log2(this < 0 ? -this : this+1)))}.) 0N/A * @return number of bits in the minimal two's-complement 0N/A * representation of this BigInteger, <i>excluding</i> a sign bit. 1246N/A if (n == -
1) {
// bitLength not initialized yet 1246N/A n =
0;
// offset by one to initialize 0N/A // Calculate the bit length of the magnitude 1246N/A // Check if magnitude is a power of two 0N/A * Returns the number of bits in the two's complement representation 0N/A * of this BigInteger that differ from its sign bit. This method is 0N/A * useful when implementing bit-vector style sets atop BigIntegers. 0N/A * @return number of bits in the two's complement representation 0N/A * of this BigInteger that differ from its sign bit. 1246N/A if (
bc == -
1) {
// bitCount not initialized yet 1246N/A bc =
0;
// offset by one to initialize 0N/A // Count the bits in the magnitude 0N/A // Count the trailing zeros in the magnitude 0N/A // Primality Testing 0N/A * Returns {@code true} if this BigInteger is probably prime, 0N/A * {@code false} if it's definitely composite. If 1794N/A * {@code certainty} is ≤ 0, {@code true} is 0N/A * @param certainty a measure of the uncertainty that the caller is 0N/A * willing to tolerate: if the call returns {@code true} 0N/A * the probability that this BigInteger is prime exceeds 0N/A * (1 - 1/2<sup>{@code certainty}</sup>). The execution time of 0N/A * this method is proportional to the value of this parameter. 0N/A * @return {@code true} if this BigInteger is probably prime, 0N/A * {@code false} if it's definitely composite. 0N/A // Comparison Operations 0N/A * Compares this BigInteger with the specified BigInteger. This 0N/A * method is provided in preference to individual methods for each 0N/A * of the six boolean comparison operators ({@literal <}, ==, 0N/A * {@literal >}, {@literal >=}, !=, {@literal <=}). The suggested 0N/A * idiom for performing these comparisons is: {@code 0N/A * (x.compareTo(y)} <<i>op</i>> {@code 0)}, where 0N/A * <<i>op</i>> is one of the six comparison operators. 0N/A * @param val BigInteger to which this BigInteger is to be compared. 0N/A * @return -1, 0 or 1 as this BigInteger is numerically less than, equal 0N/A * to, or greater than {@code val}. 1246N/A * Compares the magnitude array of this BigInteger with the specified 1246N/A * BigInteger's. This is the version of compareTo ignoring sign. 1246N/A * @param val BigInteger whose magnitude array to be compared. 1246N/A * @return -1, 0 or 1 as this magnitude array is less than, equal to or 1246N/A * greater than the magnitude aray for the specified BigInteger's. 0N/A * Compares this BigInteger with the specified Object for equality. 0N/A * @param x Object to which this BigInteger is to be compared. 0N/A * @return {@code true} if and only if the specified Object is a 0N/A * BigInteger whose value is numerically equal to this BigInteger. 0N/A // This test is just an optimization, which may or may not help 0N/A * Returns the minimum of this BigInteger and {@code val}. 0N/A * @param val value with which the minimum is to be computed. 0N/A * @return the BigInteger whose value is the lesser of this BigInteger and 0N/A * {@code val}. If they are equal, either may be returned. 0N/A * Returns the maximum of this BigInteger and {@code val}. 0N/A * @param val value with which the maximum is to be computed. 0N/A * @return the BigInteger whose value is the greater of this and 0N/A * {@code val}. If they are equal, either may be returned. 0N/A * Returns the hash code for this BigInteger. 0N/A * @return hash code for this BigInteger. 0N/A * Returns the String representation of this BigInteger in the 0N/A * given radix. If the radix is outside the range from {@link 0N/A * Character#MIN_RADIX} to {@link Character#MAX_RADIX} inclusive, 0N/A * it will default to 10 (as is the case for 0N/A * {@code Integer.toString}). The digit-to-character mapping 0N/A * provided by {@code Character.forDigit} is used, and a minus 0N/A * sign is prepended if appropriate. (This representation is 0N/A * compatible with the {@link #BigInteger(String, int) (String, 0N/A * int)} constructor.) 0N/A * @param radix radix of the String representation. 0N/A * @return String representation of this BigInteger in the given radix. 0N/A * @see Integer#toString 0N/A * @see Character#forDigit 0N/A * @see #BigInteger(java.lang.String, int) 0N/A // Compute upper bound on number of digit groups and allocate space 0N/A // Translate number to string, a digit group at a time 0N/A // Put sign (if any) and first digit group into result buffer 0N/A // Append remaining digit groups padded with leading zeros 0N/A // Prepend (any) leading zeros for this digit group 0N/A /* zero[i] is a string of i consecutive zeros. */ 0N/A "000000000000000000000000000000000000000000000000000000000000000";
0N/A for (
int i=
0; i<
63; i++)
0N/A * Returns the decimal String representation of this BigInteger. 0N/A * The digit-to-character mapping provided by 0N/A * {@code Character.forDigit} is used, and a minus sign is 0N/A * prepended if appropriate. (This representation is compatible 0N/A * with the {@link #BigInteger(String) (String)} constructor, and 0N/A * allows for String concatenation with Java's + operator.) 0N/A * @return decimal String representation of this BigInteger. 0N/A * @see Character#forDigit 0N/A * @see #BigInteger(java.lang.String) 0N/A * Returns a byte array containing the two's-complement 0N/A * representation of this BigInteger. The byte array will be in 0N/A * <i>big-endian</i> byte-order: the most significant byte is in 0N/A * the zeroth element. The array will contain the minimum number 0N/A * of bytes required to represent this BigInteger, including at 0N/A * least one sign bit, which is {@code (ceil((this.bitLength() + 0N/A * 1)/8))}. (This representation is compatible with the 0N/A * {@link #BigInteger(byte[]) (byte[])} constructor.) 0N/A * @return a byte array containing the two's-complement representation of 0N/A * @see #BigInteger(byte[]) 0N/A * Converts this BigInteger to an {@code int}. This 4008N/A * conversion is analogous to a 4008N/A * <i>narrowing primitive conversion</i> from {@code long} to 4008N/A * {@code int} as defined in section 5.1.3 of 4008N/A * <cite>The Java™ Language Specification</cite>: 4008N/A * if this BigInteger is too big to fit in an 0N/A * {@code int}, only the low-order 32 bits are returned. 0N/A * Note that this conversion can lose information about the 0N/A * overall magnitude of the BigInteger value as well as return a 0N/A * result with the opposite sign. 0N/A * @return this BigInteger converted to an {@code int}. 0N/A * Converts this BigInteger to a {@code long}. This 4008N/A * conversion is analogous to a 4008N/A * <i>narrowing primitive conversion</i> from {@code long} to 4008N/A * {@code int} as defined in section 5.1.3 of 4008N/A * <cite>The Java™ Language Specification</cite>: 4008N/A * if this BigInteger is too big to fit in a 0N/A * {@code long}, only the low-order 64 bits are returned. 0N/A * Note that this conversion can lose information about the 0N/A * overall magnitude of the BigInteger value as well as return a 0N/A * result with the opposite sign. 0N/A * @return this BigInteger converted to a {@code long}. 0N/A for (
int i=
1; i>=
0; i--)
0N/A * Converts this BigInteger to a {@code float}. This 4008N/A * conversion is similar to the 4008N/A * <i>narrowing primitive conversion</i> from {@code double} to 4008N/A * {@code float} as defined in section 5.1.3 of 4008N/A * <cite>The Java™ Language Specification</cite>: 4008N/A * if this BigInteger has too great a magnitude 0N/A * to represent as a {@code float}, it will be converted to 0N/A * {@link Float#NEGATIVE_INFINITY} or {@link 0N/A * Float#POSITIVE_INFINITY} as appropriate. Note that even when 0N/A * the return value is finite, this conversion can lose 0N/A * information about the precision of the BigInteger value. 0N/A * @return this BigInteger converted to a {@code float}. 0N/A // Somewhat inefficient, but guaranteed to work. 0N/A * Converts this BigInteger to a {@code double}. This 4008N/A * conversion is similar to the 4008N/A * <i>narrowing primitive conversion</i> from {@code double} to 4008N/A * {@code float} as defined in section 5.1.3 of 4008N/A * <cite>The Java™ Language Specification</cite>: 4008N/A * if this BigInteger has too great a magnitude 0N/A * to represent as a {@code double}, it will be converted to 0N/A * {@link Double#NEGATIVE_INFINITY} or {@link 0N/A * Double#POSITIVE_INFINITY} as appropriate. Note that even when 0N/A * the return value is finite, this conversion can lose 0N/A * information about the precision of the BigInteger value. 0N/A * @return this BigInteger converted to a {@code double}. 0N/A // Somewhat inefficient, but guaranteed to work. 0N/A * Returns a copy of the input array stripped of any leading zero bytes. 0N/A // Find first nonzero byte 0N/A * Returns the input array stripped of any leading zero bytes. 0N/A * Since the source is trusted the copying may be skipped. 0N/A // Find first nonzero byte 0N/A * Returns a copy of the input array stripped of any leading zero bytes. 0N/A // Find first nonzero byte 0N/A // Allocate new array and copy relevant part of input array 0N/A * Takes an array a representing a negative 2's-complement number and 0N/A * returns the minimal (no leading zero bytes) unsigned whose value is -a. 0N/A // Find first non-sign (0xff) byte of input 0N/A /* Allocate output array. If all non-sign bytes are 0x00, we must 0N/A * allocate space for one extra output byte. */ 0N/A /* Copy one's complement of input into output, leaving extra 0N/A * byte (if it exists) == 0x00 */ 0N/A // Mask indicates which bits must be complemented 0N/A // Add one to one's complement to generate two's complement 0N/A * Takes an array a representing a negative 2's-complement number and 0N/A * returns the minimal (no leading zero ints) unsigned whose value is -a. 0N/A // Find first non-sign (0xffffffff) int of input 0N/A /* Allocate output array. If all non-sign ints are 0x00, we must 0N/A * allocate space for one extra output int. */ 0N/A /* Copy one's complement of input into output, leaving extra 0N/A * int (if it exists) == 0x00 */ 0N/A // Add one to one's complement to generate two's complement 0N/A * The following two arrays are used for fast String conversions. Both 0N/A * are indexed by radix. The first is the number of digits of the given 0N/A * radix that can fit in a Java long without "going negative", i.e., the 0N/A * highest integer n such that radix**n < 2**63. The second is the 0N/A * "long radix" that tears each number into "long digits", each of which 0N/A * consists of the number of digits in the corresponding element in 0N/A * digitsPerLong (longRadix[i] = i**digitPerLong[i]). Both arrays have 0N/A * nonsense values in their 0 and 1 elements, as radixes 0 and 1 are not 0N/A 62,
39,
31,
27,
24,
22,
20,
19,
18,
18,
17,
17,
16,
16,
15,
15,
15,
14,
0N/A 14,
14,
14,
13,
13,
13,
13,
13,
13,
12,
12,
12,
12,
12,
12,
12,
12};
0N/A * These two arrays are the integer analogue of above. 0N/A 11,
10,
9,
9,
8,
8,
8,
8,
7,
7,
7,
7,
7,
7,
7,
6,
6,
6,
6,
0N/A 6,
6,
6,
6,
6,
6,
6,
6,
6,
6,
5};
0N/A 0x40000000,
0x4546b3db,
0x40000000,
0x48c27395,
0x159fd800,
0N/A 0x75db9c97,
0x40000000,
0x17179149,
0x3b9aca00,
0xcc6db61,
0N/A 0x19a10000,
0x309f1021,
0x57f6c100,
0xa2f1b6f,
0x10000000,
0N/A 0x18754571,
0x247dbc80,
0x3547667b,
0x4c4b4000,
0x6b5a6e1d,
0N/A 0x6c20a40,
0x8d2d931,
0xb640000,
0xe8d4a51,
0x1269ae40,
0N/A 0x17179149,
0x1cb91000,
0x23744899,
0x2b73a840,
0x34e63b41,
0N/A 0x40000000,
0x4cfa3cc1,
0x5c13d840,
0x6d91b519,
0x39aa400 0N/A * These routines provide access to the two's complement representation 0N/A * Returns the length of the two's complement representation in ints, 0N/A * including space for at least one sign bit. 0N/A /* Returns sign bit */ 0N/A /* Returns an int of sign bits */ 0N/A * Returns the specified int of the little-endian two's complement 0N/A * representation (int 0 is the least significant). The int number can 0N/A * be arbitrarily high (values are logically preceded by infinitely many 0N/A * Returns the index of the int that contains the first nonzero int in the 0N/A * little-endian binary representation of the magnitude (int 0 is the 0N/A * least significant). If the magnitude is zero, return value is undefined. 1246N/A if (
fn == -
2) {
// firstNonzeroIntNum not initialized yet 1246N/A // Search for the first nonzero int 0N/A /** use serialVersionUID from JDK 1.1. for interoperability */ 0N/A * Serializable fields for BigInteger. 0N/A * @serialField signum int 0N/A * signum of this BigInteger. 0N/A * @serialField magnitude int[] 0N/A * magnitude array of this BigInteger. 0N/A * @serialField bitCount int 0N/A * number of bits in this BigInteger 0N/A * @serialField bitLength int 0N/A * the number of bits in the minimal two's-complement 0N/A * representation of this BigInteger 0N/A * @serialField lowestSetBit int 0N/A * lowest set bit in the twos complement representation 0N/A * Reconstitute the {@code BigInteger} instance from a stream (that is, 0N/A * deserialize it). The magnitude is read in as an array of bytes 0N/A * for historical reasons, but it is converted to an array of ints 0N/A * and the byte array is discarded. 1246N/A * The current convention is to initialize the cache fields, bitCount, 1246N/A * bitLength and lowestSetBit, to 0 rather than some other marker value. 1246N/A * Therefore, no explicit action to set these fields needs to be taken in 1246N/A * readObject because those fields already have a 0 value be default since 1246N/A * defaultReadObject is not being used. 0N/A * In order to maintain compatibility with previous serialized forms, 0N/A * the magnitude of a BigInteger is serialized as an array of bytes. 0N/A * The magnitude field is used as a temporary store for the byte array 0N/A * that is deserialized. The cached computation fields should be 0N/A * transient but are serialized for compatibility reasons. 0N/A // prepare to read the alternate persistent fields 0N/A // Read the alternate persistent fields that we care about 0N/A message =
"BigInteger: Signum not present in stream";
0N/A message =
"BigInteger: Magnitude not present in stream";
1246N/A // Commit final fields via Unsafe 0N/A // Calculate mag field from magnitude and discard magnitude 1246N/A // Support for resetting final fields while deserializing 0N/A * Save the {@code BigInteger} instance to a stream. 0N/A * The magnitude of a BigInteger is serialized as a byte array for 0N/A * historical reasons. 0N/A * @serialData two necessary fields are written as well as obsolete 0N/A * fields for compatibility with older versions. 0N/A // set the values of the Serializable fields 1246N/A // The values written for cached fields are compatible with older 1246N/A // versions, but are ignored in readObject so don't otherwise matter. 0N/A * Returns the mag array as an array of bytes.