private static BigInt newBigInt() { BigInt bi = new BigInt(); bi.bignum = NativeBN.BN_new(); return bi; }
BigInt copy() { BigInt bi = new BigInt(); bi.putCopy(this); return bi; }
/** * 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); }
/** * Returns a two element {@code BigInteger} array containing * {@code this / divisor} at index 0 and {@code this % divisor} at index 1. * * @param divisor value by which {@code this} is divided. * @throws NullPointerException if {@code divisor == null}. * @throws ArithmeticException if {@code divisor == 0}. * @see #divide * @see #remainder */ public BigInteger[] divideAndRemainder(BigInteger divisor) { BigInt divisorBigInt = divisor.getBigInt(); BigInt quotient = new BigInt(); BigInt remainder = new BigInt(); BigInt.division(getBigInt(), divisorBigInt, quotient, remainder); return new BigInteger[] {new BigInteger(quotient), new BigInteger(remainder) }; }
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); }
/** * 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); }
/** * 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 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); }
/** * Constructs a new {@code BigInteger} instance with the given sign and * magnitude. * * @param signum sign of the new {@code BigInteger} (-1 for negative, 0 for * zero, 1 for positive). * @param magnitude magnitude of the new {@code BigInteger} with the most * significant byte first. * @throws NullPointerException if {@code magnitude == null}. * @throws NumberFormatException if the sign is not one of -1, 0, 1 or if * the sign is zero and the magnitude contains non-zero entries. */ public BigInteger(int signum, byte[] magnitude) { if (magnitude == null) { throw new NullPointerException("magnitude == null"); } if (signum < -1 || signum > 1) { throw new NumberFormatException("Invalid signum: " + signum); } if (signum == 0) { for (byte element : magnitude) { if (element != 0) { throw new NumberFormatException("signum-magnitude mismatch"); } } } BigInt bigInt = new BigInt(); bigInt.putBigEndian(magnitude, signum < 0); setBigInt(bigInt); }
/** * Returns a {@code BigInteger} whose value is {@code this % divisor}. * Regarding signs this methods has the same behavior as the % operator on * ints: the sign of the remainder is the same as the sign of this. * * @param divisor value by which {@code this} is divided. * @throws NullPointerException if {@code divisor == null}. * @throws ArithmeticException if {@code divisor == 0}. */ public BigInteger remainder(BigInteger divisor) { BigInt remainder = new BigInt(); BigInt.division(getBigInt(), divisor.getBigInt(), null, remainder); return new BigInteger(remainder); }
/** * 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; } }
smallValue = mantissa << (-scale); } else { BigInt bi = new BigInt(); bi.putLongInt(mantissa); bi.shift(-scale);
BigInt prime = new BigInt(); prime.putULongInt(candidate, false); setBigInt(prime);
BigInt probPrime = new BigInt();
private static BigInt newBigInt() { BigInt bi = new BigInt(); bi.bignum = NativeBN.BN_new(); return bi; }
BigInt copy() { BigInt bi = new BigInt(); bi.putCopy(this); return bi; }
/** * 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); }
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); }