Skip to content

Commit cb2ec30

Browse files
committed
improve PollardRhoBrentMontgomery32, comment on 64-bit versions
1 parent 1fc2f96 commit cb2ec30

5 files changed

+6
-8
lines changed

src/main/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoBrentMontgomery32.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ public int findSingleFactor(int nOriginal) {
104104
final int iMax = Math.min(m, r-k);
105105
for (int i=iMax; i>0; i--) {
106106
y = montMul32(y, y+1, n, minusNInvModR);
107-
final int diff = x<y ? y-x : x-y;
108-
q = montMul32(diff, q, n, minusNInvModR);
107+
q = montMul32(y-x, q, n, minusNInvModR);
109108
}
110109
G = gcd.gcd(q, n);
111110
// if q==0 then G==n -> the loop will be left and restarted with new y
@@ -118,8 +117,7 @@ public int findSingleFactor(int nOriginal) {
118117
if (G==n) {
119118
do {
120119
ys = montMul32(ys, ys+1, n, minusNInvModR);
121-
final int diff = x<ys ? ys-x : x-ys;
122-
G = gcd.gcd(diff, n);
120+
G = gcd.gcd(ys-x, n);
123121
} while (G==1);
124122
if (DEBUG) LOG.debug("G = " + G);
125123
}

src/main/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoBrentMontgomery64.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public long findSingleFactor(long nOriginal) {
104104
final int iMax = Math.min(m, r-k);
105105
for (int i=iMax; i>0; i--) {
106106
y = montMul64(y, y+1, n, minusNInvModR);
107-
final long diff = x<y ? y-x : x-y;
107+
final long diff = x<y ? y-x : x-y; // XXX would be nice if we could get rid of this like in PollardRhoBrentMontgomery32
108108
q = montMul64(diff, q, n, minusNInvModR);
109109
}
110110
G = gcd.gcd(q, n);

src/main/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoBrentMontgomery64MH.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public long findSingleFactor(long nOriginal) {
108108
final int iMax = Math.min(m, r-k);
109109
for (int i=iMax; i>0; i--) {
110110
y = montMul64(y, y+1, n, minusNInvModR);
111-
final long diff = x<y ? y-x : x-y;
111+
final long diff = x<y ? y-x : x-y; // XXX would be nice if we could get rid of this like in PollardRhoBrentMontgomery32
112112
q = montMul64(diff, q, n, minusNInvModR);
113113
}
114114
G = gcd.gcd(q, n);

src/main/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoBrentMontgomery64MHInlined.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public long findSingleFactor(long nOriginal) {
108108
final int iMax = Math.min(m, r-k);
109109
for (int i=iMax; i>0; i--) {
110110
y = montMul64(y, y+1, n, minusNInvModR);
111-
final long diff = x<y ? y-x : x-y;
111+
final long diff = x<y ? y-x : x-y; // XXX would be nice if we could get rid of this like in PollardRhoBrentMontgomery32
112112
q = montMul64(diff, q, n, minusNInvModR);
113113
}
114114
G = gcd.gcd(q, n);

src/main/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoBrentMontgomeryR64Mul63.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public long findSingleFactor(long nOriginal) {
102102
final int iMax = Math.min(m, r-k);
103103
for (int i=iMax; i>0; i--) {
104104
y = montMul63(y, y+1, n, minusNInvModR);
105-
final long diff = x<y ? y-x : x-y;
105+
final long diff = x<y ? y-x : x-y; // XXX would be nice if we could get rid of this like in PollardRhoBrentMontgomery32
106106
q = montMul63(diff, q, n, minusNInvModR);
107107
}
108108
G = gcd.gcd(q, n);

0 commit comments

Comments
 (0)