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

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

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

BigInteger.getFirstNonzeroDigit介绍

暂无

代码示例

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

/** @return sign = 0, magnitude = longer.magnitude | shorter.magnitude */
static BigInteger xorPositive(BigInteger longer, BigInteger shorter) {
  // PRE: longer and shorter are positive;
  // PRE: longer has at least as many digits as shorter
  int resLength = longer.numberLength;
  int[] resDigits = new int[resLength];
  int i = Math.min(longer.getFirstNonzeroDigit(), shorter.getFirstNonzeroDigit());
  for ( ; i < shorter.numberLength; i++) {
    resDigits[i] = longer.digits[i] ^ shorter.digits[i];
  }
  for ( ; i < longer.numberLength; i++ ){
    resDigits[i] = longer.digits[i];
  }
  return new BigInteger(1, resLength, resDigits);
}

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

/** @return sign = 1, magnitude = val.magnitude & that.magnitude*/
static BigInteger andPositive(BigInteger val, BigInteger that) {
  // PRE: both arguments are positive
  int resLength = Math.min(val.numberLength, that.numberLength);
  int i = Math.max(val.getFirstNonzeroDigit(), that.getFirstNonzeroDigit());
  if (i >= resLength) {
    return BigInteger.ZERO;
  }
  int[] resDigits = new int[resLength];
  for ( ; i < resLength; i++) {
    resDigits[i] = val.digits[i] & that.digits[i];
  }
  return new BigInteger(1, resLength, resDigits);
}

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

/** @return sign = 1, magnitude = val.magnitude & ~that.magnitude*/
static BigInteger andNotPositive(BigInteger val, BigInteger that) {
  // PRE: both arguments are positive
  int[] resDigits = new int[val.numberLength];
  int limit = Math.min(val.numberLength, that.numberLength);
  int i;
  for (i = val.getFirstNonzeroDigit(); i < limit; i++) {
    resDigits[i] = val.digits[i] & ~that.digits[i];
  }
  for ( ; i < val.numberLength; i++) {
    resDigits[i] = val.digits[i];
  }
  return new BigInteger(1, val.numberLength, resDigits);
}

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

/** @return sign = 1, magnitude = positive.magnitude & ~(-negative.magnitude)*/
static BigInteger andNotPositiveNegative(BigInteger positive, BigInteger negative) {
  // PRE: positive > 0 && negative < 0
  int iNeg = negative.getFirstNonzeroDigit();
  int iPos = positive.getFirstNonzeroDigit();
  if (iNeg >= positive.numberLength) {
    return positive;
  }
  int resLength = Math.min(positive.numberLength, negative.numberLength);
  int[] resDigits = new int[resLength];
  // Always start from first non zero of positive
  int i = iPos;
  for ( ; i < iNeg; i++) {
    // resDigits[i] = positive.digits[i] & -1 (~0)
    resDigits[i] = positive.digits[i];
  }
  if (i == iNeg) {
    resDigits[i] = positive.digits[i] & (negative.digits[i] - 1);
    i++;
  }
  for ( ; i < resLength; i++) {
    // resDigits[i] = positive.digits[i] & ~(~negative.digits[i]);
    resDigits[i] = positive.digits[i] & negative.digits[i];
  }
  return new BigInteger(1, resLength, resDigits);
}

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

/** @return sign = -1, magnitude = -(-val.magnitude | -that.magnitude) */
static BigInteger orNegative(BigInteger val, BigInteger that){
  // PRE: val and that are negative;
  // PRE: val has at least as many trailing zeros digits as that
  int iThat = that.getFirstNonzeroDigit();
  int iVal = val.getFirstNonzeroDigit();
  int i;
  if (iVal >= that.numberLength) {
    return that;
  }else if (iThat >= val.numberLength) {
    return val;
  }
  int resLength = Math.min(val.numberLength, that.numberLength);
  int[] resDigits = new int[resLength];
  //Looking for the first non-zero digit of the result
  if (iThat == iVal) {
    resDigits[iVal] = -(-val.digits[iVal] | -that.digits[iVal]);
    i = iVal;
  } else {
    for (i = iThat; i < iVal; i++) {
      resDigits[i] = that.digits[i];
    }
    resDigits[i] = that.digits[i] & (val.digits[i] - 1);
  }
  for (i++; i < resLength; i++) {
    resDigits[i] = val.digits[i] & that.digits[i];
  }
  return new BigInteger(-1, resLength, resDigits);
}

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

int iPos = positive.getFirstNonzeroDigit();
int iNeg = negative.getFirstNonzeroDigit();

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

/**
 * Returns the position of the lowest set bit in the two's complement
 * representation of this {@code BigInteger}. If all bits are zero (this==0)
 * then -1 is returned as result.
 *
 * <p><b>Implementation Note:</b> Usage of this method is not recommended as
 * the current implementation is not efficient.
 */
public int getLowestSetBit() {
  prepareJavaRepresentation();
  if (sign == 0) {
    return -1;
  }
  // (sign != 0) implies that exists some non zero digit
  int i = getFirstNonzeroDigit();
  return ((i << 5) + Integer.numberOfTrailingZeros(digits[i]));
}

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

int iLonger = longer.getFirstNonzeroDigit();
int iShorter = shorter.getFirstNonzeroDigit();

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

int iVal = val.getFirstNonzeroDigit();
int iThat = that.getFirstNonzeroDigit();

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

int iVal = val.getFirstNonzeroDigit();
int iThat = that.getFirstNonzeroDigit();
int i = iThat;
int limit;

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

/** @see BigInteger#bitLength() */
static int bitLength(BigInteger val) {
  val.prepareJavaRepresentation();
  if (val.sign == 0) {
    return 0;
  }
  int bLength = (val.numberLength << 5);
  int highDigit = val.digits[val.numberLength - 1];
  if (val.sign < 0) {
    int i = val.getFirstNonzeroDigit();
    // We reduce the problem to the positive case.
    if (i == val.numberLength - 1) {
      highDigit--;
    }
  }
  // Subtracting all sign bits
  bLength -= Integer.numberOfLeadingZeros(highDigit);
  return bLength;
}

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

int iNeg = negative.getFirstNonzeroDigit();
int iPos = positive.getFirstNonzeroDigit();
int i;
int limit;

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

/** @see BigInteger#bitCount() */
static int bitCount(BigInteger val) {
  val.prepareJavaRepresentation();
  int bCount = 0;
  if (val.sign == 0) {
    return 0;
  }
  int i = val.getFirstNonzeroDigit();
  if (val.sign > 0) {
    for ( ; i < val.numberLength; i++) {
      bCount += Integer.bitCount(val.digits[i]);
    }
  } else {// (sign < 0)
    // this digit absorbs the carry
    bCount += Integer.bitCount(-val.digits[i]);
    for (i++; i < val.numberLength; i++) {
      bCount += Integer.bitCount(~val.digits[i]);
    }
    // We take the complement sum:
    bCount = (val.numberLength << 5) - bCount;
  }
  return bCount;
}

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

int digit;
int iNeg = negative.getFirstNonzeroDigit();
int iPos = positive.getFirstNonzeroDigit();

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

} else {
  int firstNonZeroDigit = val.getFirstNonzeroDigit();
  if (intCount > firstNonZeroDigit) {
    resDigits[intCount] ^= bitNumber;

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

int resLength = Math.max(negative.numberLength, positive.numberLength);
int[] resDigits;
int iNeg = negative.getFirstNonzeroDigit();
int iPos = positive.getFirstNonzeroDigit();
int i;
int limit;

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

int iThis = getFirstNonzeroDigit();
int bytesLen = (bitLen >> 3) + 1;

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

n = (1 << (n & 31)); // int with 1 set to the needed position
if (sign < 0) {
  int firstNonZeroDigit = getFirstNonzeroDigit();
  if (intCount < firstNonZeroDigit) {
    return false;

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

if (that.sign > 0) {
  return orDiffSigns(that, val);
} else if (that.getFirstNonzeroDigit() > val.getFirstNonzeroDigit()) {
  return orNegative(that, val);
} else {

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

if (that.sign > 0) {
  return xorDiffSigns(that, val);
} else if (that.getFirstNonzeroDigit() > val.getFirstNonzeroDigit()) {
  return xorNegative(that, val);
} else {

相关文章