< prev index next >

src/java.base/share/classes/java/math/MutableBigInteger.java

Print this page




 755 
 756         // Add remainder of the longer number
 757         while(x > 0) {
 758             x--;
 759             if (carry == 0 && result == value && rstart == (x + offset))
 760                 return;
 761             sum = (value[x+offset] & LONG_MASK) + carry;
 762             result[rstart--] = (int)sum;
 763             carry = sum >>> 32;
 764         }
 765         while(y > 0) {
 766             y--;
 767             sum = (addend.value[y+addend.offset] & LONG_MASK) + carry;
 768             result[rstart--] = (int)sum;
 769             carry = sum >>> 32;
 770         }
 771 
 772         if (carry > 0) { // Result must grow in length
 773             resultLen++;
 774             if (result.length < resultLen) {
 775                 int temp[] = new int[resultLen];
 776                 // Result one word longer from carry-out; copy low-order
 777                 // bits into new result.
 778                 System.arraycopy(result, 0, temp, 1, result.length);
 779                 temp[0] = 1;
 780                 result = temp;
 781             } else {
 782                 result[rstart--] = 1;
 783             }
 784         }
 785 
 786         value = result;
 787         intLen = resultLen;
 788         offset = result.length - resultLen;
 789     }
 790 
 791     /**
 792      * Adds the value of {@code addend} shifted {@code n} ints to the left.
 793      * Has the same effect as {@code addend.leftShift(32*ints); add(addend);}
 794      * but doesn't change the value of {@code addend}.
 795      */


 821         while (x > 0) {
 822             x--;
 823             if (carry == 0 && result == value && rstart == (x + offset)) {
 824                 return;
 825             }
 826             sum = (value[x+offset] & LONG_MASK) + carry;
 827             result[rstart--] = (int)sum;
 828             carry = sum >>> 32;
 829         }
 830         while (y > 0) {
 831             y--;
 832             int bval = y+addend.offset < addend.value.length ? addend.value[y+addend.offset] : 0;
 833             sum = (bval & LONG_MASK) + carry;
 834             result[rstart--] = (int)sum;
 835             carry = sum >>> 32;
 836         }
 837 
 838         if (carry > 0) { // Result must grow in length
 839             resultLen++;
 840             if (result.length < resultLen) {
 841                 int temp[] = new int[resultLen];
 842                 // Result one word longer from carry-out; copy low-order
 843                 // bits into new result.
 844                 System.arraycopy(result, 0, temp, 1, result.length);
 845                 temp[0] = 1;
 846                 result = temp;
 847             } else {
 848                 result[rstart--] = 1;
 849             }
 850         }
 851 
 852         value = result;
 853         intLen = resultLen;
 854         offset = result.length - resultLen;
 855     }
 856 
 857     /**
 858      * Like {@link #addShifted(MutableBigInteger, int)} but {@code this.intLen} must
 859      * not be greater than {@code n}. In other words, concatenates {@code this}
 860      * and {@code addend}.
 861      */




 755 
 756         // Add remainder of the longer number
 757         while(x > 0) {
 758             x--;
 759             if (carry == 0 && result == value && rstart == (x + offset))
 760                 return;
 761             sum = (value[x+offset] & LONG_MASK) + carry;
 762             result[rstart--] = (int)sum;
 763             carry = sum >>> 32;
 764         }
 765         while(y > 0) {
 766             y--;
 767             sum = (addend.value[y+addend.offset] & LONG_MASK) + carry;
 768             result[rstart--] = (int)sum;
 769             carry = sum >>> 32;
 770         }
 771 
 772         if (carry > 0) { // Result must grow in length
 773             resultLen++;
 774             if (result.length < resultLen) {
 775                 int[] temp = new int[resultLen];
 776                 // Result one word longer from carry-out; copy low-order
 777                 // bits into new result.
 778                 System.arraycopy(result, 0, temp, 1, result.length);
 779                 temp[0] = 1;
 780                 result = temp;
 781             } else {
 782                 result[rstart--] = 1;
 783             }
 784         }
 785 
 786         value = result;
 787         intLen = resultLen;
 788         offset = result.length - resultLen;
 789     }
 790 
 791     /**
 792      * Adds the value of {@code addend} shifted {@code n} ints to the left.
 793      * Has the same effect as {@code addend.leftShift(32*ints); add(addend);}
 794      * but doesn't change the value of {@code addend}.
 795      */


 821         while (x > 0) {
 822             x--;
 823             if (carry == 0 && result == value && rstart == (x + offset)) {
 824                 return;
 825             }
 826             sum = (value[x+offset] & LONG_MASK) + carry;
 827             result[rstart--] = (int)sum;
 828             carry = sum >>> 32;
 829         }
 830         while (y > 0) {
 831             y--;
 832             int bval = y+addend.offset < addend.value.length ? addend.value[y+addend.offset] : 0;
 833             sum = (bval & LONG_MASK) + carry;
 834             result[rstart--] = (int)sum;
 835             carry = sum >>> 32;
 836         }
 837 
 838         if (carry > 0) { // Result must grow in length
 839             resultLen++;
 840             if (result.length < resultLen) {
 841                 int[] temp = new int[resultLen];
 842                 // Result one word longer from carry-out; copy low-order
 843                 // bits into new result.
 844                 System.arraycopy(result, 0, temp, 1, result.length);
 845                 temp[0] = 1;
 846                 result = temp;
 847             } else {
 848                 result[rstart--] = 1;
 849             }
 850         }
 851 
 852         value = result;
 853         intLen = resultLen;
 854         offset = result.length - resultLen;
 855     }
 856 
 857     /**
 858      * Like {@link #addShifted(MutableBigInteger, int)} but {@code this.intLen} must
 859      * not be greater than {@code n}. In other words, concatenates {@code this}
 860      * and {@code addend}.
 861      */


< prev index next >