Skip to content

Commit accfafb

Browse files
author
Max Freedom Pollard
committed
Check only the decimal-character transition points in checkNumDigits
Halt the power-of-ten loop on signed overflow going negative rather than on a maxExp constant, and drop the -1000..1000 sweep: the loop already visits both sides of every transition where the character count changes.
1 parent 6498a90 commit accfafb

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

‎src/test/java/org/apache/datasketches/common/UtilTest.java‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,16 @@ public void checkCharacterPad() {
242242
assertEquals(out,"zzzzzzzzzzzzPad 30, prepend z:");
243243
}
244244

245+
/**
246+
* Check all the transition points where the number of decimal characters change.
247+
*/
245248
@Test
246249
public void checkNumDigits() {
247-
for (long n = -1000; n <= 1000; n++) {
248-
checkN(n);
249-
}
250-
final int maxExp = 18; //1E18 is the largest power of ten that fits in a signed long
251-
long n = 1;
252-
for (int exp = 0; exp <= maxExp; exp++) {
250+
for (long n = 1; n > 0; n *= 10) { //n goes negative on rollover, which halts the loop
253251
checkN(n);
254252
checkN(n - 1);
255253
checkN(-n);
256254
checkN(-n + 1);
257-
if (exp < maxExp) { n *= 10; } //the multiply past 1E18 would overflow
258255
}
259256
checkN(Long.MAX_VALUE);
260257
checkN(Long.MIN_VALUE);

0 commit comments

Comments
 (0)