You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2025/09/25 12:54:03 UTC

(commons-numbers) 11/16: Update condition tests to have literal on the right

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit a7f45f14e6bd22f9957bd0df58b59c0d539e250e
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Thu Sep 25 12:41:58 2025 +0100

    Update condition tests to have literal on the right
---
 .../java/org/apache/commons/numbers/primes/Primes.java     |  6 +++---
 .../org/apache/commons/numbers/primes/SmallPrimes.java     | 14 +++++++-------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java
index ea9ed95a..2ca38f43 100644
--- a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java
+++ b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java
@@ -51,7 +51,7 @@ public final class Primes {
         }
 
         for (final int p : SmallPrimes.PRIMES) {
-            if (0 == (n % p)) {
+            if (n % p == 0) {
                 return n == p;
             }
         }
@@ -81,9 +81,9 @@ public final class Primes {
         // prepare entry in the +2, +4 loop:
         // n should not be a multiple of 3
         final int rem = n % 3;
-        if (0 == rem) { // if n % 3 == 0
+        if (rem == 0) { // if n % 3 == 0
             n += 2; // n % 3 == 2
-        } else if (1 == rem) { // if n % 3 == 1
+        } else if (rem == 1) { // if n % 3 == 1
             n += 4; // n % 3 == 2
         }
         while (true) { // this loop skips all multiple of 3
diff --git a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/SmallPrimes.java b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/SmallPrimes.java
index aed4b8f5..f600c03d 100644
--- a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/SmallPrimes.java
+++ b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/SmallPrimes.java
@@ -150,7 +150,7 @@ final class SmallPrimes {
     static int smallTrialDivision(int n,
                                   final List<Integer> factors) {
         for (final int p : PRIMES) {
-            while (0 == n % p) {
+            while (n % p == 0) {
                 n /= p;
                 factors.add(p);
             }
@@ -195,7 +195,7 @@ final class SmallPrimes {
             final int f = km + a[currentEquivalenceClassIndex];
             if (f > maxFactor) {
                 done = true;
-            } else if (0 == n % f) {
+            } else if (n % f == 0) {
                 n /= f;
                 factors.add(f);
                 done = true;
@@ -222,7 +222,7 @@ final class SmallPrimes {
     static List<Integer> trialDivision(int n) {
         final List<Integer> factors = new ArrayList<>(32);
         n = smallTrialDivision(n, factors);
-        if (1 == n) {
+        if (n == 1) {
             return factors;
         }
         // here we are sure that n is either a prime or a semi prime
@@ -264,17 +264,17 @@ final class SmallPrimes {
             final BigInteger a = BigInteger.valueOf(PRIMES[i]);
             final BigInteger bPow = a.modPow(br, bn);
             int y = bPow.intValue();
-            if (1 != y && y != nMinus1) {
+            if (y != 1 && y != nMinus1) {
                 int j = 1;
-                while (j <= s - 1 && nMinus1 != y) {
+                while (j <= s - 1 && y != nMinus1) {
                     final long square = ((long) y) * y;
                     y = (int) (square % n);
-                    if (1 == y) {
+                    if (y == 1) {
                         return false;
                     } // definitely composite
                     j++;
                 }
-                if (nMinus1 != y) {
+                if (y != nMinus1) {
                     return false;
                 } // definitely composite
             }