Refine search
int[] modules = new int[primes.length]; boolean isDivisible[] = new boolean[gapSize]; BigInt ni = n.getBigInt(); if (ni.bitLength() <= 10) { int l = (int)ni.longInt(); if (l < primes[primes.length - 1]) { for (i = 0; l >= primes[i]; i++) {} BigInt startPoint = ni.copy(); BigInt probPrime = new BigInt(); startPoint.addPositiveInt(BigInt.remainderByPositiveInt(ni, 2) + 1); modules[i] = BigInt.remainderByPositiveInt(startPoint, primes[i]) - gapSize; probPrime.putCopy(startPoint); probPrime.addPositiveInt(j); if (probPrime.isPrime(100)) { return new BigInteger(probPrime); startPoint.addPositiveInt(gapSize);
private static BigDecimal addAndMult10(BigDecimal thisValue,BigDecimal augend, int diffScale) { if(diffScale < MathUtils.LONG_POWERS_OF_TEN.length && Math.max(thisValue.bitLength,augend.bitLength+LONG_POWERS_OF_TEN_BIT_LENGTH[diffScale])+1<64) { return valueOf(thisValue.smallValue+augend.smallValue*MathUtils.LONG_POWERS_OF_TEN[diffScale],thisValue.scale); } else { BigInt bi = Multiplication.multiplyByTenPow(augend.getUnscaledValue(),diffScale).getBigInt(); bi.add(thisValue.getUnscaledValue().getBigInt()); return new BigDecimal(new BigInteger(bi), thisValue.scale); } }
/** * Returns a {@code BigInteger} whose value is {@code this + value}. */ public BigInteger add(BigInteger value) { BigInt lhs = getBigInt(); BigInt rhs = value.getBigInt(); if (rhs.sign() == 0) { return this; } if (lhs.sign() == 0) { return value; } return new BigInteger(BigInt.addition(lhs, rhs)); }
static BigInt exp(BigInt a, int p) { // Sign of p is ignored! BigInt power = new BigInt(); power.putLongInt(p); return bigExp(a, power); // OPTIONAL: // int BN_sqr(BigInteger r, BigInteger a, BN_CTX ctx); // int BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx); }
BigInteger(int sign, long value) { BigInt bigInt = new BigInt(); bigInt.putULongInt(value, (sign < 0)); setBigInt(bigInt); }
/** * Returns a {@code BigInteger} whose value is the absolute value of {@code * this}. */ public BigInteger abs() { BigInt bigInt = getBigInt(); if (bigInt.sign() >= 0) { return this; } BigInt a = bigInt.copy(); a.setSign(1); return new BigInteger(a); }
/** * Multiplies a number by a positive integer. * @param val an arbitrary {@code BigInteger} * @param factor a positive {@code int} number * @return {@code val * factor} */ static BigInteger multiplyByPositiveInt(BigInteger val, int factor) { BigInt bi = val.getBigInt().copy(); bi.multiplyByPositiveInt(factor); return new BigInteger(bi); }
smallValue = mantissa << (-scale); } else { BigInt bi = new BigInt(); bi.putLongInt(mantissa); bi.shift(-scale); intVal = new BigInteger(bi); bitLength = bitLength(smallValue); } else { setUnscaledValue(Multiplication.multiplyByFivePow(BigInteger.valueOf(mantissa), scale));
/** * Returns a {@code BigInteger} whose value is {@code this / divisor}. * * @param divisor value by which {@code this} is divided. * @return {@code this / divisor}. * @throws NullPointerException if {@code divisor == null}. * @throws ArithmeticException if {@code divisor == 0}. */ public BigInteger divide(BigInteger divisor) { BigInt quotient = new BigInt(); BigInt.division(getBigInt(), divisor.getBigInt(), quotient, null); return new BigInteger(quotient); }
candidate |= 1; // Any prime longer than 2 bits must have the bottom bit set. } while (!isSmallPrime(candidate)); BigInt prime = new BigInt(); prime.putULongInt(candidate, false); setBigInt(prime); } else { setBigInt(BigInt.generatePrimeDefault(bitLength)); } while (bitLength() != bitLength);
void putHexString(String original) { String s = checkString(original, 16); this.makeValid(); int usedLen = NativeBN.BN_hex2bn(this.bignum, s); if (usedLen < s.length()) { throw invalidBigInteger(original); } }
/** * Prepares this {@code BigInteger} for serialization, i.e. the * non-transient fields {@code signum} and {@code magnitude} are assigned. */ private void writeObject(ObjectOutputStream out) throws IOException { BigInt bigInt = getBigInt(); signum = bigInt.sign(); magnitude = bigInt.bigEndianMagnitude(); out.defaultWriteObject(); } }
BigInt bigInt = new BigInt(); bigInt.putDecString(value); setBigInt(bigInt); } else if (radix == 16) { BigInt bigInt = new BigInt(); bigInt.putHexString(value); setBigInt(bigInt); } else { if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) { throw new NumberFormatException("value.isEmpty()"); BigInteger.parseFromString(this, value, radix);
/** * Assigns all transient fields upon deserialization of a {@code BigInteger} * instance. */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); BigInt bigInt = new BigInt(); bigInt.putBigEndian(magnitude, signum < 0); setBigInt(bigInt); }
/** * Compares this {@code BigInteger} with {@code value}. Returns {@code -1} * if {@code this < value}, {@code 0} if {@code this == value} and {@code 1} * if {@code this > value}, . * * @param value value to be compared with {@code this}. * @throws NullPointerException if {@code value == null}. */ public int compareTo(BigInteger value) { return BigInt.cmp(getBigInt(), value.getBigInt()); }
/** * Returns the length of the value's two's complement representation without * leading zeros for positive numbers / without leading ones for negative * values. * * <p>The two's complement representation of {@code this} will be at least * {@code bitLength() + 1} bits long. * * <p>The value will fit into an {@code int} if {@code bitLength() < 32} or * into a {@code long} if {@code bitLength() < 64}. * * @return the length of the minimal two's complement representation for * {@code this} without the sign bit. */ public int bitLength() { // Optimization to avoid unnecessary duplicate representation: if (!nativeIsValid && javaIsValid) { return BitLevel.bitLength(this); } return getBigInt().bitLength(); }
/** * Constructs a new {@code BigInteger} by parsing {@code value}. The string * representation consists of an optional plus or minus sign followed by a * non-empty sequence of decimal digits. Digits are interpreted as if by * {@code Character.digit(char,10)}. * * @param value string representation of the new {@code BigInteger}. * @throws NullPointerException if {@code value == null}. * @throws NumberFormatException if {@code value} is not a valid * representation of a {@code BigInteger}. */ public BigInteger(String value) { BigInt bigInt = new BigInt(); bigInt.putDecString(value); setBigInt(bigInt); }
/** * Returns the internal native representation of this big integer, computing * it if necessary. */ BigInt getBigInt() { if (nativeIsValid) { return bigInt; } synchronized (this) { if (nativeIsValid) { return bigInt; } BigInt bigInt = new BigInt(); bigInt.putLittleEndianInts(digits, (sign < 0)); setBigInt(bigInt); return bigInt; } }
/** * Constructs a new {@code BigInteger} from the given two's complement * representation. The most significant byte is the entry at index 0. The * most significant bit of this entry determines the sign of the new {@code * BigInteger} instance. The array must be nonempty. * * @param value two's complement representation of the new {@code * BigInteger}. * @throws NullPointerException if {@code value == null}. * @throws NumberFormatException if the length of {@code value} is zero. */ public BigInteger(byte[] value) { if (value.length == 0) { throw new NumberFormatException("value.length == 0"); } BigInt bigInt = new BigInt(); bigInt.putBigEndianTwosComplement(value); setBigInt(bigInt); }