Author: luc
Date: Fri Apr 20 20:15:11 2012
New Revision: 1328492
URL: http://svn.apache.org/viewvc?rev=1328492&view=rev
Log:
Added a workaround for an OpenJDK issue on sparc solaris.
The compiler has issues with very small double constants, despite they
are perfectly legal Java and representable in IEEE754.
JIRA: MATH-721
Modified:
commons/proper/math/trunk/src/changes/changes.xml
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/PrecisionTest.java
Modified: commons/proper/math/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1328492&r1=1328491&r2=1328492&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Fri Apr 20 20:15:11 2012
@@ -52,6 +52,9 @@ If the output is not quite correct, chec
<body>
<release version="3.1" date="TBD" description="
">
+ <action dev="luc" type="fix" issue="MATH-721">
+ Added a workaround for an OpenJDK issue on sparc solaris with too
small constants.
+ </action>
<action dev="tn" type="fix" issue="MATH-779" due-to="Reid Hochstedler">
Fixed ListPopulation#iterator to return an unmodifiable iterator.
</action>
@@ -66,7 +69,6 @@ If the output is not quite correct, chec
</action>
<action dev="tn" type="add" issue="MATH-773" due-to="Reid Hochstedler">
Added class FixedElapsedTime (new StoppingCondition for evolution of
generations) to genetics package.
- </action>
<action dev="celestin" type="add" issue="MATH-756">
Added classes Decimal64 and Decimal64Field, which are wrapper classes
around primitive doubles. These classes implement FieldElement and Field,
respectively.
</action>
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java?rev=1328492&r1=1328491&r2=1328492&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Precision.java
Fri Apr 20 20:15:11 2012
@@ -30,17 +30,23 @@ import org.apache.commons.math3.util.Fas
* @version $Id$
*/
public class Precision {
+
+ /** Exponent offset in IEEE754 representation. */
+ private static final long EXPONENT_OFFSET = 1023l;
+
/**
* Smallest positive number such that {@code 1 - EPSILON} is not
* numerically equal to 1: {@value}.
+ * In IEEE 754 arithmetic, this is 2<sup>-53</sup>: {@value}.
*/
- public static final double EPSILON = 0x1.0p-53;
+ public static final double EPSILON =
Double.longBitsToDouble((EXPONENT_OFFSET - 53l) << 52);
/**
* Safe minimum, such that {@code 1 / SAFE_MIN} does not overflow.
* In IEEE 754 arithmetic, this is also the smallest normalized
* number 2<sup>-1022</sup>: {@value}.
*/
- public static final double SAFE_MIN = 0x1.0p-1022;
+ public static final double SAFE_MIN =
Double.longBitsToDouble((EXPONENT_OFFSET - 1022l) << 52);
+
/** Offset to order signed double numbers lexicographically. */
private static final long SGN_MASK = 0x8000000000000000L;
/** Offset to order signed double numbers lexicographically. */
Modified:
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/PrecisionTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/PrecisionTest.java?rev=1328492&r1=1328491&r2=1328492&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/PrecisionTest.java
(original)
+++
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/PrecisionTest.java
Fri Apr 20 20:15:11 2012
@@ -467,8 +467,14 @@ public class PrecisionTest {
@Test
+ public void testIssue721() {
+ Assert.assertEquals(-53, FastMath.getExponent(Precision.EPSILON));
+ Assert.assertEquals(-1022, FastMath.getExponent(Precision.SAFE_MIN));
+ }
+
+
+ @Test
public void testRepresentableDelta() {
- int totalCount = 0;
int nonRepresentableCount = 0;
final double x = 100;
final int numTrials = 10000;