harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r442916 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/lang/ test/java/org/apache/harmony/luni/tests/java/lang/
Date Wed, 13 Sep 2006 09:18:26 GMT
Author: pyang
Date: Wed Sep 13 02:18:25 2006
New Revision: 442916

URL: http://svn.apache.org/viewvc?view=rev&rev=442916
Log:
Patch applied for HARMONY-1449 ([classlib][luni] new methods java.lang.Math.signum(double),
java.lang.Math.signum(float),java.lang.StrictMath.signum(double), java.lang.StrictMath.signum(float))

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StrictMath.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java?view=diff&rev=442916&r1=442915&r2=442916
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java
Wed Sep 13 02:18:25 2006
@@ -474,6 +474,32 @@
 			return 0;
 		return (int) floor(f + 0.5f);
 	}
+    
+    /**
+     * Answers the signum function of the argument. If the argument is less than
+     * zero, it answers -1.0. If greater than zero, 1.0 is returned. It returns
+     * zero if the argument is also zero.
+     * 
+     * @param d
+     *            the value to compute signum function of
+     * @return the value of the signum function.
+     */
+    public static double signum(double d) {
+        return StrictMath.signum(d);
+    }
+    
+    /**
+     * Answers the signum function of the argument. If the argument is less than
+     * zero, it answers -1.0. If greater than zero, 1.0 is returned. It returns
+     * zero if the argument is also zero.
+     * 
+     * @param f
+     *            the value to compute signum function of
+     * @return the value of the signum function.
+     */
+    public static float signum(float f) {
+        return StrictMath.signum(f);
+    }
 
 	/**
 	 * Answers the closest double approximation of the sine of the argument

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StrictMath.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StrictMath.java?view=diff&rev=442916&r1=442915&r2=442916
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StrictMath.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StrictMath.java
Wed Sep 13 02:18:25 2006
@@ -478,6 +478,50 @@
 			return 0;
 		return (int) Math.floor(f + 0.5f);
 	}
+    
+    /**
+     * Answers the signum function of the argument. If the argument is less than
+     * zero, it answers -1.0. If greater than zero, 1.0 is returned. It returns
+     * zero if the argument is also zero.
+     * 
+     * @param d
+     *            the value to compute signum function of
+     * @return the value of the signum function.
+     */
+    public static double signum(double d){
+        if(Double.isNaN(d)){
+            return Double.NaN;
+        }
+        double sig = d;
+        if(d > 0){
+            sig = 1.0;
+        }else if (d < 0){
+            sig = -1.0;
+        }
+        return sig;
+    }
+    
+    /**
+     * Answers the signum function of the argument. If the argument is less than
+     * zero, it answers -1.0. If greater than zero, 1.0 is returned. It returns
+     * zero if the argument is also zero.
+     * 
+     * @param f
+     *            the value to compute signum function of
+     * @return the value of the signum function.
+     */
+    public static float signum(float f){
+        if(Float.isNaN(f)){
+            return Float.NaN;
+        }
+        float sig = f;
+        if(f > 0){
+            sig = 1.0f;
+        }else if (f < 0){
+            sig = -1.0f;
+        }
+        return sig;
+    }
 
     /**
      * Answers the closest double approximation of the hyperbolic sine of the

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java?view=diff&rev=442916&r1=442915&r2=442916
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java
Wed Sep 13 02:18:25 2006
@@ -273,11 +273,11 @@
                         Double.NEGATIVE_INFINITY), 0D);
         assertEquals("Should return POSITIVE_INFINITY",
                 Double.POSITIVE_INFINITY, Math.hypot(Double.NEGATIVE_INFINITY,
-                        Double.POSITIVE_INFINITY), 0D);
-        assertEquals("Should return NaN", Double.NaN, Math.hypot(Double.NaN,
-                2342301.89843));
-        assertEquals("Should return NaN", Double.NaN, Math.hypot(-345.2680,
-                Double.NaN));
+                        Double.POSITIVE_INFINITY), 0D);        
+        assertTrue("Should be NaN", Double.isNaN(Math.hypot(Double.NaN,
+                2342301.89843)));
+        assertTrue("Should be NaN", Double.isNaN(Math.hypot(-345.2680,
+                Double.NaN)));        
 
         assertEquals("Should return 2396424.905416697", 2396424.905416697, Math
                 .hypot(12322.12, -2396393.2258), 0D);
@@ -320,7 +320,7 @@
     public void test_log1p_D() {
         // Test for special cases
         assertTrue("Should return NaN", Double.isNaN(Math.log1p(Double.NaN)));
-        assertEquals("Should return NaN", Double.NaN, Math.log1p(-32.0482175));
+        assertTrue("Should return NaN", Double.isNaN(Math.log1p(-32.0482175)));
         assertEquals("Should return POSITIVE_INFINITY",
                 Double.POSITIVE_INFINITY, Math.log1p(Double.POSITIVE_INFINITY), 0D);
         assertEquals("Should return 0.0", 0.0, Math.log1p(0.0), 0D);
@@ -486,16 +486,67 @@
 		// Test for method int java.lang.Math.round(float)
 		assertEquals("Incorrect rounding of a float", -91, Math.round(-90.89f));
 	}
+    
+    /**
+     * @tests java.lang.Math#signum(double)
+     */
+    public void test_signum_D() {
+        assertTrue(Double.isNaN(Math.signum(Double.NaN)));
+        assertTrue(Double.isNaN(Math.signum(Double.NaN)));
+        assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
+                .signum(0.0)));
+        assertEquals(Double.doubleToLongBits(+0.0), Double
+                .doubleToLongBits(Math.signum(+0.0)));
+        assertEquals(Double.doubleToLongBits(-0.0), Double
+                .doubleToLongBits(Math.signum(-0.0)));
+
+        assertEquals(1.0, Math.signum(253681.2187962), 0D);
+        assertEquals(-1.0, Math.signum(-125874693.56), 0D);
+        assertEquals(1.0, Math.signum(1.2587E-308), 0D);
+        assertEquals(-1.0, Math.signum(-1.2587E-308), 0D);
+
+        assertEquals(1.0, Math.signum(Double.MAX_VALUE), 0D);
+        assertEquals(1.0, Math.signum(Double.MIN_VALUE), 0D);
+        assertEquals(-1.0, Math.signum(-Double.MAX_VALUE), 0D);
+        assertEquals(-1.0, Math.signum(-Double.MIN_VALUE), 0D);
+        assertEquals(1.0, Math.signum(Double.POSITIVE_INFINITY), 0D);
+        assertEquals(-1.0, Math.signum(Double.NEGATIVE_INFINITY), 0D);
+    }
+
+    /**
+     * @tests java.lang.Math#signum(float)
+     */
+    public void test_signum_F() {
+        assertTrue(Float.isNaN(Math.signum(Float.NaN)));
+        assertEquals(Float.floatToIntBits(0.0f), Float
+                .floatToIntBits(Math.signum(0.0f)));
+        assertEquals(Float.floatToIntBits(+0.0f), Float
+                .floatToIntBits(Math.signum(+0.0f)));
+        assertEquals(Float.floatToIntBits(-0.0f), Float
+                .floatToIntBits(Math.signum(-0.0f)));
+
+        assertEquals(1.0f, Math.signum(253681.2187962f), 0f);
+        assertEquals(-1.0f, Math.signum(-125874693.56f), 0f);
+        assertEquals(1.0f, Math.signum(1.2587E-11f), 0f);
+        assertEquals(-1.0f, Math.signum(-1.2587E-11f), 0f);
+
+        assertEquals(1.0f, Math.signum(Float.MAX_VALUE), 0f);
+        assertEquals(1.0f, Math.signum(Float.MIN_VALUE), 0f);
+        assertEquals(-1.0f, Math.signum(-Float.MAX_VALUE), 0f);
+        assertEquals(-1.0f, Math.signum(-Float.MIN_VALUE), 0f);
+        assertEquals(1.0f, Math.signum(Float.POSITIVE_INFINITY), 0f);
+        assertEquals(-1.0f, Math.signum(Float.NEGATIVE_INFINITY), 0f);
+    }
 
 	/**
-	 * @tests java.lang.Math#sin(double)
-	 */
+     * @tests java.lang.Math#sin(double)
+     */
 	public void test_sinD() {
 		// Test for method double java.lang.Math.sin(double)
 		assertEquals("Incorrect answer", 0.0, Math.sin(0), 0D);
 		assertEquals("Incorrect answer", 0.8414709848078965, Math.sin(1), 0D);
 	}
-
+    
     /**
      * @tests java.lang.Math#sinh(double)
      */

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java?view=diff&rev=442916&r1=442915&r2=442916
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java
Wed Sep 13 02:18:25 2006
@@ -115,8 +115,8 @@
     @SuppressWarnings("boxing")
     public void test_cbrt_D() {
         // Test for special situations
-        assertEquals("Should return Double.NaN", Double.NaN, StrictMath
-                .cbrt(Double.NaN));
+        assertTrue("Should return Double.NaN", Double.isNaN(StrictMath
+                .cbrt(Double.NaN)));
         assertEquals("Should return Double.POSITIVE_INFINITY",
                 Double.POSITIVE_INFINITY, StrictMath
                         .cbrt(Double.POSITIVE_INFINITY));
@@ -175,9 +175,9 @@
      */
     @SuppressWarnings("boxing")
     public void test_cosh_D() {
-        // Test for special situations
-        assertEquals("Should return NaN", Double.NaN, StrictMath
-                .cosh(Double.NaN));
+        // Test for special situations        
+        assertTrue("Should return NaN", Double.isNaN(StrictMath
+                .cosh(Double.NaN)));
         assertEquals("Should return POSITIVE_INFINITY",
                 Double.POSITIVE_INFINITY, StrictMath
                         .cosh(Double.POSITIVE_INFINITY));
@@ -221,8 +221,8 @@
      */
     @SuppressWarnings("boxing")
     public void test_expm1_D() {
-        //Test for special cases
-        assertEquals("Should return NaN", Double.NaN, StrictMath.expm1(Double.NaN));
+        //Test for special cases        
+        assertTrue("Should return NaN", Double.isNaN(StrictMath.expm1(Double.NaN)));
         assertEquals("Should return POSITIVE_INFINITY",
                 Double.POSITIVE_INFINITY, StrictMath.expm1(Double.POSITIVE_INFINITY));
         assertEquals("Should return -1.0", -1.0, StrictMath
@@ -329,13 +329,14 @@
      */
     @SuppressWarnings("boxing")
     public void test_log10_D() {
-        // Test for special cases
-        assertEquals("Should return NaN", Double.NaN, StrictMath
-                .log10(Double.NaN));
-        assertEquals("Should return NaN", Double.NaN, StrictMath
-                .log10(-2541.05745687234187532));
-        assertEquals("Should return NaN", Double.POSITIVE_INFINITY, StrictMath
-                .log10(Double.POSITIVE_INFINITY));
+        // Test for special cases        
+        assertTrue("Should return NaN", Double.isNaN(StrictMath
+                .log10(Double.NaN)));
+        assertTrue("Should return NaN", Double.isNaN(StrictMath
+                .log10(-2541.05745687234187532)));
+        assertEquals("Should return POSITIVE_INFINITY",
+                Double.POSITIVE_INFINITY, StrictMath
+                        .log10(Double.POSITIVE_INFINITY));
         assertEquals("Should return NEGATIVE_INFINITY",
                 Double.NEGATIVE_INFINITY, StrictMath.log10(0.0));
         assertEquals("Should return NEGATIVE_INFINITY",
@@ -363,10 +364,10 @@
     @SuppressWarnings("boxing")
     public void test_log1p_D() {
         // Test for special cases
-        assertEquals("Should return NaN", Double.NaN, StrictMath
-                .log1p(Double.NaN));
-        assertEquals("Should return NaN", Double.NaN, StrictMath
-                .log1p(-32.0482175));
+        assertTrue("Should return NaN", Double.isNaN(StrictMath
+                .log1p(Double.NaN)));
+        assertTrue("Should return NaN", Double.isNaN(StrictMath
+                .log1p(-32.0482175)));
         assertEquals("Should return POSITIVE_INFINITY",
                 Double.POSITIVE_INFINITY, StrictMath
                         .log1p(Double.POSITIVE_INFINITY));
@@ -535,10 +536,61 @@
 		assertEquals("Incorrect rounding of a float",
 				-91, StrictMath.round(-90.89f));
 	}
+    
+    /**
+     * @tests java.lang.StrictMath#signum(double)
+     */
+    public void test_signum_D() {
+        assertTrue(Double.isNaN(StrictMath.signum(Double.NaN)));
+        assertEquals(Double.doubleToLongBits(0.0), Double
+                .doubleToLongBits(StrictMath.signum(0.0)));
+        assertEquals(Double.doubleToLongBits(+0.0), Double
+                .doubleToLongBits(StrictMath.signum(+0.0)));
+        assertEquals(Double.doubleToLongBits(-0.0), Double
+                .doubleToLongBits(StrictMath.signum(-0.0)));
+
+        assertEquals(1.0, StrictMath.signum(253681.2187962), 0D);
+        assertEquals(-1.0, StrictMath.signum(-125874693.56), 0D);
+        assertEquals(1.0, StrictMath.signum(1.2587E-308), 0D);
+        assertEquals(-1.0, StrictMath.signum(-1.2587E-308), 0D);
+
+        assertEquals(1.0, StrictMath.signum(Double.MAX_VALUE), 0D);
+        assertEquals(1.0, StrictMath.signum(Double.MIN_VALUE), 0D);
+        assertEquals(-1.0, StrictMath.signum(-Double.MAX_VALUE), 0D);
+        assertEquals(-1.0, StrictMath.signum(-Double.MIN_VALUE), 0D);
+        assertEquals(1.0, StrictMath.signum(Double.POSITIVE_INFINITY), 0D);
+        assertEquals(-1.0, StrictMath.signum(Double.NEGATIVE_INFINITY), 0D);
+
+    }
+    
+    /**
+     * @tests java.lang.StrictMath#signum(float)
+     */
+    public void test_signum_F() {
+        assertTrue(Float.isNaN(StrictMath.signum(Float.NaN)));
+        assertEquals(Float.floatToIntBits(0.0f), Float
+                .floatToIntBits(StrictMath.signum(0.0f)));
+        assertEquals(Float.floatToIntBits(+0.0f), Float
+                .floatToIntBits(StrictMath.signum(+0.0f)));
+        assertEquals(Float.floatToIntBits(-0.0f), Float
+                .floatToIntBits(StrictMath.signum(-0.0f)));
+
+        assertEquals(1.0f, StrictMath.signum(253681.2187962f), 0f);
+        assertEquals(-1.0f, StrictMath.signum(-125874693.56f), 0f);
+        assertEquals(1.0f, StrictMath.signum(1.2587E-11f), 0f);
+        assertEquals(-1.0f, StrictMath.signum(-1.2587E-11f), 0f);
+
+        assertEquals(1.0f, StrictMath.signum(Float.MAX_VALUE), 0f);
+        assertEquals(1.0f, StrictMath.signum(Float.MIN_VALUE), 0f);
+        assertEquals(-1.0f, StrictMath.signum(-Float.MAX_VALUE), 0f);
+        assertEquals(-1.0f, StrictMath.signum(-Float.MIN_VALUE), 0f);
+        assertEquals(1.0f, StrictMath.signum(Float.POSITIVE_INFINITY), 0f);
+        assertEquals(-1.0f, StrictMath.signum(Float.NEGATIVE_INFINITY), 0f);
+    }
 
 	/**
-	 * @tests java.lang.StrictMath#sin(double)
-	 */
+     * @tests java.lang.StrictMath#sin(double)
+     */
 	public void test_sinD() {
 		// Test for method double java.lang.StrictMath.sin(double)
 		assertTrue("Returned incorrect sine", StrictMath.sin(StrictMath



Mime
View raw message