Package java.math

Examples of java.math.BigInteger.shiftRight()


            BigDecimal numeric = new BigDecimal(new BigInteger(bytes));

            BigInteger nvalue = numeric.toBigInteger();

            long lsb_bi = nvalue.longValue(); // low-order 8 bytes out (first 64bit)
            long msb_bi = nvalue.shiftRight(8 * 8).longValue(); // most sognificant 8 bytes out (last
            // 64bit)
            // String hexbi = Long.toHexString(msb_bi) + Long.toHexString(lsb_bi) ;

            // System.out.println(Long.toHexString(lsb_bi) + " - " + Long.toHexString(lsb));
            // System.out.println(Long.toHexString(msb_bi) + " - " + Long.toHexString(msb));
View Full Code Here


        boolean remainder;
        if (left.compareTo(right) < 0)
        {
            BigInteger sum = left.add(right);
            remainder = sum.testBit(0);
            midpoint = sum.shiftRight(1);
        }
        else
        {
            BigInteger max = TWO.pow(sigbits);
            // wrapping case
View Full Code Here

        {
            BigInteger max = TWO.pow(sigbits);
            // wrapping case
            BigInteger distance = max.add(right).subtract(left);
            remainder = distance.testBit(0);
            midpoint = distance.shiftRight(1).add(left).mod(max);
        }
        return Pair.create(midpoint, remainder);
    }

    public static int compareUnsigned(byte[] bytes1, byte[] bytes2, int offset1, int offset2, int len1, int len2)
View Full Code Here

        boolean remainder;
        if (left.compareTo(right) < 0)
        {
            BigInteger sum = left.add(right);
            remainder = sum.testBit(0);
            midpoint = sum.shiftRight(1);
        }
        else
        {
            BigInteger max = TWO.pow(sigbits);
            // wrapping case
View Full Code Here

        {
            BigInteger max = TWO.pow(sigbits);
            // wrapping case
            BigInteger distance = max.add(right).subtract(left);
            remainder = distance.testBit(0);
            midpoint = distance.shiftRight(1).add(left).mod(max);
        }
        return Pair.create(midpoint, remainder);
    }

    public static int compareUnsigned(byte[] bytes1, byte[] bytes2, int offset1, int offset2, int len1, int len2)
View Full Code Here

            exp -= 1075;
            BigInteger x = BigInteger.valueOf(mantissa);
            if (exp > 0) {
                x = x.shiftLeft(exp);
            } else if (exp < 0) {
                x = x.shiftRight(-exp);
            }
            intDigits = x.toString(base);
        }

        if (d == dfloor) {
View Full Code Here

        {
            BigInteger bi = numberToBeSquareRooted.unscaledValue();
            int biLen = bi.bitLength();
            int biSqrtLen = biLen / 2;                // floors it too

            bi = bi.shiftRight(biSqrtLen);          // bad guess sqrt(d)
            iteration1 = new BigDecimal(bi);                 // x ~ sqrt(d)

            MathContext mm = new MathContext(5, RoundingMode.HALF_DOWN);   // minimal precision
            extraPrecision += 10;                   // make up for it later
View Full Code Here

                   
                    final IntegerValue absoluteIdParam = (IntegerValue)args[0].itemAt(0);
                    BigInteger absoluteId = (BigInteger)absoluteIdParam.toJavaObject(BigInteger.class);
                   
                    final byte resourceType = absoluteId.testBit(0) ? DocumentImpl.BINARY_FILE : DocumentImpl.XML_FILE;
                    absoluteId = absoluteId.shiftRight(1);
                    final int documentId = absoluteId.and(BigInteger.valueOf(0xFFFFFFFF)).intValue();
                    absoluteId = absoluteId.shiftRight(32);
                    final int collectionId = absoluteId.and(BigInteger.valueOf(0xFFFFFFFF)).intValue();
                   
                    doc = context.getBroker().getResourceById(collectionId, resourceType, documentId);
View Full Code Here

                    BigInteger absoluteId = (BigInteger)absoluteIdParam.toJavaObject(BigInteger.class);
                   
                    final byte resourceType = absoluteId.testBit(0) ? DocumentImpl.BINARY_FILE : DocumentImpl.XML_FILE;
                    absoluteId = absoluteId.shiftRight(1);
                    final int documentId = absoluteId.and(BigInteger.valueOf(0xFFFFFFFF)).intValue();
                    absoluteId = absoluteId.shiftRight(32);
                    final int collectionId = absoluteId.and(BigInteger.valueOf(0xFFFFFFFF)).intValue();
                   
                    doc = context.getBroker().getResourceById(collectionId, resourceType, documentId);
                    if(doc instanceof BinaryDocument) {
                        final BinaryDocument bin = (BinaryDocument) doc;
View Full Code Here

      // Estimate the square root with the foremost 62 bits of squarD
      BigInteger bi = squarD.unscaledValue();     // bi and scale are a tandem
      int biLen = bi.bitLength();
      int shift = Math.max(0, biLen - BITS + (biLen%2 == 0 ? 0 : 1));   // even shift..
      bi = bi.shiftRight(shift);                  // ..floors to 62 or 63 bit BigInteger

      double root = Math.sqrt(SafeDoubleParser.doubleValue(bi));
      BigDecimal halfBack = new BigDecimal(BigInteger.ONE.shiftLeft(shift/2));

      int scale = squarD.scale();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.