130131132133134135136137138139140
BigInteger midpoint; 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);
138139140141142143144145146147148
else { 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 new Pair(midpoint, remainder); }
8485868788899091929394
9293949596979899100101102
189190191192193194195196197198199
197198199200201202203204205206207
else { 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); }
191192193194195196197198199200201
199200201202203204205206207208209
220221222223224225226227228229230
for (int i = h.bitLength() - 2; i > 0; i--) { R = R.twice(); if (h.testBit(i) && !e.testBit(i)) { //System.out.print("+"); R = R.add(this); } else if (!h.testBit(i) && e.testBit(i))
225226227228229230231232233234235
if (h.testBit(i) && !e.testBit(i)) { //System.out.print("+"); R = R.add(this); } else if (!h.testBit(i) && e.testBit(i)) { //System.out.print("-"); R = R.subtract(this); } // else