You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2015/05/05 09:40:32 UTC

[math] Looking more precisely at pow(+/-0.0, y).

Repository: commons-math
Updated Branches:
  refs/heads/h10-builds 96903ec43 -> 67da172db


Looking more precisely at pow(+/-0.0, y).

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/67da172d
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/67da172d
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/67da172d

Branch: refs/heads/h10-builds
Commit: 67da172db4b70c00510ce86ff8b5d5417425b0f3
Parents: 96903ec
Author: Luc Maisonobe <lu...@apache.org>
Authored: Tue May 5 09:40:18 2015 +0200
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Tue May 5 09:40:18 2015 +0200

----------------------------------------------------------------------
 .../org/apache/commons/math4/util/FastMath.java | 19 ++++---------
 .../apache/commons/math4/util/FastMathTest.java | 29 --------------------
 2 files changed, 5 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/67da172d/src/main/java/org/apache/commons/math4/util/FastMath.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/util/FastMath.java b/src/main/java/org/apache/commons/math4/util/FastMath.java
index 59cd2d8..6da1535 100644
--- a/src/main/java/org/apache/commons/math4/util/FastMath.java
+++ b/src/main/java/org/apache/commons/math4/util/FastMath.java
@@ -1479,22 +1479,26 @@ public class FastMath {
                 long yi = (long) y;
 
                 if (y < 0 && y == yi && (yi & 1) == 1) {
+                    System.out.format(java.util.Locale.US, "in if (y < 0 && y == yi && (yi & 1) == 1) --> return Double.NEGATIVE_INFINITY%n");
                     return Double.NEGATIVE_INFINITY;
                 }
 
                 if (y > 0 && y == yi && (yi & 1) == 1) {
+                    System.out.format(java.util.Locale.US, "in if (y > 0 && y == yi && (yi & 1) == 1) --> return -0.0%n");
                     return -0.0;
                 }
             }
 
             if (y < 0) {
-                System.out.format(java.util.Locale.US, "in if (y < 0)%n");
+                System.out.format(java.util.Locale.US, "in if (y < 0) --> return Double.POSITIVE_INFINITY%n");
                 return Double.POSITIVE_INFINITY;
             }
             if (y > 0) {
+                System.out.format(java.util.Locale.US, "in if (y > 0) --> return 0.0%n");
                 return 0.0;
             }
 
+            System.out.format(java.util.Locale.US, "in neither (y < 0) not (y > 0) --> return Double.NaN%n");
             return Double.NaN;
         }
 
@@ -1510,26 +1514,13 @@ public class FastMath {
         }
 
         if (y == Double.POSITIVE_INFINITY) {
-            System.out.format(java.util.Locale.US, "in if (y == Double.POSITIVE_INFINITY)%n");
-            System.out.format(java.util.Locale.US, "x = %x, %22.19f, y = %x, %22.19f%n",
-                              Double.doubleToRawLongBits(x), x,
-                              Double.doubleToRawLongBits(y), y);
             if (x * x == 1.0) {
-                System.out.format(java.util.Locale.US, "in if(x * x == 1.0) --> return NaN%n",
-                                  Double.doubleToRawLongBits(x), x,
-                                  Double.doubleToRawLongBits(y), y);
                 return Double.NaN;
             }
 
             if (x * x > 1.0) {
-                System.out.format(java.util.Locale.US, "in if(x * x > 1.0) --> return positive infinity%n",
-                                  Double.doubleToRawLongBits(x), x,
-                                  Double.doubleToRawLongBits(y), y);
                 return Double.POSITIVE_INFINITY;
             } else {
-                System.out.format(java.util.Locale.US, "in else (i.e. not x * x > 1.0) --> return 0.0%n",
-                                  Double.doubleToRawLongBits(x), x,
-                                  Double.doubleToRawLongBits(y), y);
                 return 0.0;
             }
         }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/67da172d/src/test/java/org/apache/commons/math4/util/FastMathTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/util/FastMathTest.java b/src/test/java/org/apache/commons/math4/util/FastMathTest.java
index 4d34683..e981dda 100644
--- a/src/test/java/org/apache/commons/math4/util/FastMathTest.java
+++ b/src/test/java/org/apache/commons/math4/util/FastMathTest.java
@@ -20,7 +20,6 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
 import java.math.BigInteger;
-import java.util.Locale;
 
 import org.apache.commons.math4.TestUtils;
 import org.apache.commons.math4.dfp.Dfp;
@@ -30,8 +29,6 @@ import org.apache.commons.math4.exception.MathArithmeticException;
 import org.apache.commons.math4.random.MersenneTwister;
 import org.apache.commons.math4.random.RandomGenerator;
 import org.apache.commons.math4.random.Well1024a;
-import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.Precision;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -53,32 +50,6 @@ public class FastMathTest {
     }
 
     @Test
-    public void testH10Print() {
-        print("0.0",                                          0.0);
-        print("-0.0",                                         -0.0);
-        print("+0.0",                                         +0.0);
-        print("Double.POSITIVE_INFINITY",                     Double.POSITIVE_INFINITY);
-        print("Double.NEGATIVE_INFINITY",                     Double.NEGATIVE_INFINITY);
-        print("Double.longBitsToDouble(0x0L)",                Double.longBitsToDouble(0x0L));
-        print("Double.longBitsToDouble(0x1L)",                Double.longBitsToDouble(0x1L));
-        print("Double.longBitsToDouble(0x8000000000000000L)", Double.longBitsToDouble(0x8000000000000000L));
-        print("Double.longBitsToDouble(0x8000000000000001L)", Double.longBitsToDouble(0x8000000000000001L));
-        print("Precision.SAFE_MIN",                           Precision.SAFE_MIN);
-        print("Precision.EPSILON",                            Precision.EPSILON);
-        print("Double.MIN_VALUE",                             Double.MIN_VALUE);
-        print("Double.MAX_VALUE",                             Double.MAX_VALUE);
-        print("1.0",                                          1.0);
-        print("FastMath.nextUp(1.0)",                         FastMath.nextUp(1.0));
-        print("FastMath.nextDown(1.0)",                       FastMath.nextDown(1.0));
-        print("FastMath.nextUp(1.0) - 1.0",                   FastMath.nextUp(1.0) - 1.0);
-        print("1.0 - FastMath.nextDown(1.0)",                 1.0 - FastMath.nextDown(1.0));
-    }
-
-    private static void print(final String spec, final double x) {
-        System.out.format(Locale.US, "%s 0x%x %23.16e%n",  spec, Double.doubleToRawLongBits(x), x);
-    }
-
-    @Test
     public void testMinMaxDouble() {
         double[][] pairs = {
             { -50.0, 50.0 },