Lines Matching defs:BigInteger

48  * primitive integer types).  BigInteger provides analogues to all of Java's
50 * Additionally, BigInteger provides operations for modular arithmetic, GCD
85 * operations can produce a BigInteger with a different sign from the
86 * BigInteger being operated on, as they affect only a single bit, and the
88 * are infinitely many "virtual sign bits" preceding each BigInteger.
91 * descriptions of BigInteger methods. The pseudo-code expression
92 * {@code (i + j)} is shorthand for "a BigInteger whose value is
93 * that of the BigInteger {@code i} plus that of the BigInteger {@code j}."
95 * "{@code true} if and only if the BigInteger {@code i} represents the same
96 * value as the BigInteger {@code j}." Other pseudo-code expressions are
103 * BigInteger must support values in the range
109 * the full supported positive range of {@code BigInteger}.
113 * BigInteger constructors and operations throw {@code ArithmeticException} when
127 public class BigInteger extends Number implements Comparable<BigInteger> {
129 * The signum of this BigInteger: -1 for negative, 0 for zero, or
130 * 1 for positive. Note that the BigInteger zero <em>must</em> have
132 * representation for each BigInteger value.
137 * The magnitude of this BigInteger, in <i>big-endian</i> order: the
141 * ensure that there is exactly one representation for each BigInteger
142 * value. Note that this implies that the BigInteger zero has a
152 * One plus the bitCount of this BigInteger. This is a stable variable.
159 * One plus the bitLength of this BigInteger. This is a stable variable.
167 * Two plus the lowest set bit of this BigInteger. This is a stable variable.
175 * BigInteger that contains a nonzero int. This is a stable variable. The
179 * <p>Note: never used for a BigInteger with a magnitude of zero.
263 * of a {@code BigInteger} instance by itself. If the number of ints in
282 * representation of a BigInteger into a BigInteger. The sub-array is
294 * two's-complement binary representation of a BigInteger.
303 public BigInteger(byte[] val, int off, int len) {
305 throw new NumberFormatException("Zero length BigInteger");
325 * representation of a BigInteger into a BigInteger. The input array is
331 * BigInteger.
334 public BigInteger(byte[] val) {
340 * two's-complement binary representation of a BigInteger into a
341 * BigInteger. The input array is assumed to be in <i>big-endian</i>
346 private BigInteger(int[] val) {
348 throw new NumberFormatException("Zero length BigInteger");
363 * Translates the sign-magnitude representation of a BigInteger into a
364 * BigInteger. The sign is represented as an integer signum value: -1 for
368 * {@code len} is permissible, and will result in a BigInteger value of 0,
391 public BigInteger(int signum, byte[] magnitude, int off, int len) {
417 * Translates the sign-magnitude representation of a BigInteger into a
418 * BigInteger. The sign is represented as an integer signum value: -1 for
422 * result in a BigInteger value of 0, whether signum is -1, 0 or 1. The
434 public BigInteger(int signum, byte[] magnitude) {
440 * representation of a BigInteger into a BigInteger. It checks the
445 private BigInteger(int signum, int[] magnitude) {
464 * Translates the String representation of a BigInteger in the
465 * specified radix into a BigInteger. The String representation
472 * @param val String representation of BigInteger.
475 * of a BigInteger in the specified radix, or {@code radix} is
480 public BigInteger(String val, int radix) {
487 throw new NumberFormatException("Zero length BigInteger");
506 throw new NumberFormatException("Zero length BigInteger");
559 * Constructs a new BigInteger using a char array with radix=10.
564 BigInteger(char[] val, int sign, int len) {
662 * Translates the decimal String representation of a BigInteger into a
663 * BigInteger. The String representation consists of an optional minus
669 * @param val decimal String representation of BigInteger.
671 * of a BigInteger.
674 public BigInteger(String val) {
679 * Constructs a randomly generated BigInteger, uniformly distributed over
683 * constructs a non-negative BigInteger.
685 * @param numBits maximum bitLength of the new BigInteger.
687 * BigInteger.
691 public BigInteger(int numBits, Random rnd) {
711 * Constructs a randomly generated positive BigInteger that is probably
718 * @param bitLength bitLength of the returned BigInteger.
720 * willing to tolerate. The probability that the new BigInteger
729 public BigInteger(int bitLength, int certainty, Random rnd) {
730 BigInteger prime;
750 * Returns a positive BigInteger that is probably prime, with the
751 * specified bitLength. The probability that a BigInteger returned
754 * @param bitLength bitLength of the returned BigInteger.
757 * @return a BigInteger of {@code bitLength} bits that is probably prime
762 public static BigInteger probablePrime(int bitLength, Random rnd) {
778 private static BigInteger smallPrime(int bitLength, int certainty, Random rnd) {
792 BigInteger p = new BigInteger(temp, 1);
813 private static final BigInteger SMALL_PRIME_PRODUCT
822 private static BigInteger largePrime(int bitLength, int certainty, Random rnd) {
823 BigInteger p;
824 p = new BigInteger(bitLength, rnd).setBit(bitLength-1);
830 BigInteger candidate = searchSieve.retrieve(p, certainty, rnd);
833 p = p.add(BigInteger.valueOf(2*searchLen));
835 p = new BigInteger(bitLength, rnd).setBit(bitLength-1);
844 * Returns the first integer greater than this {@code BigInteger} that
850 * @return the first integer greater than this {@code BigInteger} that
855 public BigInteger nextProbablePrime() {
863 BigInteger result = this.add(ONE);
905 BigInteger candidate = searchSieve.retrieve(result,
909 result = result.add(BigInteger.valueOf(2 * searchLen));
921 * Returns {@code true} if this BigInteger is probably prime,
928 * the probability that this BigInteger is prime exceeds
931 * @return {@code true} if this BigInteger is probably prime,
965 * Returns true iff this BigInteger is a Lucas-Lehmer probable prime.
968 * This BigInteger is a positive, odd number.
971 BigInteger thisPlusOne = this.add(ONE);
981 BigInteger u = lucasLehmerSequence(d, thisPlusOne, this);
991 private static int jacobiSymbol(int p, BigInteger n) {
1021 u = n.mod(BigInteger.valueOf(p)).intValue();
1045 private static BigInteger lucasLehmerSequence(int z, BigInteger k, BigInteger n) {
1046 BigInteger d = BigInteger.valueOf(z);
1047 BigInteger u = ONE; BigInteger u2;
1048 BigInteger v = ONE; BigInteger v2;
1078 * Returns true iff this BigInteger passes the specified number of
1083 * This BigInteger is a positive, odd number greater than 2.
1088 BigInteger thisMinusOne = this.subtract(ONE);
1089 BigInteger m = thisMinusOne;
1099 BigInteger b;
1101 b = new BigInteger(this.bitLength(), rnd);
1105 BigInteger z = b.modPow(m, this);
1120 BigInteger(int[] magnitude, int signum) {
1133 private BigInteger(byte[] magnitude, int signum) {
1142 * Throws an {@code ArithmeticException} if the {@code BigInteger} would be
1154 throw new ArithmeticException("BigInteger would overflow supported range");
1160 * Returns a BigInteger whose value is equal to that of the
1167 * @param val value of the BigInteger to return.
1168 * @return a BigInteger with the specified value.
1170 public static BigInteger valueOf(long val) {
1179 return new BigInteger(val);
1183 * Constructs a BigInteger with the specified value, which may not be zero.
1185 private BigInteger(long val) {
1205 * Returns a BigInteger with the given two's complement representation.
1207 * BigInteger will reference the input array if feasible).
1209 private static BigInteger valueOf(int val[]) {
1210 return (val[0] > 0 ? new BigInteger(val, 1) : new BigInteger(val));
1219 private static BigInteger posConst[] = new BigInteger[MAX_CONSTANT+1];
1220 private static BigInteger negConst[] = new BigInteger[MAX_CONSTANT+1];
1227 private static volatile BigInteger[][] powerCache;
1239 posConst[i] = new BigInteger(magnitude, 1);
1240 negConst[i] = new BigInteger(magnitude, -1);
1248 powerCache = new BigInteger[Character.MAX_RADIX+1][];
1252 powerCache[i] = new BigInteger[] { BigInteger.valueOf(i) };
1258 * The BigInteger constant zero.
1262 public static final BigInteger ZERO = new BigInteger(new int[0], 0);
1265 * The BigInteger constant one.
1269 public static final BigInteger ONE = valueOf(1);
1272 * The BigInteger constant two.
1276 public static final BigInteger TWO = valueOf(2);
1279 * The BigInteger constant -1. (Not exported.)
1281 private static final BigInteger NEGATIVE_ONE = valueOf(-1);
1284 * The BigInteger constant ten.
1288 public static final BigInteger TEN = valueOf(10);
1293 * Returns a BigInteger whose value is {@code (this + val)}.
1295 * @param val value to be added to this BigInteger.
1298 public BigInteger add(BigInteger val) {
1304 return new BigInteger(add(mag, val.mag), signum);
1313 return new BigInteger(resultMag, cmp == signum ? 1 : -1);
1317 * Package private methods used by BigDecimal code to add a BigInteger
1320 BigInteger add(long val) {
1326 return new BigInteger(add(mag, Math.abs(val)), signum);
1332 return new BigInteger(resultMag, cmp == signum ? 1 : -1);
1495 * Returns a BigInteger whose value is {@code (this - val)}.
1497 * @param val value to be subtracted from this BigInteger.
1500 public BigInteger subtract(BigInteger val) {
1506 return new BigInteger(add(mag, val.mag), signum);
1514 return new BigInteger(resultMag, cmp == signum ? 1 : -1);
1550 * Returns a BigInteger whose value is {@code (this * val)}.
1555 * @param val value to be multiplied by this BigInteger.
1558 public BigInteger multiply(BigInteger val) {
1581 return new BigInteger(result, resultSign);
1591 private static BigInteger multiplyByInt(int[] x, int y, int sign) {
1593 return new BigInteger(shiftLeft(x,Integer.numberOfTrailingZeros(y)), sign);
1610 return new BigInteger(rmag, sign);
1614 * Package private methods used by BigDecimal code to multiply a BigInteger
1617 BigInteger multiply(long v) {
1621 return multiply(BigInteger.valueOf(v));
1652 return new BigInteger(rmag, rsign);
1723 private static BigInteger multiplyKaratsuba(BigInteger x, BigInteger y) {
1732 BigInteger xl = x.getLower(half);
1733 BigInteger xh = x.getUpper(half);
1734 BigInteger yl = y.getLower(half);
1735 BigInteger yh = y.getUpper(half);
1737 BigInteger p1 = xh.multiply(yh); // p1 = xh*yh
1738 BigInteger p2 = xl.multiply(yl); // p2 = xl*yl
1741 BigInteger p3 = xh.add(xl).multiply(yh.add(yl));
1744 BigInteger result = p1.shiftLeft(32*half).add(p3.subtract(p1).subtract(p2)).shiftLeft(32*half).add(p2);
1781 private static BigInteger multiplyToomCook3(BigInteger a, BigInteger b) {
1795 BigInteger a0, a1, a2, b0, b1, b2;
1803 BigInteger v0, v1, v2, vm1, vinf, t1, t2, tm1, da1, db1;
1833 BigInteger result = vinf.shiftLeft(ss).add(t2).shiftLeft(ss).add(t1).shiftLeft(ss).add(tm1).shiftLeft(ss).add(v0);
1844 * Returns a slice of a BigInteger for use in Toom-Cook multiplication.
1856 private BigInteger getToomSlice(int lowerSize, int upperSize, int slice,
1893 return new BigInteger(trustedStripLeadingZeroInts(intSlice), 1);
1904 private BigInteger exactDivideBy3() {
1933 return new BigInteger(result, signum);
1937 * Returns a new BigInteger representing n lower ints of the number.
1940 private BigInteger getLower(int n) {
1950 return new BigInteger(trustedStripLeadingZeroInts(lowerInts), 1);
1954 * Returns a new BigInteger representing mag.length-n upper
1958 private BigInteger getUpper(int n) {
1969 return new BigInteger(trustedStripLeadingZeroInts(upperInts), 1);
1975 * Returns a BigInteger whose value is {@code (this<sup>2</sup>)}.
1979 private BigInteger square() {
1987 return new BigInteger(trustedStripLeadingZeroInts(z), 1);
2100 * Squares a BigInteger using the Karatsuba squaring algorithm. It should
2106 private BigInteger squareKaratsuba() {
2109 BigInteger xl = getLower(half);
2110 BigInteger xh = getUpper(half);
2112 BigInteger xhs = xh.square(); // xhs = xh^2
2113 BigInteger xls = xl.square(); // xls = xl^2
2120 * Squares a BigInteger using the 3-way Toom-Cook squaring algorithm. It
2126 private BigInteger squareToomCook3() {
2137 BigInteger a0, a1, a2;
2141 BigInteger v0, v1, v2, vm1, vinf, t1, t2, tm1, da1;
2174 * Returns a BigInteger whose value is {@code (this / val)}.
2176 * @param val value by which this BigInteger is to be divided.
2180 public BigInteger divide(BigInteger val) {
2190 * Returns a BigInteger whose value is {@code (this / val)} using an O(n^2) algorithm from Knuth.
2192 * @param val value by which this BigInteger is to be divided.
2197 private BigInteger divideKnuth(BigInteger val) {
2210 * @param val value by which this BigInteger is to be divided, and the
2217 public BigInteger[] divideAndRemainder(BigInteger val) {
2227 private BigInteger[] divideAndRemainderKnuth(BigInteger val) {
2228 BigInteger[] result = new BigInteger[2];
2239 * Returns a BigInteger whose value is {@code (this % val)}.
2241 * @param val value by which this BigInteger is to be divided, and the
2246 public BigInteger remainder(BigInteger val) {
2256 private BigInteger remainderKnuth(BigInteger val) {
2269 private BigInteger divideBurnikelZiegler(BigInteger val) {
2278 private BigInteger remainderBurnikelZiegler(BigInteger val) {
2288 private BigInteger[] divideAndRemainderBurnikelZiegler(BigInteger val) {
2291 BigInteger qBigInt = q.isZero() ? ZERO : q.toBigInteger(signum*val.signum);
2292 BigInteger rBigInt = r.isZero() ? ZERO : r.toBigInteger(signum);
2293 return new BigInteger[] {qBigInt, rBigInt};
2297 * Returns a BigInteger whose value is <code>(this<sup>exponent</sup>)</code>.
2298 * Note that {@code exponent} is an integer rather than a BigInteger.
2300 * @param exponent exponent to which this BigInteger is to be raised.
2305 public BigInteger pow(int exponent) {
2313 BigInteger partToSquare = this.abs();
2390 BigInteger answer = ONE;
2418 * Returns the integer square root of this BigInteger. The integer square
2434 public BigInteger sqrt() {
2436 throw new ArithmeticException("Negative BigInteger");
2457 public BigInteger[] sqrtAndRemainder() {
2458 BigInteger s = sqrt();
2459 BigInteger r = this.subtract(s.square());
2460 assert r.compareTo(BigInteger.ZERO) >= 0;
2461 return new BigInteger[] {s, r};
2465 * Returns a BigInteger whose value is the greatest common divisor of
2472 public BigInteger gcd(BigInteger val) {
2557 * Returns a BigInteger whose value is the absolute value of this
2558 * BigInteger.
2562 public BigInteger abs() {
2567 * Returns a BigInteger whose value is {@code (-this)}.
2571 public BigInteger negate() {
2572 return new BigInteger(this.mag, -this.signum);
2576 * Returns the signum function of this BigInteger.
2578 * @return -1, 0 or 1 as the value of this BigInteger is negative, zero or
2588 * Returns a BigInteger whose value is {@code (this mod m}). This method
2590 * <i>non-negative</i> BigInteger.
2597 public BigInteger mod(BigInteger m) {
2599 throw new ArithmeticException("BigInteger: modulus not positive");
2601 BigInteger result = this.remainder(m);
2606 * Returns a BigInteger whose value is
2614 * negative and this BigInteger is not <i>relatively
2618 public BigInteger modPow(BigInteger exponent, BigInteger m) {
2620 throw new ArithmeticException("BigInteger: modulus not positive");
2639 BigInteger base = (this.signum < 0 || this.compareTo(m) >= 0
2641 BigInteger result;
2654 BigInteger m1 = m.shiftRight(p); // m/2**p
2655 BigInteger m2 = ONE.shiftLeft(p); // 2**p
2658 BigInteger base2 = (this.signum < 0 || this.compareTo(m1) >= 0
2662 BigInteger a1 = (m1.equals(ONE) ? ZERO :
2666 BigInteger a2 = base.modPow2(exponent, p);
2669 BigInteger y1 = m2.modInverse(m1);
2670 BigInteger y2 = m1.modInverse(m2);
2763 * Returns a BigInteger whose value is x to the power of y mod z.
2766 private BigInteger oddModPow(BigInteger y, BigInteger z) {
2995 return new BigInteger(1, t2);
3123 * Returns a BigInteger whose value is (this ** exponent) mod (2**p)
3125 private BigInteger modPow2(BigInteger exponent, int p) {
3130 BigInteger result = ONE;
3131 BigInteger baseToPow2 = this.mod2(p);
3151 * Returns a BigInteger whose value is this mod(2**p).
3152 * Assumes that this {@code BigInteger >= 0} and {@code p > 0}.
3154 private BigInteger mod2(int p) {
3167 return (mag[0] == 0 ? new BigInteger(1, mag) : new BigInteger(mag, 1));
3171 * Returns a BigInteger whose value is {@code (this}<sup>-1</sup> {@code mod m)}.
3175 * @throws ArithmeticException {@code m} &le; 0, or this BigInteger
3176 * has no multiplicative inverse mod m (that is, this BigInteger
3179 public BigInteger modInverse(BigInteger m) {
3181 throw new ArithmeticException("BigInteger: modulus not positive");
3187 BigInteger modVal = this;
3204 * Returns a BigInteger whose value is {@code (this << n)}.
3213 public BigInteger shiftLeft(int n) {
3217 return new BigInteger(shiftLeft(mag, n), signum);
3264 * Returns a BigInteger whose value is {@code (this >> n)}. Sign
3273 public BigInteger shiftRight(int n) {
3283 return new BigInteger(shiftLeft(mag, -n), signum);
3288 * Returns a BigInteger whose value is {@code (this >> n)}. The shift
3295 private BigInteger shiftRightImpl(int n) {
3336 return new BigInteger(newMag, signum);
3353 * Returns a BigInteger whose value is {@code (this & val)}. (This
3354 * method returns a negative BigInteger if and only if this and val are
3357 * @param val value to be AND'ed with this BigInteger.
3360 public BigInteger and(BigInteger val) {
3370 * Returns a BigInteger whose value is {@code (this | val)}. (This method
3371 * returns a negative BigInteger if and only if either this or val is
3374 * @param val value to be OR'ed with this BigInteger.
3377 public BigInteger or(BigInteger val) {
3387 * Returns a BigInteger whose value is {@code (this ^ val)}. (This method
3388 * returns a negative BigInteger if and only if exactly one of this and
3391 * @param val value to be XOR'ed with this BigInteger.
3394 public BigInteger xor(BigInteger val) {
3404 * Returns a BigInteger whose value is {@code (~this)}. (This method
3405 * returns a negative value if and only if this BigInteger is
3410 public BigInteger not() {
3419 * Returns a BigInteger whose value is {@code (this & ~val)}. This
3422 * BigInteger if and only if {@code this} is negative and {@code val} is
3425 * @param val value to be complemented and AND'ed with this BigInteger.
3428 public BigInteger andNot(BigInteger val) {
3456 * Returns a BigInteger whose value is equivalent to this BigInteger
3463 public BigInteger setBit(int n) {
3479 * Returns a BigInteger whose value is equivalent to this BigInteger
3487 public BigInteger clearBit(int n) {
3503 * Returns a BigInteger whose value is equivalent to this BigInteger
3511 public BigInteger flipBit(int n) {
3528 * BigInteger (the number of zero bits to the right of the rightmost
3529 * one bit). Returns -1 if this BigInteger contains no one bits.
3532 * @return index of the rightmost one bit in this BigInteger.
3557 * representation of this BigInteger, <em>excluding</em> a sign bit.
3563 * representation of this BigInteger, <em>excluding</em> a sign bit.
3593 * of this BigInteger that differ from its sign bit. This method is
3597 * of this BigInteger that differ from its sign bit.
3622 * Returns {@code true} if this BigInteger is probably prime,
3629 * the probability that this BigInteger is prime exceeds
3632 * @return {@code true} if this BigInteger is probably prime,
3638 BigInteger w = this.abs();
3650 * Compares this BigInteger with the specified BigInteger. This
3658 * @param val BigInteger to which this BigInteger is to be compared.
3659 * @return -1, 0 or 1 as this BigInteger is numerically less than, equal
3662 public int compareTo(BigInteger val) {
3677 * Compares the magnitude array of this BigInteger with the specified
3678 * BigInteger's. This is the version of compareTo ignoring sign.
3680 * @param val BigInteger whose magnitude array to be compared.
3682 * greater than the magnitude aray for the specified BigInteger's.
3684 final int compareMagnitude(BigInteger val) {
3746 * Compares this BigInteger with the specified Object for equality.
3748 * @param x Object to which this BigInteger is to be compared.
3750 * BigInteger whose value is numerically equal to this BigInteger.
3757 if (!(x instanceof BigInteger))
3760 BigInteger xInt = (BigInteger) x;
3778 * Returns the minimum of this BigInteger and {@code val}.
3781 * @return the BigInteger whose value is the lesser of this BigInteger and
3784 public BigInteger min(BigInteger val) {
3789 * Returns the maximum of this BigInteger and {@code val}.
3792 * @return the BigInteger whose value is the greater of this and
3795 public BigInteger max(BigInteger val) {
3803 * Returns the hash code for this BigInteger.
3805 * @return hash code for this BigInteger.
3817 * Returns the String representation of this BigInteger in the
3824 * compatible with the {@link #BigInteger(String, int) (String,
3828 * @return String representation of this BigInteger in the given radix.
3831 * @see #BigInteger(java.lang.String, int)
3867 BigInteger tmp = this.abs();
3870 BigInteger d = longRadix[radix];
3876 BigInteger q2 = q.toBigInteger(tmp.signum * d.signum);
3877 BigInteger r2 = r.toBigInteger(tmp.signum * d.signum);
3903 * Converts the specified BigInteger to a string and appends to
3915 private static void toString(BigInteger u, StringBuilder sb, int radix,
3941 BigInteger v = getRadixConversionCache(radix, n);
3942 BigInteger[] results;
3959 private static BigInteger getRadixConversionCache(int radix, int exponent) {
3960 BigInteger[] cacheLine = powerCache[radix]; // volatile read
3971 BigInteger[][] pc = powerCache; // volatile read again
3990 * Returns the decimal String representation of this BigInteger.
3994 * with the {@link #BigInteger(String) (String)} constructor, and
3997 * @return decimal String representation of this BigInteger.
3999 * @see #BigInteger(java.lang.String)
4007 * representation of this BigInteger. The byte array will be in
4010 * of bytes required to represent this BigInteger, including at
4013 * {@link #BigInteger(byte[]) (byte[])} constructor.)
4016 * this BigInteger.
4017 * @see #BigInteger(byte[])
4037 * Converts this BigInteger to an {@code int}. This
4042 * if this BigInteger is too big to fit in an
4045 * overall magnitude of the BigInteger value as well as return a
4048 * @return this BigInteger converted to an {@code int}.
4059 * Converts this BigInteger to a {@code long}. This
4064 * if this BigInteger is too big to fit in a
4067 * overall magnitude of the BigInteger value as well as return a
4070 * @return this BigInteger converted to a {@code long}.
4083 * Converts this BigInteger to a {@code float}. This
4088 * if this BigInteger has too great a magnitude
4093 * information about the precision of the BigInteger value.
4095 * @return this BigInteger converted to a {@code float}.
4168 * Converts this BigInteger to a {@code double}. This
4173 * if this BigInteger has too great a magnitude
4178 * information about the precision of the BigInteger value.
4180 * @return this BigInteger converted to a {@code double}.
4405 private static BigInteger longRadix[] = {null, null,
4488 * <p>Note: never used for a BigInteger with a magnitude of zero.
4509 * Serializable fields for BigInteger.
4512 * signum of this BigInteger
4514 * magnitude array of this BigInteger
4534 * Reconstitute the {@code BigInteger} instance from a stream (that is,
4556 String message = "BigInteger: Invalid signum value";
4558 message = "BigInteger: Signum not present in stream";
4563 String message = "BigInteger: signum-magnitude mismatch";
4565 message = "BigInteger: Magnitude not present in stream";
4578 throw new java.io.StreamCorruptedException("BigInteger: Out of the supported range");
4588 = unsafe.objectFieldOffset(BigInteger.class, "signum");
4590 = unsafe.objectFieldOffset(BigInteger.class, "mag");
4592 static void putSign(BigInteger bi, int sign) {
4596 static void putMag(BigInteger bi, int[] magnitude) {
4602 * Save the {@code BigInteger} instance to a stream. The magnitude of a
4603 * {@code BigInteger} is serialized as a byte array for historical reasons.
4652 * Converts this {@code BigInteger} to a {@code long}, checking
4653 * for lost information. If the value of this {@code BigInteger}
4657 * @return this {@code BigInteger} converted to a {@code long}.
4660 * @see BigInteger#longValue
4667 throw new ArithmeticException("BigInteger out of long range");
4671 * Converts this {@code BigInteger} to an {@code int}, checking
4672 * for lost information. If the value of this {@code BigInteger}
4676 * @return this {@code BigInteger} converted to an {@code int}.
4679 * @see BigInteger#intValue
4686 throw new ArithmeticException("BigInteger out of int range");
4690 * Converts this {@code BigInteger} to a {@code short}, checking
4691 * for lost information. If the value of this {@code BigInteger}
4695 * @return this {@code BigInteger} converted to a {@code short}.
4698 * @see BigInteger#shortValue
4707 throw new ArithmeticException("BigInteger out of short range");
4711 * Converts this {@code BigInteger} to a {@code byte}, checking
4712 * for lost information. If the value of this {@code BigInteger}
4716 * @return this {@code BigInteger} converted to a {@code byte}.
4719 * @see BigInteger#byteValue
4728 throw new ArithmeticException("BigInteger out of byte range");