Skip to content

Commit

Permalink
Apply auto-formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Sep 26, 2023
1 parent 44e4920 commit 5279ae0
Show file tree
Hide file tree
Showing 70 changed files with 4,595 additions and 4,336 deletions.
40 changes: 20 additions & 20 deletions src/main/java/org/libj/math/BigInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ public BigInt(long mag) {
val = alloc(1);
}
else {
int sig = 1; if (mag < 0) { mag = -mag; sig = -1; }
int sig = 1;
if (mag < 0) { mag = -mag; sig = -1; }
final int magh = (int)(mag >>> 32);
val = magh != 0 ? assignInPlace(alloc(3), sig, (int)mag, magh) : assignInPlace(alloc(2), sig, (int)mag);
}
Expand Down Expand Up @@ -1005,8 +1006,8 @@ public long divRem(final int div) {
}

/**
* Divides this {@link BigInt} by the specified <i>unsigned</i> {@code long} divisor, and returns the <i>absolute unsigned
* long</i> remainder.
* Divides this {@link BigInt} by the specified <i>unsigned</i> {@code long} divisor, and returns the <i>absolute unsigned long</i>
* remainder.
*
* <pre>
* rem = this % div
Expand Down Expand Up @@ -1244,8 +1245,8 @@ public int precision() {
}

/**
* Shifts this {@link BigInt} left by the specified number of bits. The shift distance, {@code num}, may be negative, in which
* case this method performs a right shift.
* Shifts this {@link BigInt} left by the specified number of bits. The shift distance, {@code num}, may be negative, in which case
* this method performs a right shift.
*
* <pre>
* this = this &lt;&lt; num
Expand All @@ -1261,8 +1262,8 @@ public BigInt shiftLeft(final int num) {
}

/**
* Shifts this {@link BigInt} right by the specified number of bits. The shift distance, {@code num}, may be negative, in which
* case this method performs a left shift.
* Shifts this {@link BigInt} right by the specified number of bits. The shift distance, {@code num}, may be negative, in which case
* this method performs a left shift.
*
* <pre>
* this = this &gt; &gt; num
Expand Down Expand Up @@ -1500,12 +1501,12 @@ public double doubleValue() {
}

/**
* Returns a byte array containing the two's-complement representation of this {@link BigInt}. The byte array will be in the
* endian order as specified by the {@code littleEndian} argument. The array will contain the minimum number of bytes required to
* represent this {@link BigInt}, including at least one sign bit, which is {@code (ceil((bitLength(val) + 1) / 8))}.
* Returns a byte array containing the two's-complement representation of this {@link BigInt}. The byte array will be in the endian
* order as specified by the {@code littleEndian} argument. The array will contain the minimum number of bytes required to represent
* this {@link BigInt}, including at least one sign bit, which is {@code (ceil((bitLength(val) + 1) / 8))}.
*
* @param littleEndian Whether the produced byte array is to be encoded in <i>little-endian</i> ({@code true}), or
* <i>big-endian</i> ({@code false}).
* @param littleEndian Whether the produced byte array is to be encoded in <i>little-endian</i> ({@code true}), or <i>big-endian</i>
* ({@code false}).
* @return A byte array containing the two's-complement representation of this {@link BigInt}.
*/
public byte[] toByteArray(final boolean littleEndian) {
Expand All @@ -1531,23 +1532,22 @@ public BigDecimal toBigDecimal() {
}

/**
* Compares the absolute values of this {@link BigInt} to the provided {@link BigInt}, and returns one of {@code -1}, {@code 0},
* or {@code 1} whether the absolute value of {@code this} is less than, equal to, or greater than that of the provided
* {@link BigInt}, respectively.
* Compares the absolute values of this {@link BigInt} to the provided {@link BigInt}, and returns one of {@code -1}, {@code 0}, or
* {@code 1} whether the absolute value of {@code this} is less than, equal to, or greater than that of the provided {@link BigInt},
* respectively.
*
* @param o The {@link BigInt} with which to compare.
* @return One of {@code -1}, {@code 0}, or {@code 1} if the absolute value of {@code this} is less than, equal to, or greater
* than that of he provided {@link BigInt}, respectively.
* @return One of {@code -1}, {@code 0}, or {@code 1} if the absolute value of {@code this} is less than, equal to, or greater than
* that of he provided {@link BigInt}, respectively.
* @complexity O(n)
*/
public int compareToAbs(final BigInt o) {
return compareToAbs(val, o.val);
}

/**
* Compares the values of this {@link BigInt} to the provided {@link BigInt}, and returns one of {@code -1}, {@code 0}, or
* {@code 1} whether the value of {@code this} is less than, equal to, or greater than that of the provided {@link BigInt},
* respectively.
* Compares the values of this {@link BigInt} to the provided {@link BigInt}, and returns one of {@code -1}, {@code 0}, or {@code 1}
* whether the value of {@code this} is less than, equal to, or greater than that of the provided {@link BigInt}, respectively.
*
* @param o The {@link BigInt} with which to compare.
* @return One of {@code -1}, {@code 0}, or {@code 1} if the value of {@code this} is less than, equal to, or greater than that of
Expand Down
33 changes: 17 additions & 16 deletions src/main/java/org/libj/math/BigIntAddition.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public static int[] add(final int[] val, final int add) {
* {@code int} requires a larger array.
* @param val The {@linkplain BigInt#val() value-encoded minuend}.
* @param sub The subtrahend.
* @return The result of the subtraction of the specified amount from the provided {@linkplain BigInt#val() value-encoded
* minuend}.
* @return The result of the subtraction of the specified amount from the provided {@linkplain BigInt#val() value-encoded minuend}.
* @complexity O(n)
*/
public static int[] sub(final int[] val, final int sub) {
Expand Down Expand Up @@ -145,8 +144,7 @@ else if ((len = -len) > 1 || (val[1] & LONG_MASK) > (add & LONG_MASK)) {
* @param val The {@linkplain BigInt#val() value-encoded minuend}.
* @param sig The sign of the unsigned {@code int} to subtract.
* @param sub The subtrahend (unsigned).
* @return The result of the subtraction of the specified amount from the provided {@linkplain BigInt#val() value-encoded
* minuend}.
* @return The result of the subtraction of the specified amount from the provided {@linkplain BigInt#val() value-encoded minuend}.
* @complexity O(n)
*/
public static int[] sub(final int[] val, final int sig, final int sub) {
Expand Down Expand Up @@ -226,8 +224,7 @@ protected static int[] addInPlace(final int[] val, final long add) {
* {@code long} requires a larger array.
* @param val The {@linkplain BigInt#val() value-encoded minuend}.
* @param sub The subtrahend.
* @return The result of the subtraction of the specified amount from the provided {@linkplain BigInt#val() value-encoded
* minuend}.
* @return The result of the subtraction of the specified amount from the provided {@linkplain BigInt#val() value-encoded minuend}.
* @complexity O(n)
*/
public static int[] sub(final int[] val, final long sub) {
Expand Down Expand Up @@ -266,7 +263,8 @@ private static int[] add0(final int[] val, final long add) {
if (len == 0)
return assignInPlace(val.length >= 3 ? val : alloc(3), 1, (int)add, (int)addh);

boolean sig = true; if (len < 0) { len = -len; sig = false; }
boolean sig = true;
if (len < 0) { len = -len; sig = false; }
return uaddSub(val, len, sig, add & LONG_MASK, addh, true);
}

Expand All @@ -279,7 +277,8 @@ private static int[] addUnsafe0(final int[] val, final long add) {
if (len == 0)
return assignInPlace(val, 1, (int)add, (int)addh);

boolean sig = true; if (len < 0) { len = -len; sig = false; }
boolean sig = true;
if (len < 0) { len = -len; sig = false; }
return uaddSubInPlace(val, len, sig, add & LONG_MASK, addh, true);
}

Expand All @@ -295,8 +294,7 @@ private static int[] addUnsafe0(final int[] val, final long add) {
* @param val The {@linkplain BigInt#val() value-encoded minuend}.
* @param sig The sign of the unsigned {@code long} to subtract.
* @param sub The subtrahend (unsigned).
* @return The result of the subtraction of the specified amount from the provided {@linkplain BigInt#val() value-encoded
* minuend}.
* @return The result of the subtraction of the specified amount from the provided {@linkplain BigInt#val() value-encoded minuend}.
* @complexity O(n)
*/
public static int[] sub(final int[] val, final int sig, final long sub) {
Expand All @@ -316,7 +314,8 @@ private static int[] sub0(final int[] val, final long sub) {
if (len == 0)
return assignInPlace(val.length >= 3 ? val : alloc(3), -1, (int)sub, (int)subh);

boolean sig = true; if (len < 0) { len = -len; sig = false; }
boolean sig = true;
if (len < 0) { len = -len; sig = false; }
return uaddSub(val, len, sig, sub & LONG_MASK, subh, false);
}

Expand All @@ -329,7 +328,8 @@ private static int[] subUnsafe0(final int[] val, final long sub) {
if (len == 0)
return assignInPlace(val, -1, (int)sub, (int)subh);

boolean sig = true; if (len < 0) { len = -len; sig = false; }
boolean sig = true;
if (len < 0) { len = -len; sig = false; }
return uaddSubInPlace(val, len, sig, sub & LONG_MASK, subh, false);
}

Expand Down Expand Up @@ -439,8 +439,7 @@ protected static int[] addInPlace(final int[] val, final int[] add) {
}

/**
* Subtracts a {@linkplain BigInt#val() value-encoded subtrahend} from the provided {@linkplain BigInt#val() value-encoded
* minuend}.
* Subtracts a {@linkplain BigInt#val() value-encoded subtrahend} from the provided {@linkplain BigInt#val() value-encoded minuend}.
*
* <pre>
* val = val - sub
Expand Down Expand Up @@ -491,12 +490,14 @@ private static int[] addSub(int[] val, final int[] add, final boolean addOrSub,
return val;
}

boolean sig = true; if (len < 0) { len = -len; sig = false; }
boolean sig = true;
if (len < 0) { len = -len; sig = false; }
return addSub0(val, len, sig, add, addOrSub, inPlace);
}

static int[] addSub0(int[] val, int len, boolean sig, final int[] add, final boolean addOrSub, final boolean inPlace) {
int len2 = add[0]; if (len2 < 0) { len2 = -len2; }
int len2 = add[0];
if (len2 < 0) { len2 = -len2; }
if (addOrSub == (sig == add[0] >= 0))
return addVal(val, len, sig, add, len2);

Expand Down

0 comments on commit 5279ae0

Please sign in to comment.