Java 8 RFR 8020641: Clean up some code style in recent BigInteger contributions

Joe Darcy joe.darcy at oracle.com
Tue Jul 16 23:14:19 UTC 2013


On 07/16/2013 02:32 PM, Brian Burkhalter wrote:
> Reviewers:
>
> Issue	http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8020641 (will be public soon)
> Webrev	http://cr.openjdk.java.net/~bpb/8020641/
>
> Note that this patch will need to be integrated after the one for 8014319 which is pending approval [1].
>
> Thanks,
>
> Brian
>
> [1] http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-July/018922.html

Hi Brian,

I've looked over all the code in BigInteger for general consistency of 
braces, spacing, etc.

Besides the changes you're made, here are additional updates to BigInteger:

  373         // Skip leading zeros and compute number of digits in 
magnitude
  374         while (cursor < len &&
  375                Character.digit(val.charAt(cursor), radix) == 0)
  376             cursor++;

Given the nearby code, I think line 376 should be surrounded by {}.

In the following locations, I recommend whitespace around "<", ">=", 
"<", and "==", respectively.

635             for (int i=0; i<magLen; i++)

892         for (int i=k.bitLength()-2; i>=0; i--) {

  948         for (int i=0; i<iterations; i++) {

  957             while(!((j==0 && z.equals(ONE)) || 
z.equals(thisMinusOne))) {
  958                 if (j>0 && z.equals(ONE) || ++j==a)

1484         for (int j=ystart, k=ystart+1+xstart; j>=0; j--, k--) {

1494             for (int j=ystart, k=ystart+1+i; j>=0; j--, k--) {

1707         for (int i=len-1; i>=0; i--) {

1840         for (int j=0, i=0; j<len; j++) {

1849         for (int i=len, offset=1; i>0; i--, offset+=2) {

2153                 if ((workingExponent & 1)==1) {

2167             if (signum<0 && (exponent&1)==1) {

2249         for (int i=0, c=a[i], m=i+len-1; i<m; i++) {

2516         for (int i=1; i<tblmask; i++) {

2650         for (int i=0; i<len; i++) {

2942         for (int i=0; i<result.length; i++)

2959         for (int i=0; i<result.length; i++)

2976         for (int i=0; i<result.length; i++)

2992         for (int i=0; i<result.length; i++)

3010         for (int i=0; i<result.length; i++)

3029         if (n<0)

3044         if (n<0)

3050         for (int i=0; i<result.length; i++)

3068         if (n<0)

3074         for (int i=0; i<result.length; i++)

3092         if (n<0)

3098         for (int i=0; i<result.length; i++)

3184             for (int i=0; i<mag.length; i++)

3297         if (highWord==0) {

3365         return (compareTo(val)<0 ? this : val);

3390         for (int i=0; i<mag.length; i++)

3565         for (int i=0; i<63; i++)

3603         for (int i=byteLen-1, bytesCopied=4, nextInt=0, intIndex=0; 
i>=0; i--) {

3655         for (int i=1; i>=0; i--)

3927         for (int i=result.length-1; i>=0; i--) {

3944         for (keep=0; keep<a.length && a[keep]==-1; keep++)

Space before "(" :

1224         if(yIndex==1) {

1262             if(little.length==1) {

Extra empty line

1305
1306

Space needed.

1355         while(littleIndex > 0) {

2089                 if (signum<0 && (exponent&1)==1) {

2635         while(c>0)


The texts below should be in standard block comment format.

1614         /* The algorithm requires two divisions by 2 and one by 3.
1615            All divisions are known to be exact, that is, they do 
not produce
1616            remainders, and all results are positive.  The divisions 
by 2 are
1617            implemented as right shifts which are relatively 
efficient, leaving
1618            only an exact division by 3, which is done by a specialized
1619            linear-time algorithm. */

1914         /* The algorithm requires two divisions by 2 and one by 3.
1915            All divisions are known to be exact, that is, they do 
not produce
1916            remainders, and all results are positive.  The divisions 
by 2 are
1917            implemented as right shifts which are relatively 
efficient, leaving
1918            only a division by 3.
1919            The division by 3 is done by an optimized algorithm for 
this case.
1920         */

Please take an analogous pass over MutableBigInteger.

Thanks,

-Joe



More information about the core-libs-dev mailing list