本文整理了Java中java.math.BigInteger.compareMagnitude()
方法的一些代码示例,展示了BigInteger.compareMagnitude()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.compareMagnitude()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:compareMagnitude
[英]Compares the magnitude array of this BigInteger with the specified BigInteger's. This is the version of compareTo ignoring sign.
[中]将此BigInteger的幅值数组与指定的BigInteger进行比较。这是compareTo忽略符号的版本。
代码示例来源:origin: stackoverflow.com
public int compareTo(BigInteger val) {
if (signum == val.signum) {
switch (signum) {
case 1:
return compareMagnitude(val);
case -1:
return val.compareMagnitude(this);
default:
return 0;
}
}
return signum > val.signum ? 1 : -1;
}
代码示例来源:origin: org.apidesign.bck2brwsr/emul
/**
* Compares this BigInteger with the specified BigInteger. This
* method is provided in preference to individual methods for each
* of the six boolean comparison operators ({@literal <}, ==,
* {@literal >}, {@literal >=}, !=, {@literal <=}). The suggested
* idiom for performing these comparisons is: {@code
* (x.compareTo(y)} <<i>op</i>> {@code 0)}, where
* <<i>op</i>> is one of the six comparison operators.
*
* @param val BigInteger to which this BigInteger is to be compared.
* @return -1, 0 or 1 as this BigInteger is numerically less than, equal
* to, or greater than {@code val}.
*/
public int compareTo(BigInteger val) {
if (signum == val.signum) {
switch (signum) {
case 1:
return compareMagnitude(val);
case -1:
return val.compareMagnitude(this);
default:
return 0;
}
}
return signum > val.signum ? 1 : -1;
}
代码示例来源:origin: jtulach/bck2brwsr
/**
* Compares this BigInteger with the specified BigInteger. This
* method is provided in preference to individual methods for each
* of the six boolean comparison operators ({@literal <}, ==,
* {@literal >}, {@literal >=}, !=, {@literal <=}). The suggested
* idiom for performing these comparisons is: {@code
* (x.compareTo(y)} <<i>op</i>> {@code 0)}, where
* <<i>op</i>> is one of the six comparison operators.
*
* @param val BigInteger to which this BigInteger is to be compared.
* @return -1, 0 or 1 as this BigInteger is numerically less than, equal
* to, or greater than {@code val}.
*/
public int compareTo(BigInteger val) {
if (signum == val.signum) {
switch (signum) {
case 1:
return compareMagnitude(val);
case -1:
return val.compareMagnitude(this);
default:
return 0;
}
}
return signum > val.signum ? 1 : -1;
}
代码示例来源:origin: org.apidesign.bck2brwsr/emul
/**
* Returns the length of the absolute value of a BigInteger, in
* decimal digits.
*
* @param b the BigInteger
* @return the length of the unscaled value, in decimal digits
*/
private static int bigDigitLength(BigInteger b) {
/*
* Same idea as the long version, but we need a better
* approximation of log10(2). Using 646456993/2^31
* is accurate up to max possible reported bitLength.
*/
if (b.signum == 0)
return 1;
int r = (int)((((long)b.bitLength() + 1) * 646456993) >>> 31);
return b.compareMagnitude(bigTenToThe(r)) < 0? r : r+1;
}
代码示例来源:origin: jtulach/bck2brwsr
/**
* Returns the length of the absolute value of a BigInteger, in
* decimal digits.
*
* @param b the BigInteger
* @return the length of the unscaled value, in decimal digits
*/
private static int bigDigitLength(BigInteger b) {
/*
* Same idea as the long version, but we need a better
* approximation of log10(2). Using 646456993/2^31
* is accurate up to max possible reported bitLength.
*/
if (b.signum == 0)
return 1;
int r = (int)((((long)b.bitLength() + 1) * 646456993) >>> 31);
return b.compareMagnitude(bigTenToThe(r)) < 0? r : r+1;
}
代码示例来源:origin: org.apidesign.bck2brwsr/emul
/**
* Returns a BigInteger whose value is {@code (this + val)}.
*
* @param val value to be added to this BigInteger.
* @return {@code this + val}
*/
public BigInteger add(BigInteger val) {
if (val.signum == 0)
return this;
if (signum == 0)
return val;
if (val.signum == signum)
return new BigInteger(add(mag, val.mag), signum);
int cmp = compareMagnitude(val);
if (cmp == 0)
return ZERO;
int[] resultMag = (cmp > 0 ? subtract(mag, val.mag)
: subtract(val.mag, mag));
resultMag = trustedStripLeadingZeroInts(resultMag);
return new BigInteger(resultMag, cmp == signum ? 1 : -1);
}
代码示例来源:origin: jtulach/bck2brwsr
/**
* Returns a BigInteger whose value is {@code (this - val)}.
*
* @param val value to be subtracted from this BigInteger.
* @return {@code this - val}
*/
public BigInteger subtract(BigInteger val) {
if (val.signum == 0)
return this;
if (signum == 0)
return val.negate();
if (val.signum != signum)
return new BigInteger(add(mag, val.mag), signum);
int cmp = compareMagnitude(val);
if (cmp == 0)
return ZERO;
int[] resultMag = (cmp > 0 ? subtract(mag, val.mag)
: subtract(val.mag, mag));
resultMag = trustedStripLeadingZeroInts(resultMag);
return new BigInteger(resultMag, cmp == signum ? 1 : -1);
}
代码示例来源:origin: org.apidesign.bck2brwsr/emul
/**
* Returns a BigInteger whose value is {@code (this - val)}.
*
* @param val value to be subtracted from this BigInteger.
* @return {@code this - val}
*/
public BigInteger subtract(BigInteger val) {
if (val.signum == 0)
return this;
if (signum == 0)
return val.negate();
if (val.signum != signum)
return new BigInteger(add(mag, val.mag), signum);
int cmp = compareMagnitude(val);
if (cmp == 0)
return ZERO;
int[] resultMag = (cmp > 0 ? subtract(mag, val.mag)
: subtract(val.mag, mag));
resultMag = trustedStripLeadingZeroInts(resultMag);
return new BigInteger(resultMag, cmp == signum ? 1 : -1);
}
代码示例来源:origin: jtulach/bck2brwsr
/**
* Returns a BigInteger whose value is {@code (this + val)}.
*
* @param val value to be added to this BigInteger.
* @return {@code this + val}
*/
public BigInteger add(BigInteger val) {
if (val.signum == 0)
return this;
if (signum == 0)
return val;
if (val.signum == signum)
return new BigInteger(add(mag, val.mag), signum);
int cmp = compareMagnitude(val);
if (cmp == 0)
return ZERO;
int[] resultMag = (cmp > 0 ? subtract(mag, val.mag)
: subtract(val.mag, mag));
resultMag = trustedStripLeadingZeroInts(resultMag);
return new BigInteger(resultMag, cmp == signum ? 1 : -1);
}
代码示例来源:origin: org.apidesign.bck2brwsr/emul
/**
* Returns a BigInteger whose value is {@code (this}<sup>-1</sup> {@code mod m)}.
*
* @param m the modulus.
* @return {@code this}<sup>-1</sup> {@code mod m}.
* @throws ArithmeticException {@code m} ≤ 0, or this BigInteger
* has no multiplicative inverse mod m (that is, this BigInteger
* is not <i>relatively prime</i> to m).
*/
public BigInteger modInverse(BigInteger m) {
if (m.signum != 1)
throw new ArithmeticException("BigInteger: modulus not positive");
if (m.equals(ONE))
return ZERO;
// Calculate (this mod m)
BigInteger modVal = this;
if (signum < 0 || (this.compareMagnitude(m) >= 0))
modVal = this.mod(m);
if (modVal.equals(ONE))
return ONE;
MutableBigInteger a = new MutableBigInteger(modVal);
MutableBigInteger b = new MutableBigInteger(m);
MutableBigInteger result = a.mutableModInverse(b);
return result.toBigInteger(1);
}
代码示例来源:origin: jtulach/bck2brwsr
ys == INFLATED) {
rb = bigMultiplyPowerTen(-sdiff);
return rb.compareMagnitude(val.intVal);
xs == INFLATED) {
rb = val.bigMultiplyPowerTen(sdiff);
return this.intVal.compareMagnitude(rb);
return 1;
else
return this.intVal.compareMagnitude(val.intVal);
代码示例来源:origin: org.apidesign.bck2brwsr/emul
ys == INFLATED) {
rb = bigMultiplyPowerTen(-sdiff);
return rb.compareMagnitude(val.intVal);
xs == INFLATED) {
rb = val.bigMultiplyPowerTen(sdiff);
return this.intVal.compareMagnitude(rb);
return 1;
else
return this.intVal.compareMagnitude(val.intVal);
代码示例来源:origin: jtulach/bck2brwsr
/**
* Returns a BigInteger whose value is {@code (this}<sup>-1</sup> {@code mod m)}.
*
* @param m the modulus.
* @return {@code this}<sup>-1</sup> {@code mod m}.
* @throws ArithmeticException {@code m} ≤ 0, or this BigInteger
* has no multiplicative inverse mod m (that is, this BigInteger
* is not <i>relatively prime</i> to m).
*/
public BigInteger modInverse(BigInteger m) {
if (m.signum != 1)
throw new ArithmeticException("BigInteger: modulus not positive");
if (m.equals(ONE))
return ZERO;
// Calculate (this mod m)
BigInteger modVal = this;
if (signum < 0 || (this.compareMagnitude(m) >= 0))
modVal = this.mod(m);
if (modVal.equals(ONE))
return ONE;
MutableBigInteger a = new MutableBigInteger(modVal);
MutableBigInteger b = new MutableBigInteger(m);
MutableBigInteger result = a.mutableModInverse(b);
return result.toBigInteger(1);
}
代码示例来源:origin: jtulach/bck2brwsr
this.inflate();
while ( intVal.compareMagnitude(BigInteger.TEN) >= 0 &&
scale > preferredScale) {
if (intVal.testBit(0))
代码示例来源:origin: org.apidesign.bck2brwsr/emul
this.inflate();
while ( intVal.compareMagnitude(BigInteger.TEN) >= 0 &&
scale > preferredScale) {
if (intVal.testBit(0))
内容来源于网络,如有侵权,请联系作者删除!