Lines Matching +refs:val +refs:result

69  * return a non-negative result, between {@code 0} and {@code (modulus - 1)},
184 * @param val big-endian two's-complement binary representation of
186 * @throws NumberFormatException {@code val} is zero bytes long.
188 public BigInteger(byte[] val) {
189 if (val.length == 0)
192 if (val[0] < 0) {
193 mag = makePositive(val);
196 mag = stripLeadingZeroBytes(val);
207 private BigInteger(int[] val) {
208 if (val.length == 0)
211 if (val[0] < 0) {
212 mag = makePositive(val);
215 mag = trustedStripLeadingZeroInts(val);
226 * result in a BigInteger value of 0, whether signum is -1, 0 or 1.
281 * @param val String representation of BigInteger.
282 * @param radix radix to be used in interpreting {@code val}.
283 * @throws NumberFormatException {@code val} is not a valid representation
289 public BigInteger(String val, int radix) {
291 final int len = val.length();
300 int index1 = val.lastIndexOf('-');
301 int index2 = val.lastIndexOf('+');
316 Character.digit(val.charAt(cursor), radix) == 0)
337 String group = val.substring(cursor, cursor += firstGroupLen);
346 group = val.substring(cursor, cursor += digitsPerInt[radix]);
357 BigInteger(char[] val) {
359 int len = val.length;
363 if (val[0] == '-') {
368 } else if (val[0] == '+') {
375 while (cursor < len && Character.digit(val[cursor], 10) == 0)
400 magnitude[numWords - 1] = parseInt(val, cursor, cursor += firstGroupLen);
404 int groupVal = parseInt(val, cursor, cursor += digitsPerInt[10]);
411 // Assumes start < end. The result may be negative, but it
414 int result = Character.digit(source[start++], 10);
415 if (result == -1)
422 result = 10*result + nextVal;
425 return result;
470 * @param val decimal String representation of BigInteger.
471 * @throws NumberFormatException {@code val} is not a valid representation
475 public BigInteger(String val) {
476 this(val, 10);
664 BigInteger result = this.add(ONE);
667 if (result.bitLength() < SMALL_PRIME_THRESHOLD) {
670 if (!result.testBit(0))
671 result = result.add(ONE);
675 if (result.bitLength() > 6) {
676 long r = result.remainder(SMALL_PRIME_PRODUCT).longValue();
680 result = result.add(TWO);
686 if (result.bitLength() < 4)
687 return result;
690 if (result.primeToCertainty(DEFAULT_PRIME_CERTAINTY, null))
691 return result;
693 result = result.add(TWO);
698 if (result.testBit(0))
699 result = result.subtract(ONE);
702 int searchLen = (result.bitLength() / 20) * 64;
705 BitSieve searchSieve = new BitSieve(result, searchLen);
706 BigInteger candidate = searchSieve.retrieve(result,
710 result = result.add(BigInteger.valueOf(2 * searchLen));
945 * @param val value of the BigInteger to return.
948 public static BigInteger valueOf(long val) {
949 // If -MAX_CONSTANT < val < MAX_CONSTANT, return stashed constant
950 if (val == 0)
952 if (val > 0 && val <= MAX_CONSTANT)
953 return posConst[(int) val];
954 else if (val < 0 && val >= -MAX_CONSTANT)
955 return negConst[(int) -val];
957 return new BigInteger(val);
963 private BigInteger(long val) {
964 if (val < 0) {
965 val = -val;
971 int highWord = (int)(val >>> 32);
974 mag[0] = (int)val;
978 mag[1] = (int)val;
987 private static BigInteger valueOf(int val[]) {
988 return (val[0]>0 ? new BigInteger(val, 1) : new BigInteger(val));
1037 * Returns a BigInteger whose value is {@code (this + val)}.
1039 * @param val value to be added to this BigInteger.
1040 * @return {@code this + val}
1042 public BigInteger add(BigInteger val) {
1043 if (val.signum == 0)
1046 return val;
1047 if (val.signum == signum)
1048 return new BigInteger(add(mag, val.mag), signum);
1050 int cmp = compareMagnitude(val);
1053 int[] resultMag = (cmp > 0 ? subtract(mag, val.mag)
1054 : subtract(val.mag, mag));
1075 int result[] = new int[xIndex];
1082 result[xIndex] = (int)sum;
1088 carry = ((result[--xIndex] = x[xIndex] + 1) == 0);
1092 result[--xIndex] = x[xIndex];
1094 // Grow result if necessary
1096 int bigger[] = new int[result.length + 1];
1097 System.arraycopy(result, 0, bigger, 1, result.length);
1101 return result;
1105 * Returns a BigInteger whose value is {@code (this - val)}.
1107 * @param val value to be subtracted from this BigInteger.
1108 * @return {@code this - val}
1110 public BigInteger subtract(BigInteger val) {
1111 if (val.signum == 0)
1114 return val.negate();
1115 if (val.signum != signum)
1116 return new BigInteger(add(mag, val.mag), signum);
1118 int cmp = compareMagnitude(val);
1121 int[] resultMag = (cmp > 0 ? subtract(mag, val.mag)
1122 : subtract(val.mag, mag));
1135 int result[] = new int[bigIndex];
1144 result[bigIndex] = (int)difference;
1150 borrow = ((result[--bigIndex] = big[bigIndex] - 1) == -1);
1154 result[--bigIndex] = big[bigIndex];
1156 return result;
1160 * Returns a BigInteger whose value is {@code (this * val)}.
1162 * @param val value to be multiplied by this BigInteger.
1163 * @return {@code this * val}
1165 public BigInteger multiply(BigInteger val) {
1166 if (val.signum == 0 || signum == 0)
1169 int[] result = multiplyToLen(mag, mag.length,
1170 val.mag, val.mag.length, null);
1171 result = trustedStripLeadingZeroInts(result);
1172 return new BigInteger(result, signum == val.signum ? 1 : -1);
1219 * the result into z. There will be no leading zeros in the resultant array.
1264 * Squares the contents of the int array x. The result is placed into the
1331 * Returns a BigInteger whose value is {@code (this / val)}.
1333 * @param val value by which this BigInteger is to be divided.
1334 * @return {@code this / val}
1335 * @throws ArithmeticException if {@code val} is zero.
1337 public BigInteger divide(BigInteger val) {
1340 b = new MutableBigInteger(val.mag);
1343 return q.toBigInteger(this.signum == val.signum ? 1 : -1);
1347 * Returns an array of two BigIntegers containing {@code (this / val)}
1348 * followed by {@code (this % val)}.
1350 * @param val value by which this BigInteger is to be divided, and the
1352 * @return an array of two BigIntegers: the quotient {@code (this / val)}
1353 * is the initial element, and the remainder {@code (this % val)}
1355 * @throws ArithmeticException if {@code val} is zero.
1357 public BigInteger[] divideAndRemainder(BigInteger val) {
1358 BigInteger[] result = new BigInteger[2];
1361 b = new MutableBigInteger(val.mag);
1363 result[0] = q.toBigInteger(this.signum == val.signum ? 1 : -1);
1364 result[1] = r.toBigInteger(this.signum);
1365 return result;
1369 * Returns a BigInteger whose value is {@code (this % val)}.
1371 * @param val value by which this BigInteger is to be divided, and the
1373 * @return {@code this % val}
1374 * @throws ArithmeticException if {@code val} is zero.
1376 public BigInteger remainder(BigInteger val) {
1379 b = new MutableBigInteger(val.mag);
1402 int[] result = {1};
1406 result = multiplyToLen(result, result.length,
1408 result = trustedStripLeadingZeroInts(result);
1415 return new BigInteger(result, newSign);
1420 * {@code abs(this)} and {@code abs(val)}. Returns 0 if
1421 * {@code this==0 && val==0}.
1423 * @param val value with which the GCD is to be computed.
1424 * @return {@code GCD(abs(this), abs(val))}
1426 public BigInteger gcd(BigInteger val) {
1427 if (val.signum == 0)
1430 return val.abs();
1433 MutableBigInteger b = new MutableBigInteger(val);
1435 MutableBigInteger result = a.hybridGCD(b);
1437 return result.toBigInteger(1);
1462 int result[] = new int[nInts+len];
1464 result[i] = a[i];
1465 primitiveLeftShift(result, result.length, nBits);
1466 return result;
1468 int result[] = new int[nInts+len+1];
1470 result[i] = a[i];
1471 primitiveRightShift(result, result.length, 32 - nBits);
1472 return result;
1506 private static int bitLength(int[] val, int len) {
1509 return ((len - 1) << 5) + bitLengthForInt(val[0]);
1557 BigInteger result = this.remainder(m);
1558 return (result.signum >= 0 ? result : result.add(m));
1597 BigInteger result;
1599 result = base.oddModPow(exponent, m);
1628 result = a1.multiply(m2).multiply(y1).add
1632 return (invertResult ? result.modInverse(m) : result);
1668 * The loop walks down the exponent, squaring the result buffer as
1680 * When we start, there is one more optimization: the result buffer
1855 // Convert result out of Montgomery form and return
1927 * Multiply an array by one word k and add to result, return the carry
1974 BigInteger result = valueOf(1);
1985 result = result.multiply(baseToPow2).mod2(p);
1991 return result;
2042 MutableBigInteger result = a.mutableModInverse(b);
2043 return result.toBigInteger(1);
2169 int[] javaIncrement(int[] val) {
2171 for (int i=val.length-1; i >= 0 && lastSum == 0; i--)
2172 lastSum = (val[i] += 1);
2174 val = new int[val.length+1];
2175 val[0] = 1;
2177 return val;
2183 * Returns a BigInteger whose value is {@code (this & val)}. (This
2184 * method returns a negative BigInteger if and only if this and val are
2187 * @param val value to be AND'ed with this BigInteger.
2188 * @return {@code this & val}
2190 public BigInteger and(BigInteger val) {
2191 int[] result = new int[Math.max(intLength(), val.intLength())];
2192 for (int i=0; i<result.length; i++)
2193 result[i] = (getInt(result.length-i-1)
2194 & val.getInt(result.length-i-1));
2196 return valueOf(result);
2200 * Returns a BigInteger whose value is {@code (this | val)}. (This method
2201 * returns a negative BigInteger if and only if either this or val is
2204 * @param val value to be OR'ed with this BigInteger.
2205 * @return {@code this | val}
2207 public BigInteger or(BigInteger val) {
2208 int[] result = new int[Math.max(intLength(), val.intLength())];
2209 for (int i=0; i<result.length; i++)
2210 result[i] = (getInt(result.length-i-1)
2211 | val.getInt(result.length-i-1));
2213 return valueOf(result);
2217 * Returns a BigInteger whose value is {@code (this ^ val)}. (This method
2219 * val are negative.)
2221 * @param val value to be XOR'ed with this BigInteger.
2222 * @return {@code this ^ val}
2224 public BigInteger xor(BigInteger val) {
2225 int[] result = new int[Math.max(intLength(), val.intLength())];
2226 for (int i=0; i<result.length; i++)
2227 result[i] = (getInt(result.length-i-1)
2228 ^ val.getInt(result.length-i-1));
2230 return valueOf(result);
2241 int[] result = new int[intLength()];
2242 for (int i=0; i<result.length; i++)
2243 result[i] = ~getInt(result.length-i-1);
2245 return valueOf(result);
2249 * Returns a BigInteger whose value is {@code (this & ~val)}. This
2250 * method, which is equivalent to {@code and(val.not())}, is provided as
2252 * BigInteger if and only if {@code this} is negative and {@code val} is
2255 * @param val value to be complemented and AND'ed with this BigInteger.
2256 * @return {@code this & ~val}
2258 public BigInteger andNot(BigInteger val) {
2259 int[] result = new int[Math.max(intLength(), val.intLength())];
2260 for (int i=0; i<result.length; i++)
2261 result[i] = (getInt(result.length-i-1)
2262 & ~val.getInt(result.length-i-1));
2264 return valueOf(result);
2298 int[] result = new int[Math.max(intLength(), intNum+2)];
2300 for (int i=0; i<result.length; i++)
2301 result[result.length-i-1] = getInt(i);
2303 result[result.length-intNum-1] |= (1 << (n & 31));
2305 return valueOf(result);
2322 int[] result = new int[Math.max(intLength(), ((n + 1) >>> 5) + 1)];
2324 for (int i=0; i<result.length; i++)
2325 result[result.length-i-1] = getInt(i);
2327 result[result.length-intNum-1] &= ~(1 << (n & 31));
2329 return valueOf(result);
2346 int[] result = new int[Math.max(intLength(), intNum+2)];
2348 for (int i=0; i<result.length; i++)
2349 result[result.length-i-1] = getInt(i);
2351 result[result.length-intNum-1] ^= (1 << (n & 31));
2353 return valueOf(result);
2488 * @param val BigInteger to which this BigInteger is to be compared.
2490 * to, or greater than {@code val}.
2492 public int compareTo(BigInteger val) {
2493 if (signum == val.signum) {
2496 return compareMagnitude(val);
2498 return val.compareMagnitude(this);
2503 return signum > val.signum ? 1 : -1;
2510 * @param val BigInteger whose magnitude array to be compared.
2514 final int compareMagnitude(BigInteger val) {
2517 int[] m2 = val.mag;
2565 * Returns the minimum of this BigInteger and {@code val}.
2567 * @param val value with which the minimum is to be computed.
2569 * {@code val}. If they are equal, either may be returned.
2571 public BigInteger min(BigInteger val) {
2572 return (compareTo(val)<0 ? this : val);
2576 * Returns the maximum of this BigInteger and {@code val}.
2578 * @param val value with which the maximum is to be computed.
2580 * {@code val}. If they are equal, either may be returned.
2582 public BigInteger max(BigInteger val) {
2583 return (compareTo(val)>0 ? this : val);
2647 // Put sign (if any) and first digit group into result buffer
2730 * result with the opposite sign.
2735 int result = 0;
2736 result = getInt(0);
2737 return result;
2750 * result with the opposite sign.
2755 long result = 0;
2758 result = (result << 32) + (getInt(i) & LONG_MASK);
2759 return result;
2805 private static int[] stripLeadingZeroInts(int val[]) {
2806 int vlen = val.length;
2810 for (keep = 0; keep < vlen && val[keep] == 0; keep++)
2812 return java.util.Arrays.copyOfRange(val, keep, vlen);
2819 private static int[] trustedStripLeadingZeroInts(int val[]) {
2820 int vlen = val.length;
2824 for (keep = 0; keep < vlen && val[keep] == 0; keep++)
2826 return keep == 0 ? val : java.util.Arrays.copyOfRange(val, keep, vlen);
2842 int[] result = new int[intLength];
2845 result[i] = a[b--] & 0xff;
2849 result[i] |= ((a[b--] & 0xff) << j);
2851 return result;
2874 int result[] = new int[intLength];
2880 result[i] = a[b--] & 0xff;
2885 result[i] |= ((a[b--] & 0xff) << j);
2889 result[i] = ~result[i] & mask;
2893 for (int i=result.length-1; i>=0; i--) {
2894 result[i] = (int)((result[i] & LONG_MASK) + 1);
2895 if (result[i] != 0)
2899 return result;
2918 int result[] = new int[a.length - keep + extraInt];
2923 result[i - keep + extraInt] = ~a[i];
2926 for (int i=result.length-1; ++result[i]==0; i--)
2929 return result;
3171 byte[] result = new byte[byteLen];
3182 result[i] = (byte)nextInt;
3184 return result;