Skip to content

Commit 2917774

Browse files
committed
Fixed some more bug
1 parent 785d80d commit 2917774

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/main/java/com/thealgorithms/bitmanipulation/BitwiseGCD.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
*/
2525
public final class BitwiseGCD {
2626

27-
private BitwiseGCD() { }
27+
private BitwiseGCD() {
28+
29+
}
2830

2931
/**
3032
* Computes GCD of two long values using Stein's algorithm (binary GCD).
@@ -104,11 +106,15 @@ private static long absOrThrowIfOverflow(long x) {
104106
* will be thrown.
105107
*/
106108
public static long gcd(long... values) {
107-
if (values == null || values.length == 0) return 0L;
109+
if (values == null || values.length == 0) {
110+
return 0L;
111+
}
108112
long result = values[0];
109113
for (int i = 1; i < values.length; i++) {
110114
result = gcd(result, values[i]);
111-
if (result == 1L) return 1L; // early exit
115+
if (result == 1L) {
116+
return 1L; // early exit
117+
}
112118
}
113119
return result;
114120
}
@@ -117,13 +123,14 @@ public static long gcd(long... values) {
117123
* BigInteger-backed gcd that works for the full integer range (and beyond).
118124
* This is the recommended method when inputs may be Long.MIN_VALUE or when you
119125
* need an exact result even if it is greater than Long.MAX_VALUE.
120-
*
121126
* @param a first value (may be negative)
122127
* @param b second value (may be negative)
123128
* @return non-negative gcd as a {@link BigInteger}
124129
*/
125130
public static BigInteger gcdBig(BigInteger a, BigInteger b) {
126-
if (a == null || b == null) throw new NullPointerException("Arguments must not be null");
131+
if (a == null || b == null) {
132+
throw new NullPointerException("Arguments must not be null");
133+
}
127134
return a.abs().gcd(b.abs());
128135
}
129136

@@ -140,5 +147,4 @@ public static BigInteger gcdBig(long a, long b) {
140147
public static int gcd(int a, int b) {
141148
return (int) gcd((long) a, (long) b);
142149
}
143-
144-
}
150+
}

src/test/java/com/thealgorithms/bitmanipulation/BitwiseGCDTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,4 @@ public void testGcdEdgeCasesMixed() {
107107
assertEquals(1L, BitwiseGCD.gcd(1L, Long.MAX_VALUE));
108108
assertEquals(1L, BitwiseGCD.gcd(Long.MAX_VALUE, 1L));
109109
}
110-
111-
}
110+
}

0 commit comments

Comments
 (0)