Skip to content

Commit 088d01f

Browse files
committed
cleanup
1 parent 377a131 commit 088d01f

1 file changed

Lines changed: 1 addition & 56 deletions

File tree

src/main/java/de/tilman_neumann/jml/base/UnsignedBigInt.java

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -161,57 +161,6 @@ public int intLength() {
161161
public int bitLength() {
162162
return intLength==0 ? 0 : (intLength<<5) - Integer.numberOfLeadingZeros(intArray[intLength-1]);
163163
}
164-
165-
/**
166-
* Divide this by the given <code>divisor</code>, store the quotient in <code>quotient</code> and return the remainder.
167-
* The caller must make sure that {@link #set(BigInteger)} has been invoked before.
168-
*
169-
* @param divisor
170-
* @param quotient output
171-
* @return remainder
172-
*/
173-
@Deprecated // v2 is significantly faster
174-
public int divideAndRemainder_v1(final int divisor, UnsignedBigInt quotient) {
175-
// A special treatment of intLength==1 is asymptotically bad
176-
long rem = 0;
177-
long divisor_long = divisor & 0xFFFFFFFFL;
178-
long currentDividend, quot;
179-
180-
// loop that determines intLength by the way
181-
quotient.intLength = 0; // if this < divisor
182-
int i = intLength-1;
183-
for (; i >= 0; i--) {
184-
currentDividend = (rem << 32) | (intArray[i] & 0xFFFFFFFFL);
185-
quot = currentDividend / divisor_long;
186-
// rem = currentDividend % divisor_long is faster than currentDividend - quot*divisor_long
187-
rem = currentDividend % divisor_long;
188-
if (DEBUG) {
189-
Ensure.ensureGreaterEquals(currentDividend, 0);
190-
Ensure.ensureSmallerEquals(quot, 0xFFFFFFFFL);
191-
}
192-
quotient.intArray[i] = (int) (quot & 0xFFFFFFFFL);
193-
if (quot>0) {
194-
quotient.intLength = i+1;
195-
i--; // loop decrement will not be carried out after break
196-
break; // go to loop without intLength-test
197-
}
198-
}
199-
200-
// loop without intLength-test
201-
for (; i >= 0; i--) {
202-
currentDividend = (rem << 32) | (intArray[i] & 0xFFFFFFFFL);
203-
quot = currentDividend / divisor_long;
204-
// rem = currentDividend % divisor_long is faster than currentDividend - quot*divisor_long
205-
rem = currentDividend % divisor_long;
206-
if (DEBUG) {
207-
Ensure.ensureGreaterEquals(currentDividend, 0);
208-
Ensure.ensureSmallerEquals(quot, 0xFFFFFFFFL);
209-
}
210-
quotient.intArray[i] = (int) (quot & 0xFFFFFFFFL);
211-
}
212-
213-
return (int) rem;
214-
}
215164

216165
/**
217166
* Divide this by the given <code>divisor</code>, store the quotient in <code>quotient</code> and return the remainder.
@@ -221,7 +170,7 @@ public int divideAndRemainder_v1(final int divisor, UnsignedBigInt quotient) {
221170
* @param quotient output
222171
* @return remainder
223172
*/
224-
public int divideAndRemainder/*_v2*/(final int divisor, UnsignedBigInt quotient) {
173+
public int divideAndRemainder(final int divisor, UnsignedBigInt quotient) {
225174
// A special treatment of intLength==1 is asymptotically bad
226175

227176
long divisor_long = divisor & 0xFFFFFFFFL;
@@ -255,10 +204,6 @@ public int divideAndRemainder_v1(final int divisor, UnsignedBigInt quotient) {
255204
* Compute the remainder of this modulo divisor.
256205
* The caller must make sure that {@link #set(BigInteger)} has been invoked before.
257206
*
258-
* This simple implementation seems to be amazingly fast, like 100 times faster than BigInteger.mod(d),
259-
* where BigInteger d = BigInteger.valueOf(divisor) has been created before the performance test loop.
260-
* Here, Barrett reduction has no chance to shine...
261-
*
262207
* @param divisor
263208
* @return remainder
264209
*/

0 commit comments

Comments
 (0)