You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2007/06/07 05:32:38 UTC

svn commit: r545043 - in /harmony/enhanced/classlib/branches/java6/modules/luni/src: main/java/java/lang/ test/java/org/apache/harmony/luni/tests/java/lang/

Author: pyang
Date: Wed Jun  6 20:32:37 2007
New Revision: 545043

URL: http://svn.apache.org/viewvc?view=rev&rev=545043
Log:
Apply patch for HARMONY-4055( [classlib][luni][java6] new constants in java.lang.Double/java.lang.Float and 1 new method getExponent in java.lang.Math)

Modified:
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Double.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Float.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Math.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Double.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Double.java?view=diff&rev=545043&r1=545042&r2=545043
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Double.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Double.java Wed Jun  6 20:32:37 2007
@@ -50,6 +50,15 @@
     public static final double MIN_VALUE = 5e-324;
 
     /* 4.94065645841246544e-324 gets rounded to 9.88131e-324 */
+    
+    /**
+	 * <p>
+	 * Constant for the smallest positive normal value of <code>double</code>.
+	 * </p>
+	 * 
+	 * @since 1.6
+	 */
+	public static final double MIN_NORMAL = 2.2250738585072014E-308;
 
     /**
      * <p>
@@ -66,6 +75,22 @@
      * </p>
      */
     public static final double POSITIVE_INFINITY = 1.0 / 0.0;
+    
+    /**
+     * <p>
+     * Maximum exponent that a finite double variable may have.
+     * </p>
+     * @since 1.6
+     */
+    public static final int MAX_EXPONENT = 1023;
+    
+        /**
+     * <p>
+     * Minimum exponent that a finite double variable may have.
+     * </p>
+     * @since 1.6
+     */
+    public static final int MIN_EXPONENT = -1022;
 
     /**
      * <p>

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Float.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Float.java?view=diff&rev=545043&r1=545042&r2=545043
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Float.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Float.java Wed Jun  6 20:32:37 2007
@@ -48,6 +48,14 @@
      * </p>
      */
     public static final float MIN_VALUE = 1.40129846432481707e-45f;
+    
+    /**
+     * <p>
+     * Constant for the smallest positive normal value of <code>float</code>.
+     * </p>
+     * @since 1.6
+     */
+    public static final float MIN_NORMAL = 1.1754943508222875E-38f;
 
     /**
      * <p>
@@ -84,6 +92,22 @@
 
     // Note: This can't be set to "float.class", since *that* is
     // defined to be "java.lang.Float.TYPE";
+    
+    /**
+     * <p>
+     * Maximum exponent that a finite float variable may have.
+     * </p>
+     * @since 1.6
+     */
+    public static final int MAX_EXPONENT = 127;
+    
+    /**
+     * <p>
+     * Minimum exponent that a finite float variable may have.
+     * </p>
+     * @since 1.6
+     */
+    public static final int MIN_EXPONENT = -126;
 
     /**
      * <p>

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Math.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Math.java?view=diff&rev=545043&r1=545042&r2=545043
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Math.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/Math.java Wed Jun  6 20:32:37 2007
@@ -23,7 +23,19 @@
  * constants.
  */
 public final class Math {
+	
+	private static final int FLOAT_EXPONENT_BIAS = 127;
+
+    private static final int FLOAT_EXPONENT_MASK = 0x7F800000;
+
+    private static final int DOUBLE_MANTISSA_BITS = 52;
+    
+    private static final int FLOAT_MANTISSA_BITS = 23;
+
+    private static final int DOUBLE_EXPONENT_BIAS = 1023;
 
+    private static final long DOUBLE_EXPONENT_MASK = 0x7fff000000000000L;
+    
 	/**
 	 * Standard math constants.
 	 */
@@ -629,4 +641,34 @@
     private native static double nextafter(double x, double y);
 
     private native static float nextafterf(float x, float y); 
+    
+    /**
+     * Answers the exponent of a float.
+     * 
+     * @param f
+     *            the given float
+     * @return the exponent of the float.
+     * 
+     * @since 1.6
+     */
+    public static int getExponent(float f) {
+        int bits = Float.floatToRawIntBits(f);
+        bits = (bits & FLOAT_EXPONENT_MASK) >> FLOAT_MANTISSA_BITS;
+        return bits - FLOAT_EXPONENT_BIAS;
+    }
+
+    /**
+     * Answers the exponent of a double.
+     * 
+     * @param d
+     *            the given double
+     * @return the exponent of the double.
+     * 
+     * @since 1.6
+     */
+    public static int getExponent(double d) {
+        long bits = Double.doubleToRawLongBits(d);
+        bits = (bits & DOUBLE_EXPONENT_MASK) >> DOUBLE_MANTISSA_BITS;
+        return (int) bits - DOUBLE_EXPONENT_BIAS;
+    }    
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java?view=diff&rev=545043&r1=545042&r2=545043
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java Wed Jun  6 20:32:37 2007
@@ -1403,4 +1403,40 @@
             s++;
         }
     }
+    
+    /**
+	 * @tests {@link java.lang.Double#MAX_EXPONENT}
+	 * @since 1.6
+	 */
+	public void test_MAX_EXPONENT() {
+		assertTrue("Wrong value of java.lang.Double.MAX_EXPONENT",
+				Double.MAX_EXPONENT == 1023);
+		assertTrue("Wrong value of java.lang.Double.MAX_EXPONENT",
+				Double.MAX_EXPONENT == Math.getExponent(Double.MAX_VALUE));
+	}
+
+	/**
+	 * @tests {@link java.lang.Double#MIN_EXPONENT}
+	 * @since 1.6
+	 */
+	public void test_MIN_EXPONENT() {
+		assertTrue("Wrong value of java.lang.Double.MIN_EXPONENT",
+				Double.MIN_EXPONENT == -1022);
+		assertTrue("Wrong value of java.lang.Double.MIN_EXPONENT",
+				Double.MIN_EXPONENT == Math.getExponent(Double.MIN_NORMAL));
+	}
+
+	/**
+	 * @tests {@link java.lang.Double#MIN_NORMAL}
+	 * @since 1.6
+	 */
+	public void test_MIN_NORMAL() {
+		assertTrue("Wrong value of java.lang.Double.MIN_NORMAL",
+				Double.MIN_NORMAL == 0x1.0p-1022);
+		assertTrue("Wrong value of java.lang.Double.MIN_NORMAL",
+				Double.MIN_NORMAL == Double
+						.longBitsToDouble(0x0010000000000000L));
+		assertTrue("Wrong value of java.lang.Double.MIN_NORMAL",
+				Double.MIN_NORMAL == 2.2250738585072014E-308);
+	}
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java?view=diff&rev=545043&r1=545042&r2=545043
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java Wed Jun  6 20:32:37 2007
@@ -1015,4 +1015,39 @@
             s++;
         }
     }
+    
+    /**
+	 * @tests {@link java.lang.Float#MAX_EXPONENT}
+	 * @since 1.6 
+	 */
+	public void test_MAX_EXPONENT() {
+		assertTrue("Wrong value of java.lang.Float.MAX_EXPONENT",
+				Float.MAX_EXPONENT == 127);
+		assertTrue("Wrong value of java.lang.Float.MAX_EXPONENT",
+				Float.MAX_EXPONENT == Math.getExponent(Float.MAX_VALUE));
+	}
+
+	/**
+	 * @tests {@link java.lang.Float#MIN_EXPONENT}
+	 * @since 1.6
+	 */
+	public void test_MIN_EXPONENT() {
+		assertTrue("Wrong value of java.lang.Float.MIN_EXPONENT",
+				Float.MIN_EXPONENT == -126);
+		assertTrue("Wrong value of java.lang.Float.MIN_EXPONENT",
+				Float.MIN_EXPONENT == Math.getExponent(Float.MIN_NORMAL));
+	}
+
+	/**
+	 * @tests {@link java.lang.Float#MIN_NORMAL}
+	 * @since 1.6
+	 */
+	public void test_MIN_NORMAL() {
+		assertTrue("Wrong value of java.lang.Float.MIN_NORMAL",
+				Float.MIN_NORMAL == 0x1.0p-126f);
+		assertTrue("Wrong value of java.lang.Float.MIN_NORMAL",
+				Float.MIN_NORMAL == Float.intBitsToFloat(0x00800000));
+		assertTrue("Wrong value of java.lang.Float.MIN_NORMAL",
+				Float.MIN_NORMAL == 1.1754943508222875E-38f);
+	}
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java?view=diff&rev=545043&r1=545042&r2=545043
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java Wed Jun  6 20:32:37 2007
@@ -251,6 +251,95 @@
 		assertEquals("Incorrect floor for double",
                              -79, Math.floor(-78.89), 0);
 	}
+	
+	/**
+     * cases for test_getExponent_D in MathTest/StrictMathTest
+     */
+    static final double GETEXPONENT_D_CASES[] = new double[] {
+            Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY,
+            Double.MAX_VALUE, -Double.MAX_VALUE, 2.342E231, -2.342E231, 2800.0,
+            -2800.0, 5.323, -5.323, 1.323, -1.323, 0.623, -0.623, 0.323,
+            -0.323, Double.MIN_NORMAL * 24, -Double.MIN_NORMAL * 24,
+            Double.MIN_NORMAL, -Double.MIN_NORMAL, Double.MIN_NORMAL / 2,
+            -Double.MIN_NORMAL / 2, Double.MIN_VALUE, -Double.MIN_VALUE, +0.0,
+            0.0, -0.0, Double.NaN };
+
+    /**
+     * result for test_getExponent_D in MathTest/StrictMathTest
+     */
+    static final int GETEXPONENT_D_RESULTS[] = new int[] {
+            Double.MAX_EXPONENT + 1, Double.MAX_EXPONENT + 1,
+            Double.MAX_EXPONENT, Double.MAX_EXPONENT, 768, 768, 11, 11, 2, 2,
+            0, 0, -1, -1, -2, -2, -1018, -1018, Double.MIN_EXPONENT,
+            Double.MIN_EXPONENT, Double.MIN_EXPONENT - 1,
+            Double.MIN_EXPONENT - 1, Double.MIN_EXPONENT - 1,
+            Double.MIN_EXPONENT - 1, Double.MIN_EXPONENT - 1,
+            Double.MIN_EXPONENT - 1, Double.MIN_EXPONENT - 1,
+            Double.MAX_EXPONENT + 1 };
+
+    /**
+     * @tests {@link java.lang.Math#getExponent(double)}
+     * @since 1.6
+     */
+    @SuppressWarnings("boxing")
+    public void test_getExponent_D() {
+        for (int i = 0; i < GETEXPONENT_D_CASES.length; i++) {
+            final double number = GETEXPONENT_D_CASES[i];
+            final int result = GETEXPONENT_D_RESULTS[i];
+            assertEquals("Wrong result of getExponent(double).", result, Math
+                    .getExponent(number));
+        }
+
+        try {
+            Math.getExponent((Double) null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+    }
+
+    /**
+     * cases for test_getExponent_F in MathTest/StrictMathTest
+     */
+    static final float GETEXPONENT_F_CASES[] = new float[] {
+            Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.MAX_VALUE,
+            -Float.MAX_VALUE, 3.4256E23f, -3.4256E23f, 2800.0f, -2800.0f,
+            5.323f, -5.323f, 1.323f, -1.323f, 0.623f, -0.623f, 0.323f, -0.323f,
+            Float.MIN_NORMAL * 24, -Float.MIN_NORMAL * 24, Float.MIN_NORMAL,
+            -Float.MIN_NORMAL, Float.MIN_NORMAL / 2, -Float.MIN_NORMAL / 2,
+            Float.MIN_VALUE, -Float.MIN_VALUE, +0.0f, 0.0f, -0.0f, Float.NaN,1,Float.MIN_NORMAL * 1.5f };
+
+    /**
+     * result for test_getExponent_F in MathTest/StrictMathTest
+     */
+    static final int GETEXPONENT_F_RESULTS[] = new int[] {
+            Float.MAX_EXPONENT + 1, Float.MAX_EXPONENT + 1, Float.MAX_EXPONENT,
+            Float.MAX_EXPONENT, 78, 78, 11, 11, 2, 2, 0, 0, -1, -1, -2, -2,
+            -122, -122, Float.MIN_EXPONENT, Float.MIN_EXPONENT,
+            Float.MIN_EXPONENT - 1, Float.MIN_EXPONENT - 1,
+            Float.MIN_EXPONENT - 1, Float.MIN_EXPONENT - 1,
+            Float.MIN_EXPONENT - 1, Float.MIN_EXPONENT - 1,
+            Float.MIN_EXPONENT - 1, Float.MAX_EXPONENT + 1,0,Float.MIN_EXPONENT };
+    
+    /**
+     * @tests {@link java.lang.Math#getExponent(float)}
+     * @since 1.6
+     */
+    @SuppressWarnings("boxing")
+    public void test_getExponent_F() {
+        for (int i = 0; i < GETEXPONENT_F_CASES.length; i++) {
+            final float number = GETEXPONENT_F_CASES[i];
+            final int result = GETEXPONENT_F_RESULTS[i];
+            assertEquals("Wrong result of getExponent(float).", result, Math
+                    .getExponent(number));
+        }
+        try {
+            Math.getExponent((Float) null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+    }
     
     /**
      * @tests java.lang.Math#hypot(double, double)