harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r474549 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/lang/ test/java/org/apache/harmony/luni/tests/java/lang/
Date Mon, 13 Nov 2006 22:52:23 GMT
Author: tellison
Date: Mon Nov 13 14:52:22 2006
New Revision: 474549

URL: http://svn.apache.org/viewvc?view=rev&rev=474549
Log:
Applied patch HARMONY-2123 ([classlib][luni] Double.toHexString misses significant zeros)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Double.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Float.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Double.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Double.java?view=diff&rev=474549&r1=474548&r2=474549
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Double.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Double.java
Mon Nov 13 14:52:22 2006
@@ -477,7 +477,7 @@
             String hexSignificand = Long.toHexString(significand);
 
             // if there are digits left, then insert some '0' chars first
-            if (fractionDigits > hexSignificand.length()) {
+            if (significand != 0 && fractionDigits > hexSignificand.length())
{
                 int digitDiff = fractionDigits - hexSignificand.length();
                 while (digitDiff-- != 0) {
                     hexString.append('0');
@@ -487,13 +487,24 @@
             hexString.append("p-1022");
         } else { // normal value
             hexString.append("1.");
+            // significand is 52-bits, so there can be 13 hex digits
+            int fractionDigits = 13;
             // remove trailing hex zeros, so Integer.toHexString() won't print
             // them
             while ((significand != 0) && ((significand & 0xF) == 0)) {
                 significand >>>= 4;
+                fractionDigits--;
             }
             // this assumes Integer.toHexString() returns lowercase characters
             String hexSignificand = Long.toHexString(significand);
+            
+            // if there are digits left, then insert some '0' chars first
+            if (significand != 0 && fractionDigits > hexSignificand.length())
{
+                int digitDiff = fractionDigits - hexSignificand.length();
+                while (digitDiff-- != 0) {
+                    hexString.append('0');
+                }
+            }
 
             hexString.append(hexSignificand);
             hexString.append('p');

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Float.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Float.java?view=diff&rev=474549&r1=474548&r2=474549
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Float.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Float.java
Mon Nov 13 14:52:22 2006
@@ -456,7 +456,7 @@
         }
 
         int bitValue = floatToIntBits(f);
-
+        
         boolean negative = (bitValue & 0x80000000) != 0;
         // mask exponent bits and shift down
         int exponent = (bitValue & 0x7f800000) >>> 23;
@@ -489,7 +489,7 @@
             String hexSignificand = Integer.toHexString(significand);
 
             // if there are digits left, then insert some '0' chars first
-            if (fractionDigits > hexSignificand.length()) {
+            if (significand != 0 && fractionDigits > hexSignificand.length())
{
                 int digitDiff = fractionDigits - hexSignificand.length();
                 while (digitDiff-- != 0) {
                     hexString.append('0');
@@ -499,14 +499,24 @@
             hexString.append("p-126");
         } else { // normal value
             hexString.append("1.");
+            // significand is 23-bits, so there can be 6 hex digits
+            int fractionDigits = 6;
             // remove trailing hex zeros, so Integer.toHexString() won't print
             // them
             while ((significand != 0) && ((significand & 0xF) == 0)) {
                 significand >>>= 4;
+                fractionDigits--;
             }
             // this assumes Integer.toHexString() returns lowercase characters
             String hexSignificand = Integer.toHexString(significand);
 
+            // if there are digits left, then insert some '0' chars first
+            if (significand != 0 && fractionDigits > hexSignificand.length())
{
+                int digitDiff = fractionDigits - hexSignificand.length();
+                while (digitDiff-- != 0) {
+                    hexString.append('0');
+                }
+            }
             hexString.append(hexSignificand);
             hexString.append('p');
             // remove exponent's 'bias' and convert to a string

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java?view=diff&rev=474549&r1=474548&r2=474549
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java
Mon Nov 13 14:52:22 2006
@@ -1383,6 +1383,9 @@
         assertEquals("0x1.2957874cccccdp23", Double.toHexString(9743299.65000D));
         assertEquals("0x1.2957874cccf63p23", Double.toHexString(9743299.650001234D));
         assertEquals("0x1.700d1061d3333p33", Double.toHexString(12349743299.65000D));
+        
+        // test HARMONY-2132
+        assertEquals("0x1.01p10", Double.toHexString(0x1.01p10));
     }
 
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java?view=diff&rev=474549&r1=474548&r2=474549
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java
Mon Nov 13 14:52:22 2006
@@ -994,6 +994,9 @@
         assertEquals("0x1.295788p23", Float.toHexString(9743299.65000F));
         assertEquals("0x1.295788p23", Float.toHexString(9743299.650001234F));
         assertEquals("0x1.700d1p33", Float.toHexString(12349743299.65000F));
+        
+        // test HARMONY-2132
+        assertEquals("0x1.01p10", Float.toHexString(0x1.01p10f));
     }
 
     /**



Mime
View raw message