java.math.BigInteger.getBigInt()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(212)

本文整理了Java中java.math.BigInteger.getBigInt()方法的一些代码示例,展示了BigInteger.getBigInt()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.getBigInt()方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:getBigInt

BigInteger.getBigInt介绍

[英]Returns the internal native representation of this big integer, computing it if necessary.
[中]返回此大整数的内部本机表示形式,必要时进行计算。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * 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());
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a {@code BigInteger} whose value is greatest common divisor
 * of {@code this} and {@code value}. If {@code this == 0} and {@code
 * value == 0} then zero is returned, otherwise the result is positive.
 *
 * @param value value with which the greatest common divisor is computed.
 * @throws NullPointerException if {@code value == null}.
 */
public BigInteger gcd(BigInteger value) {
  return new BigInteger(BigInt.gcd(getBigInt(), value.getBigInt()));
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a {@code BigInteger} whose value is {@code this * value}.
 *
 * @throws NullPointerException if {@code value == null}.
 */
public BigInteger multiply(BigInteger value) {
  return new BigInteger(BigInt.product(getBigInt(), value.getBigInt()));
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the sign of this {@code BigInteger}.
 *
 * @return {@code -1} if {@code this < 0}, {@code 0} if {@code this == 0},
 *     {@code 1} if {@code this > 0}.
 */
public int signum() {
  if (javaIsValid) {
    return sign;
  }
  return getBigInt().sign();
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a {@code BigInteger} whose value is {@code pow(this, exp)}.
 *
 * @throws ArithmeticException if {@code exp < 0}.
 */
public BigInteger pow(int exp) {
  if (exp < 0) {
    throw new ArithmeticException("exp < 0: " + exp);
  }
  return new BigInteger(BigInt.exp(getBigInt(), exp));
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a {@code BigInteger} whose value is {@code this - value}.
 */
public BigInteger subtract(BigInteger value) {
  BigInt lhs = getBigInt();
  BigInt rhs = value.getBigInt();
  if (rhs.sign() == 0) {
    return this;
  }
  return new BigInteger(BigInt.subtraction(lhs, rhs));
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a string representation of this {@code BigInteger} in decimal
 * form.
 */
@Override
public String toString() {
  return getBigInt().decString();
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a {@code BigInteger} whose value is {@code 1/this mod m}. The
 * modulus {@code m} must be positive. The result is guaranteed to be in the
 * interval {@code [0, m)} (0 inclusive, m exclusive). If {@code this} is
 * not relatively prime to m, then an exception is thrown.
 *
 * @param m the modulus.
 * @throws NullPointerException if {@code m == null}
 * @throws ArithmeticException if {@code m < 0 or} if {@code this} is not
 *     relatively prime to {@code m}
 */
public BigInteger modInverse(BigInteger m) {
  if (m.signum() <= 0) {
    throw new ArithmeticException("modulus not positive");
  }
  return new BigInteger(BigInt.modInverse(getBigInt(), m.getBigInt()));
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a {@code BigInteger} whose value is {@code this mod m}. The
 * modulus {@code m} must be positive. The result is guaranteed to be in the
 * interval {@code [0, m)} (0 inclusive, m exclusive). The behavior of this
 * function is not equivalent to the behavior of the % operator defined for
 * the built-in {@code int}'s.
 *
 * @param m the modulus.
 * @return {@code this mod m}.
 * @throws NullPointerException if {@code m == null}.
 * @throws ArithmeticException if {@code m < 0}.
 */
public BigInteger mod(BigInteger m) {
  if (m.signum() <= 0) {
    throw new ArithmeticException("m.signum() <= 0");
  }
  return new BigInteger(BigInt.modulus(getBigInt(), m.getBigInt()));
}

代码示例来源:origin: robovm/robovm

/**
 * 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);
}

代码示例来源:origin: robovm/robovm

/**
 * 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);
}

代码示例来源:origin: robovm/robovm

/**
 * Tests whether this {@code BigInteger} is probably prime. If {@code true}
 * is returned, then this is prime with a probability greater than
 * {@code 1 - 1/2<sup>certainty</sup>)}. If {@code false} is returned, then this
 * is definitely composite. If the argument {@code certainty} <= 0, then
 * this method returns true.
 *
 * @param certainty tolerated primality uncertainty.
 * @return {@code true}, if {@code this} is probably prime, {@code false}
 *     otherwise.
 */
public boolean isProbablePrime(int certainty) {
  if (certainty <= 0) {
    return true;
  }
  return getBigInt().isPrime(certainty);
}

代码示例来源:origin: robovm/robovm

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);
  }
}

代码示例来源:origin: robovm/robovm

/**
 * 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));
}

代码示例来源:origin: robovm/robovm

/**
   * 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();
  }
}

代码示例来源:origin: robovm/robovm

/**
 * 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);
}

代码示例来源:origin: robovm/robovm

/**
 * 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) };
}

代码示例来源:origin: robovm/robovm

/**
 * 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);
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a {@code BigInteger} whose value is the {@code -this}.
 */
public BigInteger negate() {
  BigInt bigInt = getBigInt();
  int sign = bigInt.sign();
  if (sign == 0) {
    return this;
  }
  BigInt a = bigInt.copy();
  a.setSign(-sign);
  return new BigInteger(a);
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a string containing a string representation of this {@code
 * BigInteger} with base radix. If {@code radix < Character.MIN_RADIX} or
 * {@code radix > Character.MAX_RADIX} then a decimal representation is
 * returned. The characters of the string representation are generated with
 * method {@code Character.forDigit}.
 *
 * @param radix base to be used for the string representation.
 */
public String toString(int radix) {
  if (radix == 10) {
    return getBigInt().decString();
  } else {
    prepareJavaRepresentation();
    return Conversion.bigInteger2String(this, radix);
  }
}

相关文章