incubator-hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edwardy...@apache.org
Subject svn commit: r696962 - in /incubator/hama/trunk: CHANGES.txt src/java/org/apache/hama/util/Numeric.java src/test/org/apache/hama/TestDenseMatrix.java
Date Fri, 19 Sep 2008 07:34:23 GMT
Author: edwardyoon
Date: Fri Sep 19 00:34:23 2008
New Revision: 696962

URL: http://svn.apache.org/viewvc?rev=696962&view=rev
Log: (empty)

Modified:
    incubator/hama/trunk/CHANGES.txt
    incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java
    incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java

Modified: incubator/hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=696962&r1=696961&r2=696962&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Fri Sep 19 00:34:23 2008
@@ -52,6 +52,7 @@
 
   BUG FIXES
 
+    HAMA-64: Bytes and Double convert (edwardyoon)
     HAMA-55: Write dimension attributes when job completed (edwardyoon)
     HAMA-54: Split doesn't split by map task num (edwardyoon)
     HAMA-53: NullPointerException on distributed cluster (edwardyoon)

Modified: incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java?rev=696962&r1=696961&r2=696962&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/util/Numeric.java Fri Sep 19 00:34:23 2008
@@ -26,7 +26,8 @@
  * Provides a number format conversion
  */
 public class Numeric {
-  
+  private static long BITMASK = 0xFF;
+
   /**
    * Bytes to integer conversion
    * 
@@ -54,7 +55,10 @@
    * @return the converted value
    */
   public static double bytesToDouble(byte[] bytes) {
-    return Double.parseDouble(Bytes.toString(bytes));
+    long value = 0;
+    for (int i = 0; i < 8; i++)
+      value = ((((long)(bytes[i])) & 0xFF) << (56 - i * 8)) | value;
+    return Double.longBitsToDouble(value);
   }
 
   /**
@@ -64,7 +68,17 @@
    * @return the converted value
    */
   public static byte[] doubleToBytes(Double doubleValue) {
-    return Bytes.toBytes(doubleValue.toString());
+    byte[] buf = new byte[8];
+    long longVal = Double.doubleToLongBits(doubleValue);
+    buf[0] = (Long.valueOf((longVal & (BITMASK << 56)) >>> 56)).byteValue();
+    buf[1] = (Long.valueOf((longVal & (BITMASK << 48)) >>> 48)).byteValue();
+    buf[2] = (Long.valueOf((longVal & (BITMASK << 40)) >>> 40)).byteValue();
+    buf[3] = (Long.valueOf((longVal & (BITMASK << 32)) >>> 32)).byteValue();
+    buf[4] = (Long.valueOf((longVal & (long)0x00000000FF000000) >>> 24)).byteValue();
+    buf[5] = (Long.valueOf((longVal & (long)0x0000000000FF0000) >>> 16)).byteValue();
+    buf[6] = (Long.valueOf((longVal & (long)0x000000000000FF00) >>>  8)).byteValue();
+    buf[7] = (Long.valueOf((longVal & (long)0x00000000000000FF))).byteValue();
+    return buf;
   }
 
   /**

Modified: incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java?rev=696962&r1=696961&r2=696962&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java Fri Sep 19 00:34:23
2008
@@ -177,8 +177,8 @@
 
     for (int i = 0; i < SIZE; i++) {
       for (int j = 0; j < SIZE; j++) {
-        assertEquals(String.valueOf(result.get(i, j)).substring(0, 14), String
-            .valueOf(C[i][j]).substring(0, 14));
+        assertEquals(String.valueOf(result.get(i, j)).substring(0, 14), 
+            String.valueOf(C[i][j]).substring(0, 14));
       }
     }
   }



Mime
View raw message