sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1529483 - in /sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util: DoubleDouble.java Numerics.java
Date Sat, 05 Oct 2013 16:42:00 GMT
Author: desruisseaux
Date: Sat Oct  5 16:42:00 2013
New Revision: 1529483

URL: http://svn.apache.org/r1529483
Log:
Specify the threshold for zero value as constant, for clarity.

Modified:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java?rev=1529483&r1=1529482&r2=1529483&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
[UTF-8] Sat Oct  5 16:42:00 2013
@@ -62,6 +62,11 @@ import org.apache.sis.math.MathFunctions
  */
 public final class DoubleDouble extends Number {
     /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -7602414219228638550L;
+
+    /**
      * {@code true} for disabling the extended precision. This variable should always be
{@code false},
      * except for testing purpose. If set to {@code true}, then all double-double arithmetic
operations
      * are immediately followed by a clearing of {@link DoubleDouble#error}.  The result
should then be
@@ -79,9 +84,11 @@ public final class DoubleDouble extends 
     public static final boolean DISABLED = false;
 
     /**
-     * For cross-version compatibility.
+     * When computing <var>a</var> - <var>b</var> as a double-double
(106 significand bits) value,
+     * if the amount of non-zero significand bits is equals or lower than that amount, consider
the
+     * result as zero.
      */
-    private static final long serialVersionUID = -7602414219228638550L;
+    private static final int ZERO_THRESHOLD = 3;
 
     /**
      * The split constant used as part of multiplication algorithms. The split algorithm
is as below
@@ -426,11 +433,11 @@ public final class DoubleDouble extends 
              * The two values almost cancelled, only their error terms are different.
              * The number of significand bits (mantissa) in the IEEE 'double' representation
is 52,
              * not counting the hidden bit. So estimate the accuracy of the double-double
number as
-             * the accuracy of the 'double' value (which is 1 ULP) scaled as if we had 50
additional
-             * significand bits (we ignore 2 bits as a safety margin). If the error is not
greater
-             * than that value, then assume that it is not significant.
+             * the accuracy of the 'double' value (which is 1 ULP) scaled as if we had 52
additional
+             * significand bits (we ignore some more bits if ZERO_THRESHOLD is greater than
1).
+             * If the error is not greater than that value, then assume that it is not significant.
              */
-            if (Math.abs(error) <= Math.scalb(Math.ulp(otherValue), -50)) {
+            if (Math.abs(error) <= Math.scalb(Math.ulp(otherValue), ZERO_THRESHOLD - Numerics.SIGNIFICAND_SIZE))
{
                 error = 0;
                 return;
             }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java?rev=1529483&r1=1529482&r2=1529483&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
[UTF-8] Sat Oct  5 16:42:00 2013
@@ -77,6 +77,12 @@ public final class Numerics extends Stat
     public static final long SIGN_BIT_MASK = Long.MIN_VALUE;
 
     /**
+     * Number of bits in the significand (mantissa) part of IEEE 754 {@code double} representation,
+     * including the hidden bit.
+     */
+    static final int SIGNIFICAND_SIZE = 53;
+
+    /**
      * A prime number used for hash code computation. Value 31 is often used because
      * some modern compilers can optimize {@code x*31} as {@code (x << 5) - x}
      * (Josh Bloch, <cite>Effective Java</cite>).



Mime
View raw message