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 2019/12/24 22:31:17 UTC

[commons-numbers] 09/09: Do not duplicate Precision.EPSILON.

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 ba07e65b74e4f6a6a99437bf365057ad45769243
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Tue Dec 24 22:04:37 2019 +0000

    Do not duplicate Precision.EPSILON.
    
    The class already imports Precision for use in equality testing so use
    the public constant direct.
---
 .../apache/commons/numbers/complex/Complex.java    | 23 ++++------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index c926e6e..0ddddf4 100644
--- a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
@@ -113,21 +113,6 @@ public final class Complex implements Serializable  {
      * Equal to sqrt(u) * 2 with u the smallest normalised floating-point value.
      */
     private static final double SAFE_LOWER = Math.sqrt(Double.MIN_NORMAL) * 2;
-    /** Exponent offset in IEEE754 representation. */
-    private static final long EXPONENT_OFFSET = 1023L;
-    /**
-     * Largest double-precision floating-point number such that
-     * {@code 1 + EPSILON} is numerically equal to 1. This value is an upper
-     * bound on the relative error due to rounding real numbers to double
-     * precision floating-point numbers.
-     *
-     * <p>In IEEE 754 arithmetic, this is 2<sup>-53</sup>.</p>
-     *
-     * <p>Copied from o.a.c.numbers.core.Precision
-     *
-     * @see <a href="http://en.wikipedia.org/wiki/Machine_epsilon">Machine epsilon</a>
-     */
-    private static final double EPSILON = Double.longBitsToDouble((EXPONENT_OFFSET - 53L) << 52);
 
     /** Serializable version identifier. */
     private static final long serialVersionUID = 20180201L;
@@ -1431,7 +1416,7 @@ public final class Complex implements Serializable  {
                 }
             } else {
                 // Hull et al: Exception handling code from figure 6
-                if (y <= (EPSILON * Math.abs(xm1))) {
+                if (y <= (Precision.EPSILON * Math.abs(xm1))) {
                     if (x < 1) {
                         re = Math.acos(x);
                         im = y / Math.sqrt(xp1 * (1 - x));
@@ -1456,7 +1441,7 @@ public final class Complex implements Serializable  {
                     // u = Double.MIN_NORMAL
                     re = Math.sqrt(y);
                     im = Math.sqrt(y);
-                } else if (EPSILON * y - 1 >= x) {
+                } else if (Precision.EPSILON * y - 1 >= x) {
                     re = PI_OVER_2;
                     im = LN_2 + Math.log(y);
                 } else if (x > 1) {
@@ -1603,7 +1588,7 @@ public final class Complex implements Serializable  {
                 }
             } else {
                 // Hull et al: Exception handling code from figure 3
-                if (y <= (EPSILON * Math.abs(xm1))) {
+                if (y <= (Precision.EPSILON * Math.abs(xm1))) {
                     if (x < 1) {
                         re = Math.asin(x);
                         im = y / Math.sqrt(-xp1 * xm1);
@@ -1625,7 +1610,7 @@ public final class Complex implements Serializable  {
                     // u = Double.MIN_NORMAL
                     re = PI_OVER_2 - Math.sqrt(y);
                     im = Math.sqrt(y);
-                } else if (EPSILON * y - 1 >= x) {
+                } else if (Precision.EPSILON * y - 1 >= x) {
                     // Possible underflow:
                     re = x / y;
                     im = LN_2 + Math.log(y);