harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r620463 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java
Date Mon, 11 Feb 2008 11:19:11 GMT
Author: apetrenko
Date: Mon Feb 11 03:19:01 2008
New Revision: 620463

URL: http://svn.apache.org/viewvc?rev=620463&view=rev
Log:
Patch for HARMONY-5478 "[classlib] [luni] Math.floor/ceil/rint can be 
implemented w/o JNI calls"

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java?rev=620463&r1=620462&r2=620463&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Math.java Mon Feb
11 03:19:01 2008
@@ -150,7 +150,9 @@
 	 *            the value to be converted
 	 * @return the ceiling of the argument.
 	 */
-	public static native double ceil(double d);
+	public static double ceil(double d) {
+            return -floor(-d);
+        } 
 
 	/**
 	 * Answers the closest double approximation of the cosine of the argument
@@ -204,7 +206,13 @@
 	 *            the value to be converted
 	 * @return the ceiling of the argument.
 	 */
-	public static native double floor(double d);
+	public static double floor(double d) {
+            if (Double.isNaN(d) || Double.isInfinite(d) || d == 0) {
+               return d; 
+            }  
+            double res = (double)(long)d;
+            return d > 0 || res == d ? res : res - 1; 
+        }
     
     /**
      * Answers sqrt(<i>x</i><sup>2</sup>+<i>y</i><sup>2</sup>).
The
@@ -287,8 +295,7 @@
 		if (d1 != d2)
 			return Double.NaN;
 		/* max( +0.0,-0.0) == +0.0 */
-		if (d1 == 0.0
-				&& ((Double.doubleToLongBits(d1) & Double.doubleToLongBits(d2)) & 0x8000000000000000L)
== 0)
+		if (d1 == 0.0 && (d1 != -0.0d || d2 != -0.0d))
 			return 0.0;
 		return d1;
 	}
@@ -312,8 +319,7 @@
 		if (f1 != f2)
 			return Float.NaN;
 		/* max( +0.0,-0.0) == +0.0 */
-		if (f1 == 0.0f
-				&& ((Float.floatToIntBits(f1) & Float.floatToIntBits(f2)) & 0x80000000)
== 0)
+		if (f1 == 0.0f && (f1 != -0.0f || f2 != -0.0f))
 			return 0.0f;
 		return f1;
 	}
@@ -365,9 +371,8 @@
 		if (d1 != d2)
 			return Double.NaN;
 		/* min( +0.0,-0.0) == -0.0 */
-		if (d1 == 0.0
-				&& ((Double.doubleToLongBits(d1) | Double.doubleToLongBits(d2)) & 0x8000000000000000l)
!= 0)
-			return 0.0 * (-1.0);
+		if (d1 == 0.0 && (d1 == -0.0d || d2 == -0.0d))
+			return -0.0d;
 		return d1;
 	}
 
@@ -390,9 +395,8 @@
 		if (f1 != f2)
 			return Float.NaN;
 		/* min( +0.0,-0.0) == -0.0 */
-		if (f1 == 0.0f
-				&& ((Float.floatToIntBits(f1) | Float.floatToIntBits(f2)) & 0x80000000) !=
0)
-			return 0.0f * (-1.0f);
+		if (f1 == 0.0f	&& (f1 == -0.0f || f2 == -0.0f)) 
+			return -0.0f;
 		return f1;
 	}
 
@@ -444,7 +448,10 @@
 	 *            the value to be converted
 	 * @return the closest integer to the argument (as a double).
 	 */
-	public static native double rint(double d);
+	public static double rint(double d) {
+            double res = floor(d + 0.5d);
+            return res - d == 0.5d && d > 0 ? res - 1 : res;  
+        }
 
 	/**
 	 * Answers the result of rounding the argument to an integer.



Mime
View raw message