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/04 17:21:34 UTC
[math] Revert "Attempt to circumvent some errors which seem to be
platform-dependent."
Repository: commons-math
Updated Branches:
refs/heads/master c771c0080 -> 6571233ed
Revert "Attempt to circumvent some errors which seem to be platform-dependent."
This reverts commit c771c0080b08abd80418c4e88f1be3efec828f0a.
The attempt failed, the error is still present.
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/6571233e
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/6571233e
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/6571233e
Branch: refs/heads/master
Commit: 6571233ed2e9c926b07d752992a96532714ae9af
Parents: c771c00
Author: Luc Maisonobe <lu...@apache.org>
Authored: Mon May 4 17:19:59 2015 +0200
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Mon May 4 17:19:59 2015 +0200
----------------------------------------------------------------------
.../org/apache/commons/math4/util/FastMath.java | 28 +++++++++++---------
.../apache/commons/math4/util/FastMathTest.java | 4 +--
2 files changed, 17 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/6571233e/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 fcd03ea..24bb857 100644
--- a/src/main/java/org/apache/commons/math4/util/FastMath.java
+++ b/src/main/java/org/apache/commons/math4/util/FastMath.java
@@ -315,9 +315,6 @@ public class FastMath {
/** Mask used to clear the non-sign part of a long. */
private static final long MASK_NON_SIGN_LONG = 0x7fffffffffffffffl;
- /** Bits representation of +1.0. */
- private static final long PLUS_ONE_BITS = 0x3ff0000000000000L;
-
/** 2^52 - double numbers this large must be integral (no fraction) or NaN or Infinite */
private static final double TWO_POWER_52 = 4503599627370496.0;
/** 2^53 - double numbers this large must be even. */
@@ -1471,10 +1468,6 @@ public class FastMath {
return x;
}
- if (y != y) { // Y is NaN
- return y;
- }
-
if (x == 0) {
long bits = Double.doubleToRawLongBits(x);
if ((bits & 0x8000000000000000L) != 0) {
@@ -1492,13 +1485,18 @@ public class FastMath {
if (y < 0) {
return Double.POSITIVE_INFINITY;
- } else {
+ }
+ if (y > 0) {
return 0.0;
}
+ return Double.NaN;
}
if (x == Double.POSITIVE_INFINITY) {
+ if (y != y) { // y is NaN
+ return y;
+ }
if (y < 0.0) {
return 0.0;
} else {
@@ -1507,17 +1505,21 @@ public class FastMath {
}
if (y == Double.POSITIVE_INFINITY) {
- long bitsAbsX = MASK_NON_SIGN_LONG & Double.doubleToRawLongBits(x);
- if (bitsAbsX > PLUS_ONE_BITS) {
+ if (x * x == 1.0) {
+ return Double.NaN;
+ }
+
+ if (x * x > 1.0) {
return Double.POSITIVE_INFINITY;
- } else if (bitsAbsX < PLUS_ONE_BITS) {
- return 0.0;
} else {
- return Double.NaN;
+ return 0.0;
}
}
if (x == Double.NEGATIVE_INFINITY) {
+ if (y != y) { // y is NaN
+ return y;
+ }
if (y < 0) {
long yi = (long) y;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/6571233e/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 06a1d07..5d36fea 100644
--- a/src/test/java/org/apache/commons/math4/util/FastMathTest.java
+++ b/src/test/java/org/apache/commons/math4/util/FastMathTest.java
@@ -29,6 +29,8 @@ 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;
@@ -391,8 +393,6 @@ public class FastMathTest {
Assert.assertTrue("pow(-2.0, 3.5) should be NaN", Double.isNaN(FastMath.pow(-2.0, 3.5)));
- Assert.assertTrue("pow(-0.0, NaN) should be NaN", Double.isNaN(FastMath.pow(-0.0, Double.NaN)));
-
// Added tests for a 100% coverage
Assert.assertTrue("pow(+Inf, NaN) should be NaN", Double.isNaN(FastMath.pow(Double.POSITIVE_INFINITY, Double.NaN)));