harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r451108 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/org/apache/harmony/luni/util/FloatingPointParser.java test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java
Date Fri, 29 Sep 2006 03:52:13 GMT
Author: pyang
Date: Thu Sep 28 20:52:11 2006
New Revision: 451108

URL: http://svn.apache.org/viewvc?view=rev&rev=451108
Log:
Apply fifth patch for HARMONY-747(java.lang.Doulbe.parseDouble(String) does not support Hex
number)

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java?view=diff&rev=451108&r1=451107&r2=451108
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
Thu Sep 28 20:52:11 2006
@@ -325,6 +325,8 @@
     private static final int FLOAT_MANTISSA_WIDTH = 23;
     
     private static final int HEX_RADIX = 16;
+    
+    private static final int MAX_SIGNIFICANT_LENGTH = 15;
 
     private static final String HEX_SIGNIFICANT = "0[xX](\\p{XDigit}+\\.?|\\p{XDigit}*\\.\\p{XDigit}+)";
//$NON-NLS-1$
 
@@ -344,12 +346,18 @@
     private final long EXPONENT_BASE;
     
     private final long MAX_EXPONENT;
+    
+    private final long MIN_EXPONENT;
+    
+    private final long MANTISSA_MASK;
 
     private long sign;
 
     private long exponent;
 
     private long mantissa;
+    
+    private String abandonedNumber=""; //$NON-NLS-1$
 
     public HexStringParser(int exponent_width, int mantissa_width) {
         this.EXPONENT_WIDTH = exponent_width;
@@ -357,6 +365,8 @@
         
         this.EXPONENT_BASE = ~(-1L << (exponent_width - 1));
         this.MAX_EXPONENT = ~(-1L << exponent_width);
+        this.MIN_EXPONENT = -(MANTISSA_WIDTH + 1);
+        this.MANTISSA_MASK = ~(-1L << mantissa_width);
     }
 
     /*
@@ -411,47 +421,73 @@
         return hexSegments;
     }
 
-    // Parses the sign field
+    /*
+     * Parses the sign field.
+     */
     private void parseHexSign(String signStr) {
         this.sign = signStr.equals("-") ? 1 : 0; //$NON-NLS-1$
     }
 
-    // Parses the exponent field
+    /*
+     * Parses the exponent field.
+     */
     private void parseExponent(String exponentStr) {
         char leadingChar = exponentStr.charAt(0);
-        int sign = (leadingChar == '-' ? -1 : 1);
+        int expSign = (leadingChar == '-' ? -1 : 1);
         if (!Character.isDigit(leadingChar)) {
             exponentStr = exponentStr.substring(1);
         }
 
         try {
-            exponent = sign * Long.parseLong(exponentStr) + EXPONENT_BASE;
+            exponent = expSign * Long.parseLong(exponentStr);
+            checkedAddExponent(EXPONENT_BASE);
         } catch (NumberFormatException e) {
-            exponent = sign * Long.MAX_VALUE;
+            exponent = expSign * Long.MAX_VALUE;
         }
     }
    
-    // Parses the mantissa field
+    /*
+     * Parses the mantissa field.
+     */
     private void parseMantissa(String significantStr) {
         String[] strings = significantStr.split("\\."); //$NON-NLS-1$
         String strIntegerPart = strings[0];
         String strDecimalPart = strings.length > 1 ? strings[1] : ""; //$NON-NLS-1$
 
-        String significand = getNormalizedSignificand(strIntegerPart, strDecimalPart);
-        if(significand.equals("0")){ //$NON-NLS-1$
+        String significand = getNormalizedSignificand(strIntegerPart,strDecimalPart);
+        if (significand.equals("0")) { //$NON-NLS-1$
             setZero();
             return;
         }
-        
+
         int offset = getOffset(strIntegerPart, strDecimalPart);
-        boolean isOverFlow = checkedAddExponent(offset);
-        if (isOverFlow) {
+        checkedAddExponent(offset);
+        
+        if (exponent >= MAX_EXPONENT) {
+            setInfinite();
+            return;
+        }
+        
+        if (exponent <= MIN_EXPONENT) {
+            setZero();
             return;
         }
 
-        // TODO
-    }
+        if (significand.length() > MAX_SIGNIFICANT_LENGTH) {
+            abandonedNumber = significand.substring(MAX_SIGNIFICANT_LENGTH);
+            significand = significand.substring(0, MAX_SIGNIFICANT_LENGTH);
+        }
 
+        mantissa = Long.parseLong(significand, HEX_RADIX);
+
+        if (exponent >= 1) {
+            processNormalNumber();
+        } else{
+            processSubNormalNumber();
+        }
+
+    }
+    
     private void setInfinite() {
         exponent = MAX_EXPONENT;
         mantissa = 0;
@@ -461,21 +497,81 @@
         exponent = 0;
         mantissa = 0;
     }
-
-    private boolean checkedAddExponent(long offset) {
-        double d = exponent;
-        boolean isOverFlow = false;
-        d += offset;
-        if (d >= Long.MAX_VALUE) {
-            setInfinite();
-            isOverFlow = true;
-        } else if (d <= -Long.MAX_VALUE) {
-            setZero();
-            isOverFlow = true;
+    
+    /*
+     * Sets the exponent variable to Long.MAX_VALUE or -Long.MAX_VALUE if
+     * overflow or underflow happens.
+     */
+    private void checkedAddExponent(long offset) {
+        long result = exponent + offset;
+        int expSign = Long.signum(exponent);
+        if (expSign * Long.signum(offset) > 0 && expSign * Long.signum(result)
< 0) {
+            exponent = expSign * Long.MAX_VALUE;
+        } else {
+            exponent = result;
+        }
+    }
+    
+    private void processNormalNumber(){
+        int desiredWidth = MANTISSA_WIDTH + 2;
+        fitMantissaInDesiredWidth(desiredWidth);
+        round();
+        mantissa = mantissa & MANTISSA_MASK;
+    }
+    
+    private void processSubNormalNumber(){
+        int desiredWidth = MANTISSA_WIDTH + 1;
+        desiredWidth += (int)exponent;//lends bit from mantissa to exponent
+        exponent = 0;
+        fitMantissaInDesiredWidth(desiredWidth);
+        round();
+        mantissa = mantissa & MANTISSA_MASK;
+    }
+    
+    /*
+     * Adjusts the mantissa to desired width for further analysis.
+     */
+    private void fitMantissaInDesiredWidth(int desiredWidth){
+        int bitLength = countBitsLength(mantissa);
+        if (bitLength > desiredWidth) {
+            discardTrailingBits(bitLength - desiredWidth);
         } else {
-            exponent += offset;
+            mantissa <<= (desiredWidth - bitLength);
+        }
+    }
+    
+    /*
+     * Stores the discarded bits to abandonedNumber.
+     */
+    private void discardTrailingBits(long num) {
+        long mask = ~(-1L << num);
+        abandonedNumber += (mantissa & mask);
+        mantissa >>= num;
+    }
+
+    /*
+     * The value is rounded up or down to the nearest infinitely precise result.
+     * If the value is exactly halfway between two infinitely precise results,
+     * then it should be rounded up to the nearest infinitely precise even.
+     */
+    private void round() {
+        String result = abandonedNumber.replaceAll("0+", ""); //$NON-NLS-1$ //$NON-NLS-2$
+        boolean moreThanZero = (result.length() > 0 ? true : false);
+
+        int lastDiscardedBit = (int) (mantissa & 1L);
+        mantissa >>= 1;
+        int tailBitInMantissa = (int) (mantissa & 1L);
+        
+        if (lastDiscardedBit == 1 && (moreThanZero || tailBitInMantissa == 1)) {
+            int oldLength = countBitsLength(mantissa);
+            mantissa += 1L;
+            int newLength = countBitsLength(mantissa);
+            
+            //Rounds up to exponent when whole bits of mantissa are one-bits.
+            if (oldLength >= MANTISSA_WIDTH && newLength > oldLength) {
+                checkedAddExponent(1);
+            }
         }
-        return isOverFlow;
     }
 
     /*

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=451108&r1=451107&r2=451108
==============================================================================
--- 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
Thu Sep 28 20:52:11 2006
@@ -557,7 +557,7 @@
     /**
      * @tests java.lang.Double#parseDouble(java.lang.String)
      */
-    public void test_parseDouble_LString_Hexadecimal() {
+    public void test_parseDouble_LString_Illegal() {
         try {
             Double.parseDouble("0.0p0D");
             fail("Should throw NumberFormatException.");
@@ -620,6 +620,515 @@
         } catch (NumberFormatException e) {
             // expected
         }
+    }
+    
+    /**
+     * @tests java.lang.Double#parseDouble(java.lang.String)
+     */
+    public void test_parseDouble_LString_FromHexString() {
+        double actual;
+        double expected;
+
+        actual = Double.parseDouble("0x0.0p0D");
+        assertEquals("Returned incorrect value", 0.0d, actual);
+
+        actual = Double.parseDouble("0xa.ap+9d");
+        assertEquals("Returned incorrect value", 5440.0d, actual);
+
+        actual = Double.parseDouble("+0Xb.10ap8");
+        assertEquals("Returned incorrect value", 2832.625d, actual);
+
+        actual = Double.parseDouble("-0X.a0P2D");
+        assertEquals("Returned incorrect value", -2.5d, actual);
+
+        actual = Double.parseDouble("\r 0x22.1p2d \t");
+        assertEquals("Returned incorrect value", 136.25d, actual);
+
+        actual = Double.parseDouble("0x1.0p-1");
+        assertEquals("Returned incorrect value", 0.5, actual);
+
+        actual = Double
+                .parseDouble("0x00000000000000000000000000000000001.0p-1");
+        assertEquals("Returned incorrect value", 0.5, actual);
+
+         actual = Double.parseDouble("0x1.0p-00000000000000000000000000001");
+         assertEquals("Returned incorrect value", 0.5, actual);
+
+        actual = Double.parseDouble("0x.100000000000000000000000000000000p1");
+        assertEquals("Returned incorrect value", 0.125, actual);
+
+        actual = Double.parseDouble("0x0.0p999999999999999999999999999999999999999999999999999999999999999");
+        assertEquals("Returned incorrect value", 0.0, actual);
+        
+        actual = Double.parseDouble("0xf1.0p9999999999999999999999999999999999999999999999999999999999999999");
+        assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, actual);
+
+        actual = Double.parseDouble("0xffffffffffffffffffffffffffffffffffff.ffffffffffffffffffffffffffffffffffffffffffffffp1");
+        expected = Double.longBitsToDouble(0x4900000000000000L);
+        assertEquals("Returned incorrect value", expected, actual);
+        
+        actual = Double.parseDouble("0x0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001p1600");
+        expected = Double.longBitsToDouble(0x7f30000000000000L);
+        assertEquals("Returned incorrect value", expected, actual);
+        
+        actual = Double.parseDouble("0x0.0p-999999999999999999999999999999999999999999999999999999");
+        assertEquals("Returned incorrect value", 0.0, actual);
+        
+        actual = Double.parseDouble("0xf1.0p-9999999999999999999999999999999999999999999999999999999999999999");
+        assertEquals("Returned incorrect value", 0.0, actual);
+        
+        actual = Double.parseDouble("0x10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000p-1600");
+        expected = Double.longBitsToDouble(0xf0000000000000L);
+        assertEquals("Returned incorrect value", expected, actual);
+        
+        actual = Double.parseDouble("0x1.p9223372036854775807");
+        assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, actual);
+        
+        actual = Double.parseDouble("0x1.p9223372036854775808");
+        assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, actual);
+        
+        actual = Double.parseDouble("0x10.p9223372036854775808");
+        assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, actual);
+        
+        actual = Double.parseDouble("0xabcd.ffffffffp+2000");
+        assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, actual);
+        
+        actual = Double.parseDouble("0x1.p-9223372036854775808");
+        assertEquals("Returned incorrect value", 0.0, actual);
+        
+        actual = Double.parseDouble("0x1.p-9223372036854775809");
+        assertEquals("Returned incorrect value", 0.0, actual);
+        
+        actual = Double.parseDouble("0x.1p-9223372036854775809");
+        assertEquals("Returned incorrect value", 0.0, actual);
+        
+        actual = Double.parseDouble("0xabcd.ffffffffffffffp-2000");
+        assertEquals("Returned incorrect value", 0.0, actual);
+    }
+    
+    /**
+     * @tests java.lang.Double#parseDouble(java.lang.String)
+     */
+    public void test_parseDouble_LString_NormalPositiveExponent() {
+        long[] expecteds = {
+                0x3f323456789abcdfL,                0x40e111012345678aL,                0x41a1110091a2b3c5L,
+                0x4259998091a2b3c5L,                0x4311110048d159e2L,                0x43c5554048d159e2L,
+                0x4479998048d159e2L,                0x452dddc048d159e2L,                0x45e111002468acf1L,
+                0x469333202468acf1L,                0x4751011001234568L,                0x4802112101234568L,
+                0x48b3213201234568L,                0x4964314301234568L,                0x4a15415401234568L,
+                0x4ac6516501234568L,                0x4b77617601234568L,                0x4c28718701234568L,
+                0x4cd9819801234568L,                0x4d9049048091a2b4L,                0x4e4101100091a2b4L,
+                0x4ef189188091a2b4L,                0x4fa211210091a2b4L,                0x505299298091a2b4L,
+                0x510321320091a2b4L,                0x51b3a93a8091a2b4L,                0x526431430091a2b4L,
+                0x5314b94b8091a2b4L,                0x53c841840091a2b4L,                0x5478c98c8091a2b4L,
+                0x552981980091a2b4L,                0x55da09a08091a2b4L,                0x568a91a90091a2b4L,
+                0x573b19b18091a2b4L,                0x57eba1ba0091a2b4L,                0x589c29c28091a2b4L,
+                0x594cb1cb0091a2b4L,                0x5a001d01c048d15aL,                0x5ab061060048d15aL,
+                0x5b60a50a4048d15aL,                0x5c1101100048d15aL,                0x5cc145144048d15aL,
+                0x5d7189188048d15aL,                0x5e21cd1cc048d15aL,                0x5ed211210048d15aL,
+                0x5f8255254048d15aL,                0x603419418048d15aL,                0x60e45d45c048d15aL,
+                0x6194a14a0048d15aL,                0x6244e54e4048d15aL,                0x62f541540048d15aL,
+                0x63a585584048d15aL,                0x6455c95c8048d15aL,                0x65060d60c048d15aL,
+                0x65b651650048d15aL,                0x666815814048d15aL,                0x671859858048d15aL,
+                0x67c89d89c048d15aL,                0x6878e18e0048d15aL,                0x692925924048d15aL,
+                0x69d981980048d15aL,                0x6a89c59c4048d15aL,                0x6b3a09a08048d15aL,
+                0x6bea4da4c048d15aL,                0x6c9c11c10048d15aL,                0x6d4c55c54048d15aL,
+                0x6dfc99c98048d15aL,                0x6eacddcdc048d15aL,                0x6f5d21d20048d15aL,
+                0x700d65d64048d15aL,                0x70bdc1dc0048d15aL,                0x716e05e04048d15aL,
+                0x721e49e48048d15aL,                0x72d00700602468adL,                0x73802902802468adL,
+                0x74304b04a02468adL,                0x74e06d06c02468adL,                0x75908f08e02468adL,
+                0x7640b10b002468adL,                0x76f0d30d202468adL,                0x77a10110002468adL,
+                0x78512312202468adL,                0x79020520402468adL,                0x79b22722602468adL,
+                0x7a624924802468adL,                0x7b126b26a02468adL,                0x7bc28d28c02468adL,
+                0x7c72af2ae02468adL,                0x7d22d12d002468adL,                0x7dd2f32f202468adL,
+                0x7e832132002468adL,                0x7f40011001012345L,                0x7ff0000000000000L,
+                0x7ff0000000000000L,                0x7ff0000000000000L,                0x7ff0000000000000L,
+                0x7ff0000000000000L,                0x7ff0000000000000L,                0x7ff0000000000000L,
+                0x7ff0000000000000L,                0x7ff0000000000000L,                0x7ff0000000000000L,
+                0x7ff0000000000000L,                0x7ff0000000000000L,                0x7ff0000000000000L,
+                0x7ff0000000000000L,                0x7ff0000000000000L,                0x7ff0000000000000L,
+                0x7ff0000000000000L,                0x7ff0000000000000L,                0x7ff0000000000000L,
+                0x7ff0000000000000L,                0x7ff0000000000000L  };
+
+        for (int i = 0; i < expecteds.length; i++) {
+            int part = i*11;
+            String inputString = "0x" + part + "." + part + "0123456789abcdefp" + part;
+            
+            double actual = Double.parseDouble(inputString);
+            double expected = Double.longBitsToDouble(expecteds[i]);
+            
+            String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
+            String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
+            String errorMsg = i + "th input string is:<" + inputString
+                    + ">.The expected result should be:<" + expectedString
+                    + ">, but was: <" + actualString + ">. ";
+            
+            assertEquals(errorMsg, expected, actual);
+        }
+    }
+    
+    /**
+     * @tests java.lang.Double#parseDouble(java.lang.String)
+     */
+    public void test_parseDouble_LString_NormalNegativeExponent() {
+        long[] expecteds = {
+                0x3f323456789abcdfL,                0x3f8111012345678aL,                0x3ee1110091a2b3c5L,
+                0x3e39998091a2b3c5L,                0x3d91110048d159e2L,                0x3ce5554048d159e2L,
+                0x3c39998048d159e2L,                0x3b8dddc048d159e2L,                0x3ae111002468acf1L,
+                0x3a3333202468acf1L,                0x3991011001234568L,                0x38e2112101234568L,
+                0x3833213201234568L,                0x3784314301234568L,                0x36d5415401234568L,
+                0x3626516501234568L,                0x3577617601234568L,                0x34c8718701234568L,
+                0x3419819801234568L,                0x337049048091a2b4L,                0x32c101100091a2b4L,
+                0x321189188091a2b4L,                0x316211210091a2b4L,                0x30b299298091a2b4L,
+                0x300321320091a2b4L,                0x2f53a93a8091a2b4L,                0x2ea431430091a2b4L,
+                0x2df4b94b8091a2b4L,                0x2d4841840091a2b4L,                0x2c98c98c8091a2b4L,
+                0x2be981980091a2b4L,                0x2b3a09a08091a2b4L,                0x2a8a91a90091a2b4L,
+                0x29db19b18091a2b4L,                0x292ba1ba0091a2b4L,                0x287c29c28091a2b4L,
+                0x27ccb1cb0091a2b4L,                0x27201d01c048d15aL,                0x267061060048d15aL,
+                0x25c0a50a4048d15aL,                0x251101100048d15aL,                0x246145144048d15aL,
+                0x23b189188048d15aL,                0x2301cd1cc048d15aL,                0x225211210048d15aL,
+                0x21a255254048d15aL,                0x20f419418048d15aL,                0x20445d45c048d15aL,
+                0x1f94a14a0048d15aL,                0x1ee4e54e4048d15aL,                0x1e3541540048d15aL,
+                0x1d8585584048d15aL,                0x1cd5c95c8048d15aL,                0x1c260d60c048d15aL,
+                0x1b7651650048d15aL,                0x1ac815814048d15aL,                0x1a1859858048d15aL,
+                0x19689d89c048d15aL,                0x18b8e18e0048d15aL,                0x180925924048d15aL,
+                0x175981980048d15aL,                0x16a9c59c4048d15aL,                0x15fa09a08048d15aL,
+                0x154a4da4c048d15aL,                0x149c11c10048d15aL,                0x13ec55c54048d15aL,
+                0x133c99c98048d15aL,                0x128cddcdc048d15aL,                0x11dd21d20048d15aL,
+                0x112d65d64048d15aL,                0x107dc1dc0048d15aL,                0xfce05e04048d15aL,
+                0xf1e49e48048d15aL,                0xe700700602468adL,                0xdc02902802468adL,
+                0xd104b04a02468adL,                0xc606d06c02468adL,                0xbb08f08e02468adL,
+                0xb00b10b002468adL,                0xa50d30d202468adL,                0x9a10110002468adL,
+                0x8f12312202468adL,                0x8420520402468adL,                0x7922722602468adL,
+                0x6e24924802468adL,                0x6326b26a02468adL,                0x5828d28c02468adL,
+                0x4d2af2ae02468adL,                0x422d12d002468adL,                0x372f32f202468adL,
+                0x2c32132002468adL,                0x220011001012345L,                0x170121012012345L,
+                0xc0231023012345L,                0x10341034012345L,                0x208a208a024L,
+                0x41584158L,                            0x83388L,                       
        0x108L,
+                0x0L,                                        0x0L,                      
                0x0L,
+                0x0L,                                        0x0L,                      
                0x0L,
+                0x0L,                                        0x0L,                      
                0x0L,
+                0x0L,                                        0x0L,                      
                0x0L,
+                0x0L,                                        0x0L };
+
+        for (int i = 0; i < expecteds.length; i++) {
+            int part = i*11;
+            String inputString = "0x" + part + "." + part + "0123456789abcdefp-" + part;
+            
+            double actual = Double.parseDouble(inputString);
+            double expected = Double.longBitsToDouble(expecteds[i]);
+            
+            String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
+            String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
+            String errorMsg = i + "th input string is:<" + inputString
+                    + ">.The expected result should be:<" + expectedString
+                    + ">, but was: <" + actualString + ">. ";
+            
+            assertEquals(errorMsg, expected, actual);
+        }
+    }
+    
+    /**
+     * @tests java.lang.Double#parseDouble(java.lang.String)
+     */
+    public void test_parseDouble_LString_MaxNormalBoundary() {
+       long[] expecteds = {
+               0x7fefffffffffffffL,               0x7fefffffffffffffL,               0x7fefffffffffffffL,
+               0x7fefffffffffffffL,               0x7fefffffffffffffL,               0x7fefffffffffffffL,
+               0x7fefffffffffffffL,               0x7ff0000000000000L,               0x7ff0000000000000L,
+               0x7ff0000000000000L,               0x7ff0000000000000L,               0x7ff0000000000000L,
+               0x7ff0000000000000L,               0x7ff0000000000000L,               0x7ff0000000000000L,
+               
+               0xffefffffffffffffL,               0xffefffffffffffffL,               0xffefffffffffffffL,
+               0xffefffffffffffffL,               0xffefffffffffffffL,               0xffefffffffffffffL,
+               0xffefffffffffffffL,               0xfff0000000000000L,               0xfff0000000000000L,
+               0xfff0000000000000L,               0xfff0000000000000L,               0xfff0000000000000L,
+               0xfff0000000000000L,               0xfff0000000000000L,               0xfff0000000000000L
};
+       
+       String[] inputs = {
+               "0x1.fffffffffffffp1023",
+               "0x1.fffffffffffff000000000000000000000000001p1023",
+               "0x1.fffffffffffff1p1023",
+               "0x1.fffffffffffff100000000000000000000000001p1023",
+               "0x1.fffffffffffff1fffffffffffffffffffffffffffffffffffffffffffffp1023",
+               "0x1.fffffffffffff7p1023",
+               "0x1.fffffffffffff700000000000000000000000001p1023",
+               "0x1.fffffffffffff8p1023",
+               "0x1.fffffffffffff800000000000000000000000001p1023",
+               "0x1.fffffffffffff8fffffffffffffffffffffffffffffffffffffffffffffp1023",
+               "0x1.fffffffffffff9p1023",
+               "0x1.fffffffffffff900000000000000000000000001p1023",
+               "0x1.ffffffffffffffp1023",
+               "0x1.ffffffffffffff00000000000000000000000001p1023",
+               "0x1.fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp1023",
+
+               "-0x1.fffffffffffffp1023",
+               "-0x1.fffffffffffff000000000000000000000000001p1023",
+               "-0x1.fffffffffffff1p1023",
+               "-0x1.fffffffffffff100000000000000000000000001p1023",
+               "-0x1.fffffffffffff1fffffffffffffffffffffffffffffffffffffffffffffp1023",
+               "-0x1.fffffffffffff7p1023",
+               "-0x1.fffffffffffff700000000000000000000000001p1023",
+               "-0x1.fffffffffffff8p1023",
+               "-0x1.fffffffffffff800000000000000000000000001p1023",
+               "-0x1.fffffffffffff8fffffffffffffffffffffffffffffffffffffffffffffp1023",
+               "-0x1.fffffffffffff9p1023",
+               "-0x1.fffffffffffff900000000000000000000000001p1023",
+               "-0x1.ffffffffffffffp1023",
+               "-0x1.ffffffffffffff00000000000000000000000001p1023",
+               "-0x1.fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp1023" };
+       
+       for (int i = 0; i < inputs.length; i++) {
+           double actual = Double.parseDouble(inputs[i]);
+           double expected = Double.longBitsToDouble(expecteds[i]);
+           
+           String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
+           String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
+           String errorMsg = i + "th input string is:<" + inputs[i]
+                   + ">.The expected result should be:<" + expectedString
+                   + ">, but was: <" + actualString + ">. ";
+           
+           assertEquals(errorMsg, expected, actual);
+       }
+    }
+    
+    /**
+     * @tests java.lang.Double#parseDouble(java.lang.String)
+     */
+    public void test_parseDouble_LString_MinNormalBoundary() {
+        long[] expecteds = {
+                0x10000000000000L,                0x10000000000000L,                0x10000000000000L,
+                0x10000000000000L,                0x10000000000000L,                0x10000000000000L,
+                0x10000000000000L,                0x10000000000000L,                0x10000000000001L,
+                0x10000000000001L,                0x10000000000001L,                0x10000000000001L,
+                0x10000000000001L,                0x10000000000001L,                0x10000000000001L,
+                
+                0x8010000000000000L,                0x8010000000000000L,                0x8010000000000000L,
+                0x8010000000000000L,                0x8010000000000000L,                0x8010000000000000L,
+                0x8010000000000000L,                0x8010000000000000L,                0x8010000000000001L,
+                0x8010000000000001L,                0x8010000000000001L,                0x8010000000000001L,
+                0x8010000000000001L,                0x8010000000000001L,                0x8010000000000001L
};
+       
+       String[] inputs = {
+               "0x1.0p-1022",
+               "0x1.00000000000001p-1022",
+               "0x1.000000000000010000000000000000001p-1022",
+               "0x1.00000000000001fffffffffffffffffffffffffffffffffp-1022",
+               "0x1.00000000000007p-1022",
+               "0x1.000000000000070000000000000000001p-1022",
+               "0x1.00000000000007fffffffffffffffffffffffffffffffffp-1022",
+               "0x1.00000000000008p-1022",
+               "0x1.000000000000080000000000000000001p-1022",
+               "0x1.00000000000008fffffffffffffffffffffffffffffffffp-1022",
+               "0x1.00000000000009p-1022",
+               "0x1.000000000000090000000000000000001p-1022",
+               "0x1.00000000000009fffffffffffffffffffffffffffffffffp-1022",
+               "0x1.0000000000000fp-1022",
+               "0x1.0000000000000ffffffffffffffffffffffffffffffffffp-1022",
+               
+               "-0x1.0p-1022",
+               "-0x1.00000000000001p-1022",
+               "-0x1.000000000000010000000000000000001p-1022",
+               "-0x1.00000000000001fffffffffffffffffffffffffffffffffp-1022",
+               "-0x1.00000000000007p-1022",
+               "-0x1.000000000000070000000000000000001p-1022",
+               "-0x1.00000000000007fffffffffffffffffffffffffffffffffp-1022",
+               "-0x1.00000000000008p-1022",
+               "-0x1.000000000000080000000000000000001p-1022",
+               "-0x1.00000000000008fffffffffffffffffffffffffffffffffp-1022",
+               "-0x1.00000000000009p-1022",
+               "-0x1.000000000000090000000000000000001p-1022",
+               "-0x1.00000000000009fffffffffffffffffffffffffffffffffp-1022",
+               "-0x1.0000000000000fp-1022",
+               "-0x1.0000000000000ffffffffffffffffffffffffffffffffffp-1022" };
+       
+       for (int i = 0; i < inputs.length; i++) {
+           double actual = Double.parseDouble(inputs[i]);
+           double expected = Double.longBitsToDouble(expecteds[i]);
+           
+           String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
+           String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
+           String errorMsg = i + "th input string is:<" + inputs[i]
+                   + ">.The expected result should be:<" + expectedString
+                   + ">, but was: <" + actualString + ">. ";
+           
+           assertEquals(errorMsg, expected, actual);
+       }
+    }
+    
+    /**
+     * @tests java.lang.Double#parseDouble(java.lang.String)
+     */
+    public void test_parseDouble_LString_MaxSubNormalBoundary() {
+        long[] expecteds = {
+                0xfffffffffffffL,                0xfffffffffffffL,                0xfffffffffffffL,
+                0xfffffffffffffL,                0xfffffffffffffL,                0xfffffffffffffL,
+                0xfffffffffffffL,                0x10000000000000L,                0x10000000000000L,
+                0x10000000000000L,                0x10000000000000L,                0x10000000000000L,
+                0x10000000000000L,                0x10000000000000L,                0x10000000000000L,
+                
+                0x800fffffffffffffL,                0x800fffffffffffffL,                0x800fffffffffffffL,
+                0x800fffffffffffffL,                0x800fffffffffffffL,                0x800fffffffffffffL,
+                0x800fffffffffffffL,                0x8010000000000000L,                0x8010000000000000L,
+                0x8010000000000000L,                0x8010000000000000L,                0x8010000000000000L,
+                0x8010000000000000L,                0x8010000000000000L,                0x8010000000000000L
};
+       
+       String[] inputs = {
+               "0x0.fffffffffffffp-1022",
+               "0x0.fffffffffffff00000000000000000000000000000000001p-1022",
+               "0x0.fffffffffffff1p-1022",
+               "0x0.fffffffffffff10000000000000000000000000000000001p-1022",
+               "0x0.fffffffffffff1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
+               "0x0.fffffffffffff7p-1022",
+               "0x0.fffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
+               "0x0.fffffffffffff8p-1022",
+               "0x0.fffffffffffff80000000000000000000000000000000001p-1022",
+               "0x0.fffffffffffff8ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
+               "0x0.fffffffffffff9p-1022",
+               "0x0.fffffffffffff9ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
+               "0x0.ffffffffffffffp-1022",
+               "0x0.ffffffffffffff0000000000000000000000000000000001p-1022",
+               "0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
+
+               "-0x0.fffffffffffffp-1022",
+               "-0x0.fffffffffffff00000000000000000000000000000000001p-1022",
+               "-0x0.fffffffffffff1p-1022",
+               "-0x0.fffffffffffff10000000000000000000000000000000001p-1022",
+               "-0x0.fffffffffffff1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
+               "-0x0.fffffffffffff7p-1022",
+               "-0x0.fffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
+               "-0x0.fffffffffffff8p-1022",
+               "-0x0.fffffffffffff80000000000000000000000000000000001p-1022",
+               "-0x0.fffffffffffff8ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
+               "-0x0.fffffffffffff9p-1022",
+               "-0x0.fffffffffffff9ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
+               "-0x0.ffffffffffffffp-1022",
+               "-0x0.ffffffffffffff0000000000000000000000000000000001p-1022",
+               "-0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022"
};        
+       
+       for (int i = 0; i < inputs.length; i++) {
+           double actual = Double.parseDouble(inputs[i]);
+           double expected = Double.longBitsToDouble(expecteds[i]);
+           
+           String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
+           String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
+           String errorMsg = i + "th input string is:<" + inputs[i]
+                   + ">.The expected result should be:<" + expectedString
+                   + ">, but was: <" + actualString + ">. ";
+           
+           assertEquals(errorMsg, expected, actual);
+       }
+    }
+    
+    /**
+     * @tests java.lang.Double#parseDouble(java.lang.String)
+     */
+    public void test_parseDouble_LString_MinSubNormalBoundary() {
+        long[] expecteds = {
+                0x1L,                0x1L,                0x2L,
+                0x1L,                0x1L,                0x1L,
+                0x2L,                0x2L,                0x2L,
+                0x2L,                0x2L,                0x2L,
+                0x2L,                0x2L,                0x2L,
+                
+                0x8000000000000001L,                0x8000000000000001L,                0x8000000000000002L,
+                0x8000000000000001L,                0x8000000000000001L,                0x8000000000000001L,
+                0x8000000000000002L,                0x8000000000000002L,                0x8000000000000002L,
+                0x8000000000000002L,                0x8000000000000002L,                0x8000000000000002L,
+                0x8000000000000002L,                0x8000000000000002L,                0x8000000000000002L
};
+       
+       String[] inputs = {
+               "0x0.0000000000001p-1022",
+               "0x0.00000000000010000000000000000001p-1022",
+               "0x0.0000000000001fffffffffffffffffffffffffffffffffp-1022",
+               "0x0.00000000000017p-1022",
+               "0x0.000000000000170000000000000000001p-1022",
+               "0x0.00000000000017fffffffffffffffffffffffffffffffffp-1022",
+               "0x0.00000000000018p-1022",
+               "0x0.000000000000180000000000000000001p-1022",
+               "0x0.00000000000018fffffffffffffffffffffffffffffffffp-1022",
+               "0x0.00000000000019p-1022",
+               "0x0.000000000000190000000000000000001p-1022",
+               "0x0.00000000000019fffffffffffffffffffffffffffffffffp-1022",
+               "0x0.0000000000001fp-1022",
+               "0x0.0000000000001f0000000000000000001p-1022",
+               "0x0.0000000000001ffffffffffffffffffffffffffffffffffp-1022",  
+               
+               "-0x0.0000000000001p-1022",
+               "-0x0.00000000000010000000000000000001p-1022",
+               "-0x0.0000000000001fffffffffffffffffffffffffffffffffp-1022",
+               "-0x0.00000000000017p-1022",
+               "-0x0.000000000000170000000000000000001p-1022",
+               "-0x0.00000000000017fffffffffffffffffffffffffffffffffp-1022",
+               "-0x0.00000000000018p-1022",
+               "-0x0.000000000000180000000000000000001p-1022",
+               "-0x0.00000000000018fffffffffffffffffffffffffffffffffp-1022",
+               "-0x0.00000000000019p-1022",
+               "-0x0.000000000000190000000000000000001p-1022",
+               "-0x0.00000000000019fffffffffffffffffffffffffffffffffp-1022",
+               "-0x0.0000000000001fp-1022",
+               "-0x0.0000000000001f0000000000000000001p-1022",
+               "-0x0.0000000000001ffffffffffffffffffffffffffffffffffp-1022" };
+       
+       for (int i = 0; i < inputs.length; i++) {
+           double actual = Double.parseDouble(inputs[i]);
+           double expected = Double.longBitsToDouble(expecteds[i]);
+           
+           String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
+           String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
+           String errorMsg = i + "th input string is:<" + inputs[i]
+                   + ">.The expected result should be:<" + expectedString
+                   + ">, but was: <" + actualString + ">. ";
+           
+           assertEquals(errorMsg, expected, actual);
+       }
+    }
+    
+    /**
+     * @tests java.lang.Double#parseDouble(java.lang.String)
+     */
+    public void test_parseDouble_LString_ZeroBoundary() {
+        long[] expecteds = {
+                0x0L,                0x0L,                0x0L,
+                0x1L,                0x1L,                0x1L,
+                0x1L,                0x1L,                0x1L,
+                0x8000000000000000L,                0x8000000000000000L,                0x8000000000000000L,
+                0x8000000000000001L,                0x8000000000000001L,                0x8000000000000001L,
+                0x8000000000000001L,                0x8000000000000001L,                0x8000000000000001L
};
+       
+       String[] inputs = {
+               "0x0.00000000000004p-1022",
+               "0x0.00000000000007ffffffffffffffffffffffp-1022",
+               "0x0.00000000000008p-1022",
+               "0x0.000000000000080000000000000000001p-1022",
+               "0x0.00000000000008fffffffffffffffffffffffffffffffp-1022",
+               "0x0.00000000000009p-1022",
+               "0x0.000000000000090000000000000000001p-1022",
+               "0x0.00000000000009fffffffffffffffffffffffffffffffffp-1022",
+               "0x0.0000000000000fffffffffffffffffffffffffffffffffffp-1022",
+          
+               "-0x0.00000000000004p-1022",
+               "-0x0.00000000000007ffffffffffffffffffffffp-1022",
+               "-0x0.00000000000008p-1022",
+               "-0x0.000000000000080000000000000000001p-1022",
+               "-0x0.00000000000008fffffffffffffffffffffffffffffffp-1022",
+               "-0x0.00000000000009p-1022",
+               "-0x0.000000000000090000000000000000001p-1022",
+               "-0x0.00000000000009fffffffffffffffffffffffffffffffffp-1022",
+               "-0x0.0000000000000fffffffffffffffffffffffffffffffffffp-1022" };
+       
+       for (int i = 0; i < inputs.length; i++) {
+           double actual = Double.parseDouble(inputs[i]);
+           double expected = Double.longBitsToDouble(expecteds[i]);
+           
+           String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
+           String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
+           String errorMsg = i + "th input string is:<" + inputs[i]
+                   + ">.The expected result should be:<" + expectedString
+                   + ">, but was: <" + actualString + ">. ";
+           
+           assertEquals(errorMsg, expected, actual);
+       }
     }
 
     /**



Mime
View raw message