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 2022/01/22 13:13:56 UTC

[commons-numbers] 01/05: Move BoostGamma.Policy to package level class

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 d64d4ba5a344ef92fc89ab9547f7fd146a77fd27
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Tue Jan 4 21:17:50 2022 +0000

    Move BoostGamma.Policy to package level class
---
 .../apache/commons/numbers/gamma/BoostGamma.java   | 61 -----------------
 .../commons/numbers/gamma/IncompleteGamma.java     |  2 -
 .../org/apache/commons/numbers/gamma/Policy.java   | 79 ++++++++++++++++++++++
 .../commons/numbers/gamma/RegularizedGamma.java    |  2 -
 .../commons/numbers/gamma/BoostGammaTest.java      |  5 +-
 5 files changed, 81 insertions(+), 68 deletions(-)

diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostGamma.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostGamma.java
index 976458b..ea79786 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostGamma.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostGamma.java
@@ -294,67 +294,6 @@ final class BoostGamma {
     };
 
     /**
-     * Encapsulate the policy for function evaluation.
-     * This is a reduced implementation of the Boost {@code boost::math::policies}
-     * functionality. No settings are preserved for the error handling policy or
-     * promotion of data types for computations.
-     * This controls the convergence criteria and maximum iterations for series evaluations.
-     *
-     * @see <a href="https://www.boost.org/doc/libs/1_77_0/libs/math/doc/html/policy.html">
-     * Policies: Controlling Precision, Error Handling etc</a>
-     */
-    static final class Policy {
-        /** Default policy. The Boost default uses 2^-52 for the epsilon. This uses
-         * 2^-53 to use an extra guard digit in the Kahan series summations.
-         * The minimum value for the Commons continued fraction epsilon is also 2^-53. */
-        private static final Policy DEFAULT = new Policy(0x1.0p-53, 1000000);
-
-        /** Epsilon value for relative error. */
-        private final double eps;
-        /** The maximum number of iterations permitted in a series evaluation. */
-        private final int maxIterations;
-
-        /**
-         * Instantiates a new policy.
-         *
-         * @param eps the eps
-         * @param maxIterations the maximum number of iterations permitted in a series
-         * evaluation
-         */
-        Policy(double eps, int maxIterations) {
-            this.eps = eps;
-            this.maxIterations = maxIterations;
-        }
-
-        /**
-         * Gets the default.
-         *
-         * @return the default policy
-         */
-        static Policy getDefault() {
-            return DEFAULT;
-        }
-
-        /**
-         * Gets the epsilon value for relative error.
-         *
-         * @return the epsilon
-         */
-        double getEps() {
-            return eps;
-        }
-
-        /**
-         * Gets the maximum number of iterations permitted in a series evaluation.
-         *
-         * @return max iterations
-         */
-        int getMaxIterations() {
-            return maxIterations;
-        }
-    }
-
-    /**
      * 53-bit precision implementation of the Lanczos approximation.
      *
      * <p>This implementation is in partial fraction form with the leading constant
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/IncompleteGamma.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/IncompleteGamma.java
index cac2a25..210e8ff 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/IncompleteGamma.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/IncompleteGamma.java
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.numbers.gamma;
 
-import org.apache.commons.numbers.gamma.BoostGamma.Policy;
-
 /**
  * <a href="https://mathworld.wolfram.com/IncompleteGammaFunction.html">
  * Incomplete Gamma functions</a>.
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Policy.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Policy.java
new file mode 100644
index 0000000..bf0d7bf
--- /dev/null
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Policy.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.numbers.gamma;
+
+/**
+ * Encapsulate the policy for function evaluation.
+ * This is a reduced implementation of the Boost {@code boost::math::policies}
+ * functionality. No settings are preserved for the error handling policy or
+ * promotion of data types for computations.
+ * This controls the convergence criteria and maximum iterations for series evaluations.
+ *
+ * @see <a href="https://www.boost.org/doc/libs/1_77_0/libs/math/doc/html/policy.html">
+ * Policies: Controlling Precision, Error Handling etc</a>
+ */
+final class Policy {
+    /** Default policy. The Boost default uses 2^-52 for the epsilon. This uses
+     * 2^-53 to use an extra guard digit in the Kahan series summations.
+     * The minimum value for the Commons continued fraction epsilon is also 2^-53. */
+    private static final Policy DEFAULT = new Policy(0x1.0p-53, 1000000);
+
+    /** Epsilon value for relative error. */
+    private final double eps;
+    /** The maximum number of iterations permitted in a series evaluation. */
+    private final int maxIterations;
+
+    /**
+     * Instantiates a new policy.
+     *
+     * @param eps the eps
+     * @param maxIterations the maximum number of iterations permitted in a series
+     * evaluation
+     */
+    Policy(double eps, int maxIterations) {
+        this.eps = eps;
+        this.maxIterations = maxIterations;
+    }
+
+    /**
+     * Gets the default.
+     *
+     * @return the default policy
+     */
+    static Policy getDefault() {
+        return DEFAULT;
+    }
+
+    /**
+     * Gets the epsilon value for relative error.
+     *
+     * @return the epsilon
+     */
+    double getEps() {
+        return eps;
+    }
+
+    /**
+     * Gets the maximum number of iterations permitted in a series evaluation.
+     *
+     * @return max iterations
+     */
+    int getMaxIterations() {
+        return maxIterations;
+    }
+}
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
index 43cc8ae..e724a70 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.numbers.gamma;
 
-import org.apache.commons.numbers.gamma.BoostGamma.Policy;
-
 /**
  * <a href="https://mathworld.wolfram.com/RegularizedGammaFunction.html">
  * Regularized Gamma functions</a>.
diff --git a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/BoostGammaTest.java b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/BoostGammaTest.java
index 2e03760..fd94d8a 100644
--- a/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/BoostGammaTest.java
+++ b/commons-numbers-gamma/src/test/java/org/apache/commons/numbers/gamma/BoostGammaTest.java
@@ -26,7 +26,6 @@ import java.util.function.DoubleBinaryOperator;
 import java.util.function.DoubleUnaryOperator;
 import java.util.regex.Pattern;
 import org.apache.commons.numbers.gamma.BoostGamma.Lanczos;
-import org.apache.commons.numbers.gamma.BoostGamma.Policy;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.MethodOrderer;
 import org.junit.jupiter.api.Order;
@@ -1290,7 +1289,7 @@ class BoostGammaTest {
         final TestUtils.ErrorStatistics e1 = new TestUtils.ErrorStatistics();
         final TestUtils.ErrorStatistics e2 = new TestUtils.ErrorStatistics();
 
-        final Policy pol = BoostGamma.Policy.getDefault();
+        final Policy pol = Policy.getDefault();
         final DoubleBinaryOperator without = (a, x) -> gammaIncompleteImp(a, x, invert, pol, NO_ASYM_APPROX);
         final DoubleBinaryOperator with = (a, x) -> gammaIncompleteImp(a, x, invert, pol, useAsymp);
         final int expectedField = invert ? 3 : 5;
@@ -1731,7 +1730,7 @@ class BoostGammaTest {
      * @return incomplete tgamma
      */
     private static double incompleteTgammaLargeX(double a, double x) {
-        return BoostGamma.incompleteTgammaLargeX(a, x, BoostGamma.Policy.getDefault());
+        return BoostGamma.incompleteTgammaLargeX(a, x, Policy.getDefault());
     }
 
     /**