diff --git a/src/main/java/org/apache/commons/math4/distribution/EnumeratedDistribution.java b/src/main/java/org/apache/commons/math4/distribution/EnumeratedDistribution.java index 8e45c0c88..8e1149f0d 100644 --- a/src/main/java/org/apache/commons/math4/distribution/EnumeratedDistribution.java +++ b/src/main/java/org/apache/commons/math4/distribution/EnumeratedDistribution.java @@ -213,10 +213,10 @@ public class EnumeratedDistribution implements Serializable { index = -index-1; } - if (index >= 0 && index < probabilities.length) { - if (randomValue < cumulativeProbabilities[index]) { - return singletons.get(index); - } + if (index >= 0 && + index < probabilities.length && + randomValue < cumulativeProbabilities[index]) { + return singletons.get(index); } /* This should never happen, but it ensures we will return a correct diff --git a/src/main/java/org/apache/commons/math4/fitting/leastsquares/GaussNewtonOptimizer.java b/src/main/java/org/apache/commons/math4/fitting/leastsquares/GaussNewtonOptimizer.java index 5999b2056..747c7922b 100644 --- a/src/main/java/org/apache/commons/math4/fitting/leastsquares/GaussNewtonOptimizer.java +++ b/src/main/java/org/apache/commons/math4/fitting/leastsquares/GaussNewtonOptimizer.java @@ -234,13 +234,11 @@ public class GaussNewtonOptimizer implements LeastSquaresOptimizer { currentPoint = current.getPoint(); // Check convergence. - if (previous != null) { - if (checker.converged(iterationCounter.getCount(), previous, current)) { - return new OptimumImpl( - current, - evaluationCounter.getCount(), - iterationCounter.getCount()); - } + if (previous != null && + checker.converged(iterationCounter.getCount(), previous, current)) { + return new OptimumImpl(current, + evaluationCounter.getCount(), + iterationCounter.getCount()); } // solve the linearized least squares problem