void add ( MutableBigInteger addend ) { int x = intLen ; int y = addend . intLen ; int resultLen = ( intLen > addend . intLen ? intLen : addend . intLen ) ; int [ ] result = ( value . length < resultLen ? new int [ resultLen ] : value ) ; int rstart = result . length - 1 ; long sum ; long carry = 0 ; // Add common parts of both numbers while ( x > 0 && y > 0 ) { x -- ; y -- ; sum = ( value [ x + offset ] & LONG_MASK ) + ( addend . value [ y + addend . offset ] & LONG_MASK ) + carry ; result [ rstart -- ] = ( int ) sum ; carry = sum >>> 32 ; } // Add remainder of the longer number while ( x > 0 ) { x -- ; if ( carry == 0 && result == value && rstart == ( x + offset ) ) return ; sum = ( value [ x + offset ] & LONG_MASK ) + carry ; result [ rstart -- ] = ( int ) sum ; carry = sum >>> 32 ; } while ( y > 0 ) { y -- ; sum = ( addend . value [ y + addend . offset ] & LONG_MASK ) + carry ; result [ rstart -- ] = ( int ) sum ; carry = sum >>> 32 ; } if ( carry > 0 ) { // Result must grow in length resultLen ++ ; if ( result . length < resultLen ) { int temp [ ] = new int [ resultLen ] ; // Result one word longer from carry-out; copy low-order // bits into new result. System . arraycopy ( result , 0 , temp , 1 , result . length ) ; temp [ 0 ] = 1 ; result = temp ; } else { result [ rstart -- ] = 1 ; } } value = result ; intLen = resultLen ; offset = result . length - resultLen ; }
Adds the contents of two MutableBigInteger objects . The result is placed within this MutableBigInteger . The contents of the addend are not changed .