@@ -92,7 +92,7 @@ public static BigNumber value(final Rational x) {
9292 * TESTME
9393 *
9494 * @param whole a non-negative long.
95- * @param decimals a non-negative long, for example 14 for a 3.14 valued result.
95+ * @param decimals a non-negative long, for example, 14 for a 3.14 valued result.
9696 * @param sign true if the result should be positive.
9797 * @return a new BigNumber.
9898 */
@@ -115,7 +115,7 @@ public static BigNumber value(final long whole, final long decimals, final boole
115115 * TESTME
116116 *
117117 * @param whole a non-negative long.
118- * @param decimals a non-negative long, for example 14 for a 3.14 valued result.
118+ * @param decimals a non-negative long, for example, 14 for a 3.14 valued result.
119119 * @return a new BigNumber.
120120 */
121121 public static BigNumber value (final long whole , final long decimals ) {
@@ -275,7 +275,6 @@ public BigNumber add(final BigNumber that) {
275275 final boolean subtract = !that .sign ;
276276 for (int i = resultLength - 1 ; i >= 0 ; i --) {
277277 int sum = carry ;
278- borrow = false ;
279278 if (i < thisLength ) sum += decimals [i ];
280279 if (i < thatLength ) sum += subtract ? -that .decimals [i ] : that .decimals [i ];
281280 if (sum < 0 ) {
@@ -303,23 +302,22 @@ public BigNumber add(final BigNumber that) {
303302 * @return a negative, zero, or positive int.
304303 */
305304 public int compareTo (final BigNumber that ) {
306- if (this .equals (that )) {
305+ if (this .equals (that ))
307306 return 0 ;
308- } else {
307+ else {
309308 int wholeComparison = this .whole .compareTo (that .whole );
310- if (wholeComparison != 0 ) {
309+ if (wholeComparison != 0 )
311310 return this .sign ? wholeComparison : -wholeComparison ;
312- } else {
311+ else {
313312 final int [] thisDecimals = this .decimals ;
314313 final int [] thatDecimals = that .decimals ;
315314 final int maxLength = Math .max (thisDecimals .length , thatDecimals .length );
316315 for (int i = 0 ; i < maxLength ; i ++) {
317316 int thisNumber = (i < thisDecimals .length ) ? thisDecimals [i ] : 0 ;
318317 int thatNumber = (i < thatDecimals .length ) ? thatDecimals [i ] : 0 ;
319- if (thisNumber != thatNumber ) {
318+ if (thisNumber != thatNumber )
320319 return this .sign ? Integer .compare (thisNumber , thatNumber )
321320 : Integer .compare (thatNumber , thisNumber );
322- }
323321 }
324322 return 0 ;
325323 }
@@ -374,10 +372,10 @@ public BigNumber multiplyWithKaratsuba(final BigNumber other) {
374372 * Multiplies two integer arrays representing numerical values and returns the result in an array.
375373 * TESTME
376374 *
377- * @param arr1 the first integer array representing a number
378- * @param arr2 the second integer array representing a number
379- * @param start the starting index for the portion of the arrays to be considered
380- * @param end the ending index for the portion of the arrays to be considered
375+ * @param arr1 the first integer array representing a number
376+ * @param arr2 the second integer array representing a number
377+ * @param start the starting index for the portion of the arrays to be considered
378+ * @param end the ending index for the portion of the arrays to be considered
381379 * @param resultSize the size of the resulting array
382380 * @return an integer array representing the result of the multiplication
383381 */
@@ -410,10 +408,10 @@ private int[] multiplyArrays(final int[] arr1, final int[] arr2, final int start
410408 * efficient computation of the product.
411409 * TESTME
412410 *
413- * @param first The first integer array, where each element represents part of a larger number.
414- * @param second The second integer array, where each element represents part of a larger number.
415- * @param start The starting index for the relevant segment of the arrays to be considered for multiplication.
416- * @param end The ending index for the relevant segment of the arrays to be considered for multiplication.
411+ * @param first The first integer array, where each element represents part of a larger number.
412+ * @param second The second integer array, where each element represents part of a larger number.
413+ * @param start The starting index for the relevant segment of the arrays to be considered for multiplication.
414+ * @param end The ending index for the relevant segment of the arrays to be considered for multiplication.
417415 * @param resSize The size of the result array to store the product of the two arrays.
418416 * @return An array representing the product of the two numbers, with the result properly sized as per resSize.
419417 */
@@ -460,7 +458,7 @@ private int[] recursiveKarat(final int[] first, final int[] second, final int st
460458 * Zeros are appended to the end of the array to maintain the original length.
461459 * TESTME
462460 *
463- * @param arr the array of integers to be shifted; must not be null
461+ * @param arr the array of integers to be shifted; must not be null
464462 * @param offset the number of positions to shift the elements to the left; must be non-negative
465463 */
466464 private void leftShift (final int [] arr , final int offset ) {
@@ -479,10 +477,10 @@ private void leftShift(final int[] arr, final int offset) {
479477 * and stores the result in a new array of specified size.
480478 * TESTME
481479 *
482- * @param first the input array from which elements are added
483- * @param start the starting index of the first part in the array
484- * @param middle the ending index of the first part in the array
485- * @param end the ending index of the second part in the array
480+ * @param first the input array from which elements are added
481+ * @param start the starting index of the first part in the array
482+ * @param middle the ending index of the first part in the array
483+ * @param end the ending index of the second part in the array
486484 * @param resSize the size of the resulting array
487485 * @return an array containing the result of the addition with carry
488486 */
@@ -516,8 +514,8 @@ private int[] add(final int[] first, final int start, final int middle, final in
516514 * Handles carry values appropriately during addition.
517515 * TESTME
518516 *
519- * @param first the array representing the first number. Must be large enough
520- * to accommodate the result of the addition.
517+ * @param first the array representing the first number. Must be large enough
518+ * to accommodate the result of the addition.
521519 * @param second the array representing the second number. Its digits will be
522520 * added to the corresponding digits of the first array.
523521 */
@@ -646,14 +644,13 @@ public BigNumber divide(final long x) {
646644 *
647645 * @param o the object to be compared for equality with this BigNumber
648646 * @return true if the specified object is a BigNumber, has the same whole part,
649- * sign, and decimals as this BigNumber; otherwise, false
647+ * sign, and decimals as this BigNumber; otherwise, false
650648 */
651649 @ Override
652650 public boolean equals (final Object o ) {
653651 if (this == o ) return true ;
654652 // NOTE That if you replace this as recommended, you must ensure that Java is compiling on CircleCI with the correct compiler (Java 16).
655- if ( !(o instanceof BigNumber ) ) return false ;
656- final BigNumber bigNumber = (BigNumber ) o ;
653+ if (!(o instanceof BigNumber bigNumber )) return false ;
657654 return whole .equals (bigNumber .whole ) && sign == bigNumber .sign && Arrays .equals (decimals , bigNumber .decimals );
658655 }
659656
@@ -703,7 +700,7 @@ public BigNumber(final BigInteger whole) {
703700 }
704701
705702 /**
706- * Secondary constructor to creat a BigNumber which has no decimal part.
703+ * Secondary constructor to create a BigNumber which has no decimal part.
707704 *
708705 * @param whole any BigInteger value (positive or negative).
709706 */
@@ -731,7 +728,7 @@ private static int[] trim(final int[] array) {
731728 * if positive, retrieves the corresponding decimal index;
732729 * if negative, returns 0.
733730 * @return the element value as a long; the whole number if the index is 0,
734- * the decimal value if the index is positive, or 0 if the index is negative.
731+ * the decimal value if the index is positive, or 0 if the index is negative.
735732 */
736733 private long element (final int i ) {
737734 if (i == 0 ) return whole .longValueExact ();
@@ -768,15 +765,15 @@ public static void main(final String[] args) {
768765 /**
769766 * Measures and compares the performance of two multiplication algorithms (standard and Karatsuba) for large numbers.
770767 * TESTME
771- *
768+ * <p>
772769 * The method performs the following steps:
773770 * 1. Initializes a large constant string representing a seed value and extracts a portion for computation.
774771 * 2. Parses the seed string into a `BigNumber` object for arithmetic operations.
775772 * 3. Uses a loop to measure the time taken to execute multiplication using the standard multiplication method.
776773 * 4. Computes the average execution time for the standard multiplication method.
777774 * 5. Repeats the process for the Karatsuba multiplication method, measuring and calculating average execution time.
778- * 6. Prints the execution times for both methods, and computes the percentage improvement offered by the Karatsuba method.
779- *
775+ * 6. Prints the execution times for both methods and computes the percentage improvement offered by the Karatsuba method.
776+ * <p>
780777 * Notes:
781778 * - Considers the potential use of performance measurement utilities such as `StopWatch` or `Timer`.
782779 * - Ensures timing accuracy by iterating over each method multiple times and averaging the results.
0 commit comments