1 |
/* Prime.java --- Prime number generation utilities |
/* Prime.java --- Prime number generation utilities |
2 |
Copyright (C) 1999 Free Software Foundation, Inc. |
Copyright (C) 1999, 2004 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
55 |
BigInteger p = new BigInteger( (pmax + pmin)/2, new Random() ); |
BigInteger p = new BigInteger( (pmax + pmin)/2, new Random() ); |
56 |
if( p.compareTo( BigInteger.valueOf( 1 ).shiftLeft( pmin ) ) <= 0 ) |
if( p.compareTo( BigInteger.valueOf( 1 ).shiftLeft( pmin ) ) <= 0 ) |
57 |
{ |
{ |
58 |
p.add( BigInteger.valueOf( 1 ).shiftLeft( pmin ).subtract( p ) ); |
p = p.add( BigInteger.valueOf( 1 ).shiftLeft( pmin ).subtract( p ) ); |
59 |
} |
} |
60 |
|
|
61 |
//Step 2 - test for even |
//Step 2 - test for even |
62 |
if( p.mod( BigInteger.valueOf(2) ).compareTo( BigInteger.valueOf( 0 )) == 0) |
if( p.mod( BigInteger.valueOf(2) ).compareTo( BigInteger.valueOf( 0 )) == 0) |
63 |
p.add( BigInteger.valueOf( 1 ) ); |
p = p.add( BigInteger.valueOf( 1 ) ); |
64 |
|
|
65 |
for(;;) |
for(;;) |
66 |
{ |
{ |
76 |
// put step 2 code here so looping code is cleaner |
// put step 2 code here so looping code is cleaner |
77 |
//Step 2 - test for even |
//Step 2 - test for even |
78 |
if( p.mod( BigInteger.valueOf(2) ).compareTo( BigInteger.valueOf( 0 )) == 0) |
if( p.mod( BigInteger.valueOf(2) ).compareTo( BigInteger.valueOf( 0 )) == 0) |
79 |
p.add( BigInteger.valueOf( 1 ) ); |
p = p.add( BigInteger.valueOf( 1 ) ); |
80 |
continue; |
continue; |
81 |
} |
} |
82 |
|
|
122 |
|
|
123 |
//Step 4 - test for even |
//Step 4 - test for even |
124 |
if( p.mod( BigInteger.valueOf(2) ).compareTo( BigInteger.valueOf( 0 )) == 0) |
if( p.mod( BigInteger.valueOf(2) ).compareTo( BigInteger.valueOf( 0 )) == 0) |
125 |
p.add( r ); |
p = p.add( r ); |
126 |
|
|
127 |
for(;;) |
for(;;) |
128 |
{ |
{ |