sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1693548 - in /sis/branches/JDK8/core/sis-utility/src: main/java/org/apache/sis/internal/util/DoubleDouble.java test/java/org/apache/sis/internal/util/DoubleDoubleTest.java
Date Fri, 31 Jul 2015 09:03:59 GMT
Author: desruisseaux
Date: Fri Jul 31 09:03:59 2015
New Revision: 1693548

URL: http://svn.apache.org/r1693548
Log:
Fix: sqrt() of 0 was producing NaN.

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/DoubleDoubleTest.java

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java?rev=1693548&r1=1693547&r2=1693548&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
[UTF-8] Fri Jul 31 09:03:59 2015
@@ -943,13 +943,15 @@ public final class DoubleDouble extends
      * <blockquote>ε  ≈  (value + error - r²) / (2r)</blockquote>
      */
     public void sqrt() {
-        final double thisValue = this.value;
-        final double thisError = this.error;
-        double r = Math.sqrt(thisValue);
-        setToProduct(r, r);
-        subtract(thisValue, thisError);
-        divide(-2*r, 0); // Multiplication by 2 does not cause any precision lost.
-        setToQuickSum(r, value);
+        if (value != 0) {
+            final double thisValue = this.value;
+            final double thisError = this.error;
+            double r = Math.sqrt(thisValue);
+            setToProduct(r, r);
+            subtract(thisValue, thisError);
+            divide(-2*r, 0);                    // Multiplication by 2 does not cause any
precision lost.
+            setToQuickSum(r, value);
+        }
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/DoubleDoubleTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/DoubleDoubleTest.java?rev=1693548&r1=1693547&r2=1693548&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/DoubleDoubleTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/DoubleDoubleTest.java
[UTF-8] Fri Jul 31 09:03:59 2015
@@ -283,6 +283,9 @@ public final strictfp class DoubleDouble
             dd.subtract(value, error);
             assertEquals(0, dd.doubleValue(), 1E-29);
         }
+        dd.clear();
+        dd.sqrt();
+        assertTrue(dd.isZero());
     }
 
     /**



Mime
View raw message