本文整理了Java中java.math.BigInteger.shiftLeft()
方法的一些代码示例,展示了BigInteger.shiftLeft()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.shiftLeft()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:shiftLeft
[英]Returns a BigInteger whose value is this << n. The result is equivalent to this * pow(2, n) if n >= 0. The shift distance may be negative which means that this is shifted right. The result then corresponds to floor(this / pow(2, -n)).
Implementation Note: Usage of this method on negative values is not recommended as the current implementation is not efficient.
[中]返回一个BigInteger,其值为this<<n。如果n>=0,则结果等于this*pow(2,n)。换档距离可能为负数,这意味着它向右换档。然后,结果对应于地板(该/pow(2,-n))。
实施说明:不建议对负值使用此方法,因为当前的实施效率不高。
代码示例来源:origin: zendesk/maxwell
private BigInteger bytesToBigInteger(byte[] bytes) {
BigInteger res = BigInteger.ZERO;
for (int i = 0; i < bytes.length; i++) {
res = res.add(BigInteger.valueOf(bytes[i] & 0xFF).shiftLeft(i * 8));
}
return res;
}
代码示例来源:origin: org.apache.poi/poi
public ExpandedDouble(long rawBits) {
int biasedExp = (int) (rawBits >> 52);
if (biasedExp == 0) {
// sub-normal numbers
BigInteger frac = BigInteger.valueOf(rawBits).and(BI_FRAC_MASK);
int expAdj = 64 - frac.bitLength();
_significand = frac.shiftLeft(expAdj);
_binaryExponent = (biasedExp & 0x07FF) - 1023 - expAdj;
} else {
_significand = getFrac(rawBits);
_binaryExponent = (biasedExp & 0x07FF) - 1023;
}
}
代码示例来源:origin: io.netty/netty
private static BigInteger ipv6CidrMaskToMask(int cidrMask) {
return BigInteger.ONE.shiftLeft(128 - cidrMask).subtract(BigInteger.ONE).not();
}
代码示例来源:origin: deeplearning4j/nd4j
Bernoulli b = new Bernoulli();
BigInteger fourn = BigInteger.valueOf(4);
BigInteger fac = BigInteger.valueOf(2);
for (int i = 2;; i++) {
Rational f = b.at(2 * i).abs();
fourn = fourn.shiftLeft(2);
fac = fac.multiply(BigInteger.valueOf(2 * i)).multiply(BigInteger.valueOf(2 * i - 1));
f = f.multiply(fourn).multiply(fourn.subtract(BigInteger.ONE)).divide(fac);
xpowi = multiplyRound(xpowi, xhighprSq);
BigDecimal c = multiplyRound(xpowi, f);
代码示例来源:origin: stackoverflow.com
this(BigInteger.valueOf(numerator), BigInteger.valueOf(denominator));
this(BigInteger.valueOf(numerator), BigInteger.ONE, true);
tmpNumerator = tmpNumerator.multiply(BigInteger.ONE.shiftLeft(exponent));
else
tmpDenominator = tmpDenominator.multiply(BigInteger.ONE.shiftLeft(-exponent));
return new BigFraction(numerator.multiply(f.denominator).add(denominator.multiply(f.numerator)),
denominator.multiply(f.denominator));
return new BigFraction(numerator.add(denominator.multiply(b)),
denominator, true);
throw new IllegalArgumentException("Null argument");
return new BigFraction(numerator.multiply(f.denominator).subtract(denominator.multiply(f.numerator)),
denominator.multiply(f.denominator));
throw new IllegalArgumentException("Null argument");
return new BigFraction(denominator.subtract(numerator), denominator, true);
unscaled = unscaled.shiftLeft(fives - twos); //x * 2^n === x << n
else if (fives < twos)
unscaled = unscaled.multiply(FIVE.pow(twos - fives));
代码示例来源:origin: google/guava
sqrt0 = sqrtApproxWithDoubles(x.shiftRight(shift)).shiftLeft(shift >> 1);
BigInteger sqrt1 = sqrt0.add(x.divide(sqrt0)).shiftRight(1);
if (sqrt0.equals(sqrt1)) {
return sqrt0;
sqrt1 = sqrt0.add(x.divide(sqrt0)).shiftRight(1);
} while (sqrt1.compareTo(sqrt0) < 0);
return sqrt0;
代码示例来源:origin: robovm/robovm
mantissa = mantissa.shiftLeft(k);
exponent -= k;
mantissa = quotAndRem[0].shiftLeft(2).add(
BigInteger.valueOf((compRem * (compRem + 3)) / 2 + 1));
exponent -= 2;
代码示例来源:origin: google/guava
@GwtIncompatible // TODO
public void testSqrtHalfDown() {
for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
BigInteger result = BigIntegerMath.sqrt(x, HALF_DOWN);
BigInteger plusHalfSquared = result.pow(2).add(result).shiftLeft(2).add(ONE);
BigInteger x4 = x.shiftLeft(2);
// sqrt(x) <= result + 0.5, so 4 * x <= (result + 0.5)^2 * 4
// (result + 0.5)^2 * 4 = (result^2 + result)*4 + 1
assertTrue(x4.compareTo(plusHalfSquared) <= 0);
BigInteger minusHalfSquared = result.pow(2).subtract(result).shiftLeft(2).add(ONE);
// sqrt(x) > result - 0.5, so 4 * x > (result - 0.5)^2 * 4
// (result - 0.5)^2 * 4 = (result^2 - result)*4 + 1
assertTrue(result.equals(ZERO) || x4.compareTo(minusHalfSquared) > 0);
}
}
代码示例来源:origin: apache/hive
/**
* Convert this object to {@link BigInteger}. Do not use this method in a
* performance sensitive place.
*
* @return BigInteger to represent this object
*/
public BigInteger toBigIntegerSlow() {
BigInteger bigInt = BigInteger.valueOf(v[3] & SqlMathUtil.LONG_MASK);
bigInt = bigInt.shiftLeft(32);
bigInt = bigInt.add(BigInteger.valueOf(v[2] & SqlMathUtil.LONG_MASK));
bigInt = bigInt.shiftLeft(32);
bigInt = bigInt.add(BigInteger.valueOf(v[1] & SqlMathUtil.LONG_MASK));
bigInt = bigInt.shiftLeft(32);
bigInt = bigInt.add(BigInteger.valueOf(v[0] & SqlMathUtil.LONG_MASK));
return bigInt;
}
代码示例来源:origin: plutext/docx4j
public ExpandedDouble(long rawBits) {
int biasedExp = (int) (rawBits >> 52);
if (biasedExp == 0) {
// sub-normal numbers
BigInteger frac = BigInteger.valueOf(rawBits).and(BI_FRAC_MASK);
int expAdj = 64 - frac.bitLength();
_significand = frac.shiftLeft(expAdj);
_binaryExponent = (biasedExp & 0x07FF) - 1023 - expAdj;
} else {
BigInteger frac = getFrac(rawBits);
_significand = frac;
_binaryExponent = (biasedExp & 0x07FF) - 1023;
}
}
代码示例来源:origin: de.dfki.cos.basys.common/de.dfki.cos.basys.common.jrosbridge
/**
* Convert the given value in unsigned 64-bit representation into its actual
* value. That is, all return values of this function will be positive.
*
* @param value
* The unsigned 64-bit value to convert.
* @return The value of the given 64-bit unsigned value.
*/
public static BigInteger fromUInt64(long value) {
return BigInteger.valueOf(value).and(
BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE));
}
代码示例来源:origin: prestodb/presto
@Test
public void testRescale()
{
assertEquals(rescale(unscaledDecimal(10), 0), unscaledDecimal(10L));
assertEquals(rescale(unscaledDecimal(10), -20), unscaledDecimal(0L));
assertEquals(rescale(unscaledDecimal(15), -1), unscaledDecimal(2));
assertEquals(rescale(unscaledDecimal(1050), -3), unscaledDecimal(1));
assertEquals(rescale(unscaledDecimal(15), 1), unscaledDecimal(150));
assertEquals(rescale(unscaledDecimal(-14), -1), unscaledDecimal(-1));
assertEquals(rescale(unscaledDecimal(-14), 1), unscaledDecimal(-140));
assertEquals(rescale(unscaledDecimal(0), 1), unscaledDecimal(0));
assertEquals(rescale(unscaledDecimal(5), -1), unscaledDecimal(1));
assertEquals(rescale(unscaledDecimal(10), 10), unscaledDecimal(100000000000L));
assertEquals(rescale(unscaledDecimal("150000000000000000000"), -20), unscaledDecimal(2));
assertEquals(rescale(unscaledDecimal("-140000000000000000000"), -20), unscaledDecimal(-1));
assertEquals(rescale(unscaledDecimal("50000000000000000000"), -20), unscaledDecimal(1));
assertEquals(rescale(unscaledDecimal("150500000000000000000"), -18), unscaledDecimal(151));
assertEquals(rescale(unscaledDecimal("-140000000000000000000"), -18), unscaledDecimal(-140));
assertEquals(rescale(unscaledDecimal(BigInteger.ONE.shiftLeft(63)), -18), unscaledDecimal(9L));
assertEquals(rescale(unscaledDecimal(BigInteger.ONE.shiftLeft(62)), -18), unscaledDecimal(5L));
assertEquals(rescale(unscaledDecimal(BigInteger.ONE.shiftLeft(62)), -19), unscaledDecimal(0L));
assertEquals(rescale(MAX_DECIMAL, -1), unscaledDecimal(MAX_DECIMAL_UNSCALED_VALUE.divide(BigInteger.TEN).add(BigInteger.ONE)));
assertEquals(rescale(MIN_DECIMAL, -10), unscaledDecimal(MIN_DECIMAL_UNSCALED_VALUE.divide(BigInteger.valueOf(10000000000L)).subtract(BigInteger.ONE)));
assertEquals(rescale(unscaledDecimal(1), 37), unscaledDecimal("10000000000000000000000000000000000000"));
assertEquals(rescale(unscaledDecimal(-1), 37), unscaledDecimal("-10000000000000000000000000000000000000"));
assertEquals(rescale(unscaledDecimal("10000000000000000000000000000000000000"), -37), unscaledDecimal(1));
}
代码示例来源:origin: prestodb/presto
private static void writeBigInteger(OutputStream output, BigInteger value)
throws IOException
{
// encode the signed number as a positive integer
value = value.shiftLeft(1);
int sign = value.signum();
if (sign < 0) {
value = value.negate();
value = value.subtract(ONE);
}
int length = value.bitLength();
while (true) {
long lowBits = value.longValue() & 0x7fffffffffffffffL;
length -= 63;
// write out the next 63 bits worth of data
for (int i = 0; i < 9; ++i) {
// if this is the last byte, leave the high bit off
if (length <= 0 && (lowBits & ~0x7f) == 0) {
output.write((byte) lowBits);
return;
}
else {
output.write((byte) (0x80 | (lowBits & 0x7f)));
lowBits >>>= 7;
}
}
value = value.shiftRight(63);
}
}
}
代码示例来源:origin: prestodb/presto
sqrt0 = sqrtApproxWithDoubles(x.shiftRight(shift)).shiftLeft(shift >> 1);
BigInteger sqrt1 = sqrt0.add(x.divide(sqrt0)).shiftRight(1);
if (sqrt0.equals(sqrt1)) {
return sqrt0;
sqrt1 = sqrt0.add(x.divide(sqrt0)).shiftRight(1);
} while (sqrt1.compareTo(sqrt0) < 0);
return sqrt0;
代码示例来源:origin: google/guava
@GwtIncompatible // TODO
public void testSqrtHalfUp() {
for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
BigInteger result = BigIntegerMath.sqrt(x, HALF_UP);
BigInteger plusHalfSquared = result.pow(2).add(result).shiftLeft(2).add(ONE);
BigInteger x4 = x.shiftLeft(2);
// sqrt(x) < result + 0.5, so 4 * x < (result + 0.5)^2 * 4
// (result + 0.5)^2 * 4 = (result^2 + result)*4 + 1
assertTrue(x4.compareTo(plusHalfSquared) < 0);
BigInteger minusHalfSquared = result.pow(2).subtract(result).shiftLeft(2).add(ONE);
// sqrt(x) > result - 0.5, so 4 * x > (result - 0.5)^2 * 4
// (result - 0.5)^2 * 4 = (result^2 - result)*4 + 1
assertTrue(result.equals(ZERO) || x4.compareTo(minusHalfSquared) >= 0);
}
}
代码示例来源:origin: stackoverflow.com
/** the constant 2^64 */
private static final BigInteger TWO_64 = BigInteger.ONE.shiftLeft(64);
public String asUnsignedDecimalString(long l) {
BigInteger b = BigInteger.valueOf(l);
if(b.signum() < 0) {
b = b.add(TWO_64);
}
return b.toString();
}
代码示例来源:origin: plutext/docx4j
private static BigInteger getFrac(long rawBits) {
return BigInteger.valueOf(rawBits).and(BI_FRAC_MASK).or(BI_IMPLIED_FRAC_MSB).shiftLeft(11);
}
代码示例来源:origin: rctoris/jrosbridge
/**
* Convert the given value in unsigned 64-bit representation into its actual
* value. That is, all return values of this function will be positive.
*
* @param value
* The unsigned 64-bit value to convert.
* @return The value of the given 64-bit unsigned value.
*/
public static BigInteger fromUInt64(long value) {
return BigInteger.valueOf(value).and(
BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE));
}
代码示例来源:origin: i2p/i2p.i2p
@Override
public synchronized void setField(Field f) {
super.setField(f);
mask = BigInteger.ONE.shiftLeft(f.getb()-1).subtract(BigInteger.ONE);
}
代码示例来源:origin: google/j2objc
sqrt0 = sqrtApproxWithDoubles(x.shiftRight(shift)).shiftLeft(shift >> 1);
BigInteger sqrt1 = sqrt0.add(x.divide(sqrt0)).shiftRight(1);
if (sqrt0.equals(sqrt1)) {
return sqrt0;
sqrt1 = sqrt0.add(x.divide(sqrt0)).shiftRight(1);
} while (sqrt1.compareTo(sqrt0) < 0);
return sqrt0;
内容来源于网络,如有侵权,请联系作者删除!