You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2015/05/07 14:36:12 UTC
[math] Testing different branching.
Repository: commons-math
Updated Branches:
refs/heads/h10-builds 471285732 -> 809ce8a30
Testing different branching.
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/809ce8a3
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/809ce8a3
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/809ce8a3
Branch: refs/heads/h10-builds
Commit: 809ce8a30485e65a792674692a8dd66b60c48d98
Parents: 4712857
Author: tn <th...@gmail.com>
Authored: Thu May 7 14:35:55 2015 +0200
Committer: tn <th...@gmail.com>
Committed: Thu May 7 14:35:55 2015 +0200
----------------------------------------------------------------------
.../org/apache/commons/math4/util/FastMath.java | 44 +++++---------------
.../apache/commons/math4/util/FastMathTest.java | 5 +--
2 files changed, 12 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/809ce8a3/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 24bb857..cc4caea 100644
--- a/src/main/java/org/apache/commons/math4/util/FastMath.java
+++ b/src/main/java/org/apache/commons/math4/util/FastMath.java
@@ -1462,13 +1462,11 @@ public class FastMath {
if (y == 0.0) {
return 1.0;
- }
-
- if (x != x) { // X is NaN
+ } else if (x != x) { // X is NaN
return x;
- }
-
- if (x == 0) {
+ } else if (y != y) { // y is NaN
+ return y;
+ } else if (x == 0) {
long bits = Double.doubleToRawLongBits(x);
if ((bits & 0x8000000000000000L) != 0) {
// -zero
@@ -1485,26 +1483,16 @@ public class FastMath {
if (y < 0) {
return Double.POSITIVE_INFINITY;
- }
- if (y > 0) {
+ } else {
return 0.0;
}
-
- return Double.NaN;
- }
-
- if (x == Double.POSITIVE_INFINITY) {
- if (y != y) { // y is NaN
- return y;
- }
+ } else if (x == Double.POSITIVE_INFINITY) {
if (y < 0.0) {
return 0.0;
} else {
return Double.POSITIVE_INFINITY;
}
- }
-
- if (y == Double.POSITIVE_INFINITY) {
+ } else if (y == Double.POSITIVE_INFINITY) {
if (x * x == 1.0) {
return Double.NaN;
}
@@ -1514,13 +1502,7 @@ public class FastMath {
} else {
return 0.0;
}
- }
-
- if (x == Double.NEGATIVE_INFINITY) {
- if (y != y) { // y is NaN
- return y;
- }
-
+ } else if (x == Double.NEGATIVE_INFINITY) {
if (y < 0) {
long yi = (long) y;
if (y == yi && (yi & 1) == 1) {
@@ -1538,10 +1520,7 @@ public class FastMath {
return Double.POSITIVE_INFINITY;
}
- }
-
- if (y == Double.NEGATIVE_INFINITY) {
-
+ } else if (y == Double.NEGATIVE_INFINITY) {
if (x * x == 1.0) {
return Double.NaN;
}
@@ -1551,10 +1530,7 @@ public class FastMath {
} else {
return 0.0;
}
- }
-
- /* Handle special case x<0 */
- if (x < 0) {
+ } else if (x < 0) { /* Handle special case x<0 */
// y is an even integer in this case
if (y >= TWO_POWER_53 || y <= -TWO_POWER_53) {
return pow(-x, y);
http://git-wip-us.apache.org/repos/asf/commons-math/blob/809ce8a3/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 7f5f843..529bba4 100644
--- a/src/test/java/org/apache/commons/math4/util/FastMathTest.java
+++ b/src/test/java/org/apache/commons/math4/util/FastMathTest.java
@@ -369,7 +369,8 @@ public class FastMathTest {
@Test
public void testPowSpecialCases() {
-
+ Assert.assertEquals("pow(0.5, Infinity) should be 0.0", 0.0, FastMath.pow(0.5, Double.POSITIVE_INFINITY), Precision.EPSILON);
+
Assert.assertEquals("pow(-1, 0) should be 1.0", 1.0, FastMath.pow(-1.0, 0.0), Precision.EPSILON);
Assert.assertEquals("pow(-1, -0) should be 1.0", 1.0, FastMath.pow(-1.0, -0.0), Precision.EPSILON);
@@ -386,8 +387,6 @@ public class FastMathTest {
Assert.assertTrue("pow(0.5, -Infinity) should be Infinity", Double.isInfinite(FastMath.pow(0.5, Double.NEGATIVE_INFINITY)));
- Assert.assertEquals("pow(0.5, Infinity) should be 0.0", 0.0, FastMath.pow(0.5, Double.POSITIVE_INFINITY), Precision.EPSILON);
-
Assert.assertEquals("pow(2.0, -Infinity) should be 0.0", 0.0, FastMath.pow(2.0, Double.NEGATIVE_INFINITY), Precision.EPSILON);
Assert.assertEquals("pow(0.0, 0.5) should be 0.0", 0.0, FastMath.pow(0.0, 0.5), Precision.EPSILON);