Skip to content

Commit

Permalink
Syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Sep 14, 2023
1 parent 36cdbcb commit 2746b59
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/libj/math/BigIntMultiplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ private static void javaKaratsuba(final int[] x, final int xoff, final int[] y,
final Thread t1 = new Thread() {
@Override
public void run() {
// System.err.print(".");
// System.err.print('.');
javaKaratsuba(tmp, x2offl_b2, tmp, y2offl_b1, tmp, tmpoff, tmplen, 0, r, parallelThreshold * 2, parallelThresholdZ * 2);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/libj/math/BigIntValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ private static int parse(final char[] s, int fromIndex, final int toIndex) {
* @return The parsed {@code int}.
* @complexity O(n)
*/
private static int parse(final String s, int fromIndex, final int toIndex) {
private static int parse(final CharSequence s, int fromIndex, final int toIndex) {
int v = s.charAt(fromIndex) - '0';
while (++fromIndex < toIndex)
v = v * 10 + s.charAt(fromIndex) - '0';
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/libj/math/FloatingDecimal.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ protected int[][] initialValue() {

/* If insignificant==(1L << ixd) i = insignificantDigitsNumber[idx] is the
* same as: int i; for ( i = 0; insignificant >= 10L; i++ ) insignificant /= 10L; */
private static int[] insignificantDigitsNumber = {
private static final int[] insignificantDigitsNumber = {
0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19
};

Expand Down
46 changes: 23 additions & 23 deletions src/test/java/org/libj/math/BigIntBasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.libj.test.TestAide;

public class BigIntBasicTest {
private static Random rnd = new Random();
private static final Random random = new Random();

@Test
public void testAddInt() {
Expand Down Expand Up @@ -118,12 +118,12 @@ public void addTest() {
me = new BigInt("0");
facit = BigInteger.ZERO;
for (int i = 0; i < 1337; ++i) { // [N]
long tmp = rnd.nextLong() & ((1L << 32) - 1);
long tmp = random.nextLong() & ((1L << 32) - 1);
me.add(1, (int)tmp);
final BigInteger x = facit;
facit = facit.add(BigInteger.valueOf(tmp));
assertEquals("For-loop " + i + ": " + me + " " + x + " Added: " + tmp + "\n", facit.toString(), me.toString());
tmp = rnd.nextLong() >>> 1;
tmp = random.nextLong() >>> 1;
me.add(1, tmp);
facit = facit.add(BigInteger.valueOf(tmp));
assertEquals("For-loop2 " + i + ": " + me + " " + facit + " Added: " + tmp + "\n", facit.toString(), me.toString());
Expand Down Expand Up @@ -330,7 +330,7 @@ public void longDivTest() { // Division test using long as parameter.
BigInteger facit = new BigInteger(new String(s));
final BigInt dividend = new BigInt(s);
while (!dividend.isZero()) {
final long d = rnd.nextLong();
final long d = random.nextLong();
if (d == 0)
continue;

Expand All @@ -353,14 +353,14 @@ public void longDivTest() { // Division test using long as parameter.
}

static char[] getRndNumber(final int len) {
final int sign = rnd.nextInt(2);
final int sign = random.nextInt(2);
final char[] num = new char[len + sign];
if (sign > 0)
num[0] = '-';

num[sign] = (char)('1' + rnd.nextInt(9));
num[sign] = (char)('1' + random.nextInt(9));
for (int i = sign + 1; i < len + sign; i++) // [N]
num[i] = (char)('0' + rnd.nextInt(10));
num[i] = (char)('0' + random.nextInt(10));

return num;
}
Expand Down Expand Up @@ -476,8 +476,8 @@ public void testSetClearFlipTestBit() {
facit = facit.flipBit(32);
assertEquals("Flip bit", facit.toString(), b.toString());
for (int i = 0; i < 2048; ++i) { // [N]
char[] s = getRndNumber(1 + rnd.nextInt(100));
int bit = rnd.nextInt(600);
char[] s = getRndNumber(1 + random.nextInt(100));
int bit = random.nextInt(600);

a.assign(s);

Expand All @@ -491,7 +491,7 @@ public void testSetClearFlipTestBit() {
}
}

bit = rnd.nextInt(600);
bit = random.nextInt(600);
facit = facit.setBit(bit);
int[] x = a.val().clone();
while (true) {
Expand All @@ -507,7 +507,7 @@ public void testSetClearFlipTestBit() {
}
}

bit = rnd.nextInt(600);
bit = random.nextInt(600);
facit = facit.clearBit(bit);
x = a.val().clone();
while (true) {
Expand All @@ -523,7 +523,7 @@ public void testSetClearFlipTestBit() {
}
}

bit = rnd.nextInt(600);
bit = random.nextInt(600);
facit = facit.flipBit(bit);
x = a.val().clone();
while (true) {
Expand Down Expand Up @@ -575,8 +575,8 @@ public void testAnd() {
a.and(new BigInt(0L));
assertTrue("And with 0", a.isZero());
for (int i = 0; i < 1024; ++i) { // [N]
char[] s = getRndNumber(1 + rnd.nextInt(64)), t = getRndNumber(1 + rnd.nextInt(64));
final int sh1 = rnd.nextInt(4) * 32, sh2 = rnd.nextInt(4) * 32;
char[] s = getRndNumber(1 + random.nextInt(64)), t = getRndNumber(1 + random.nextInt(64));
final int sh1 = random.nextInt(4) * 32, sh2 = random.nextInt(4) * 32;
final BigInt c = a.clone();
while (true) {
try {
Expand Down Expand Up @@ -640,8 +640,8 @@ public void testOr() {
a.or(new BigInt(0));
assertEquals("-1 or 0 = ", "-1", a.toString());
for (int i = 0; i < 1024; ++i) { // [N]
char[] s = getRndNumber(1 + rnd.nextInt(64)), t = getRndNumber(1 + rnd.nextInt(64));
final int sh1 = rnd.nextInt(4) * 32, sh2 = rnd.nextInt(4) * 32;
char[] s = getRndNumber(1 + random.nextInt(64)), t = getRndNumber(1 + random.nextInt(64));
final int sh1 = random.nextInt(4) * 32, sh2 = random.nextInt(4) * 32;
a.assign(s);
b.assign(t);
a.shiftLeft(sh1);
Expand Down Expand Up @@ -670,8 +670,8 @@ public void testXor() {
a.xor(b);
assertTrue("Double xor is zero", a.isZero());
for (int i = 0; i < 1024; ++i) { // [N]
char[] s = getRndNumber(1 + rnd.nextInt(64)), t = getRndNumber(1 + rnd.nextInt(64));
final int sh1 = rnd.nextInt(4) * 32, sh2 = rnd.nextInt(4) * 32;
char[] s = getRndNumber(1 + random.nextInt(64)), t = getRndNumber(1 + random.nextInt(64));
final int sh1 = random.nextInt(4) * 32, sh2 = random.nextInt(4) * 32;
a.assign(s);
b.assign(t);
a.shiftLeft(sh1);
Expand All @@ -693,8 +693,8 @@ public void testAndNot() {
a.andNot(b);
assertTrue("Self andNot is zero", a.isZero());
for (int i = 0; i < 1024; ++i) { // [N]
char[] s = getRndNumber(1 + rnd.nextInt(64)), t = getRndNumber(1 + rnd.nextInt(64));
final int sh1 = rnd.nextInt(4) * 32, sh2 = rnd.nextInt(4) * 32;
char[] s = getRndNumber(1 + random.nextInt(64)), t = getRndNumber(1 + random.nextInt(64));
final int sh1 = random.nextInt(4) * 32, sh2 = random.nextInt(4) * 32;
a.assign(s);
a.shiftLeft(sh1);
BigInteger facit = new BigInteger(new String(s)).shiftLeft(sh1);
Expand Down Expand Up @@ -725,8 +725,8 @@ public void testNot() {
a.not();
assertTrue("~~0", a.isZero());
for (int i = 0; i < 1024; ++i) { // [N]
final char[] s = getRndNumber(1 + rnd.nextInt(64));
final int sh1 = rnd.nextInt(4) * 32;
final char[] s = getRndNumber(1 + random.nextInt(64));
final int sh1 = random.nextInt(4) * 32;
a.assign(s);
a.shiftLeft(sh1);
a.not();
Expand All @@ -749,7 +749,7 @@ public void testLongAdd() {
@Test
public void testMod() {
for (int i = 0; i < 1024; ++i) { // [N]
char[] s = getRndNumber(1 + rnd.nextInt(64)), t = getRndNumber(1 + rnd.nextInt(64));
char[] s = getRndNumber(1 + random.nextInt(64)), t = getRndNumber(1 + random.nextInt(64));
BigInt a = new BigInt(s), b = new BigInt(t);
BigInteger aa = new BigInteger(new String(s)), bb = new BigInteger(new String(t));
if (bb.compareTo(BigInteger.ZERO) <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/libj/math/DecimalDivisionStudy.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void testCompareLDvsMPN() {
System.err.println(Ansi.apply(Strings.pad(String.valueOf(sum[0]), RIGHT, 12), Color.MAGENTA) + Ansi.apply(Strings.pad(String.valueOf(sum[1]), RIGHT, 12), Color.MAGENTA));
}

private static long[][] time = new long[19][];
private static final long[][] time = new long[19][];

static {
for (int i = 0, i$ = time.length; i < i$; ++i) // [A]
Expand Down
1 change: 0 additions & 1 deletion src/test/java/org/libj/math/DecimalOperationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static org.libj.lang.Strings.Align.*;
import static org.libj.math.Decimal.*;
import static org.libj.math.FixedPoint.*;

import java.io.BufferedReader;
import java.io.File;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/libj/math/NumericCaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class NumericCaseTest extends CaseTest {
protected static final double shouldBeEqualFactor = 0; // 0.1;
protected static final double shouldInflateFactor = 0; // 0.2;

protected static boolean[] shouldScale = new boolean[3];
protected static final boolean[] shouldScale = new boolean[3];
protected static boolean shouldInflate;
protected static boolean shouldBeEqual;

Expand Down
12 changes: 7 additions & 5 deletions src/test/java/org/libj/math/survey/AuditReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ public File getRulesFile() throws IOException {

public void alloc(final String from, final String className) {
for (int i = 0, i$ = results.length; i < i$; ++i) { // [A]
if (results[i].isMatch(from)) {
results[i].alloc(className);
final Result result = results[i];
if (result.isMatch(from)) {
result.alloc(className);
return;
}
}
Expand Down Expand Up @@ -131,9 +132,10 @@ public int minIterations(final int defaultValue) {
public void dump() {
if (results != null) {
for (int i = 0, i$ = results.length; i < i$; ++i) { // [A]
System.err.println(Arrays.toString(results[i].auditClasses));
for (int j = 0, j$ = results[i].resultClassNames.length; j < j$; ++j) { // [A]
System.err.println(" " + results[i].resultClassNames[j] + ": " + results[i].getCounts()[j]);
final Result result = results[i];
System.err.println(Arrays.toString(result.auditClasses));
for (int j = 0, j$ = result.resultClassNames.length; j < j$; ++j) { // [A]
System.err.println(" " + result.resultClassNames[j] + ": " + result.getCounts()[j]);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/org/libj/math/survey/CaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ protected static int progress(int progress, final double i, final double j, fina

final int p = Math.min(100, (int)Math.round(100d * (i * range + j) / (range * range)));
if (p > progress) {
do
System.out.print("╸");
do {
System.out.print('╸');
System.out.flush();
}
while (++progress <= p);
}

Expand Down

0 comments on commit 2746b59

Please sign in to comment.