Harmony
  1. Harmony
  2. HARMONY-747

java.lang.Doulbe.parseDouble(String) does not support Hex number

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Classlib
    • Labels:
      None

      Description

      Hello,

      When implementing java.util.Scanner, I find that java.lang.Doulbe.parseDouble(String) does not support Hex number. Could anyone have a look at this issue? Thanks a lot.

      The following test passes on RI, but fails on Harmony.

      public void test_ParseDouble()

      { String hexString = Double.toHexString(123); assertEquals("0x1.ecp6", hexString); double d = Double.parseDouble(hexString); assertEquals(123.0, d); }

      Best regards,
      Richard

      1. lunipatch.txt
        18 kB
        Sian January
      2. patch.diff
        6 kB
        Leo Li
      3. patch_partII.diff
        4 kB
        Leo Li
      4. patch_III.diff
        1 kB
        Leo Li
      5. patch.diff
        4 kB
        Leo Li
      6. patch.diff
        40 kB
        Leo Li
      7. patchV.diff
        41 kB
        Leo Li

        Activity

        Hide
        Sian January added a comment -

        Double.valueOf(String), Float.parseFloat(String), Float.valueOf(String) and both Float and Double's String constructors did not support the Hex representation either. Possibly missing because the requirement was new in Java 5?

        This patch provides the implementation and tests for both Float and Double.

        Show
        Sian January added a comment - Double.valueOf(String), Float.parseFloat(String), Float.valueOf(String) and both Float and Double's String constructors did not support the Hex representation either. Possibly missing because the requirement was new in Java 5? This patch provides the implementation and tests for both Float and Double.
        Hide
        Paulex Yang added a comment -

        Sian, sorry to not response for so long time. But I'm not sure the patch fully resolve the issue. Seems the parseDbl/FltFromHex() considers normalDigit either 0 or 1, but actually RI can parse more hex format, for example, tests below:

        public static void main(String[] args)

        { Double d = Double.valueOf("0x3f.00p2"); System.out.println(d); }

        RI outputs: 252.0, while Harmony with the patch throws NumberFormatException.

        And from lexical syntax specified by spec on the input string of Double.valueOf()/parseDouble(), digits other than 0/1 is acceptable.

        If you have no objections, I can look at it myself how to handle this, but it would be great if you provide a additional patch on it

        [1]
        "
        FloatValue:
        Signopt NaN
        Signopt Infinity
        Signopt FloatingPointLiteral
        Signopt HexFloatingPointLiteral
        SignedInteger

        HexFloatingPointLiteral:
        HexSignificand BinaryExponent FloatTypeSuffixopt

        HexSignificand:
        HexNumeral
        HexNumeral .
        0x HexDigitsopt . HexDigits
        0X HexDigitsopt . HexDigits

        BinaryExponent:
        BinaryExponentIndicator SignedInteger

        BinaryExponentIndicator:
        p
        P
        "

        Show
        Paulex Yang added a comment - Sian, sorry to not response for so long time. But I'm not sure the patch fully resolve the issue. Seems the parseDbl/FltFromHex() considers normalDigit either 0 or 1, but actually RI can parse more hex format, for example, tests below: public static void main(String[] args) { Double d = Double.valueOf("0x3f.00p2"); System.out.println(d); } RI outputs: 252.0, while Harmony with the patch throws NumberFormatException. And from lexical syntax specified by spec on the input string of Double.valueOf()/parseDouble(), digits other than 0/1 is acceptable. If you have no objections, I can look at it myself how to handle this, but it would be great if you provide a additional patch on it [1] " FloatValue: Signopt NaN Signopt Infinity Signopt FloatingPointLiteral Signopt HexFloatingPointLiteral SignedInteger HexFloatingPointLiteral: HexSignificand BinaryExponent FloatTypeSuffixopt HexSignificand: HexNumeral HexNumeral . 0x HexDigitsopt . HexDigits 0X HexDigitsopt . HexDigits BinaryExponent: BinaryExponentIndicator SignedInteger BinaryExponentIndicator: p P "
        Hide
        Sian January added a comment -

        Hi Paulex - Thanks for looking at the patch. I won't have time to look at this for the next few weeks so you're very welcome to have a look yourself, or if you don't get time or would rather I did it then I will have a look when I can.

        Show
        Sian January added a comment - Hi Paulex - Thanks for looking at the patch. I won't have time to look at this for the next few weeks so you're very welcome to have a look yourself, or if you don't get time or would rather I did it then I will have a look when I can.
        Hide
        Leo Li added a comment -

        Hi all:
        I am willing to fix the bug. Since the issue is a little complicated, I decide to apply several patches to complete the function with one step at a time.

        Show
        Leo Li added a comment - Hi all: I am willing to fix the bug. Since the issue is a little complicated, I decide to apply several patches to complete the function with one step at a time.
        Hide
        Leo Li added a comment -

        It is the first part of the implementation to parse hex string into double, which parses the string into three sub ones which stands for sign, exponent and mantissa respectively.

        Show
        Leo Li added a comment - It is the first part of the implementation to parse hex string into double, which parses the string into three sub ones which stands for sign, exponent and mantissa respectively.
        Hide
        Paulex Yang added a comment -

        Leo, thank you verty much for the volunteer, first patch applied at revision 447351, please verify it is as you expeced. I'm looking forward your following steps.

        Show
        Paulex Yang added a comment - Leo, thank you verty much for the volunteer, first patch applied at revision 447351, please verify it is as you expeced. I'm looking forward your following steps.
        Hide
        Leo Li added a comment -

        Paulex:
        It is ok. I have verified it.

        Show
        Leo Li added a comment - Paulex: It is ok. I have verified it.
        Hide
        Leo Li added a comment -

        Hi, all
        This is the second part of the jira which mainly concludes the framework of the implementation.

        Show
        Leo Li added a comment - Hi, all This is the second part of the jira which mainly concludes the framework of the implementation.
        Hide
        Paulex Yang added a comment -

        Leo, second patch applied at revision r448138, please verify, thanks a lot.

        Show
        Paulex Yang added a comment - Leo, second patch applied at revision r448138, please verify, thanks a lot.
        Hide
        Leo Li added a comment -

        This is the third part of the issue which extract exponent of the double value.

        Show
        Leo Li added a comment - This is the third part of the issue which extract exponent of the double value.
        Hide
        Paulex Yang added a comment -

        Leo, the third patch applied at revision r448768, please verify, thanks a lot. And do you have some estimation on the following steps? for example, how much further work needed and how about your plan?

        Show
        Paulex Yang added a comment - Leo, the third patch applied at revision r448768, please verify, thanks a lot. And do you have some estimation on the following steps? for example, how much further work needed and how about your plan?
        Hide
        Leo Li added a comment -

        Paulex, I need 2-3 more patches to complete the function. One about normalize, one about rounding and another about subnormal situation.

        Show
        Leo Li added a comment - Paulex, I need 2-3 more patches to complete the function. One about normalize, one about rounding and another about subnormal situation.
        Hide
        Leo Li added a comment -

        Paulex, I have verified the second and third part of the issue. Thank you.

        Show
        Leo Li added a comment - Paulex, I have verified the second and third part of the issue. Thank you.
        Hide
        Leo Li added a comment -

        Hi, all
        This is the third part of the jira which normalizes mantissa.

        Show
        Leo Li added a comment - Hi, all This is the third part of the jira which normalizes mantissa.
        Hide
        Paulex Yang added a comment -

        Leo, the fourth patch applied at revision r450395, thanks for the enhancement, please verify.

        Show
        Paulex Yang added a comment - Leo, the fourth patch applied at revision r450395, thanks for the enhancement, please verify.
        Hide
        Leo Li added a comment -

        Verified . Thank you.

        Show
        Leo Li added a comment - Verified . Thank you.
        Hide
        Leo Li added a comment -

        This is the final part of the issue. Will somebody try this?

        Show
        Leo Li added a comment - This is the final part of the issue. Will somebody try this?
        Hide
        Leo Li added a comment -

        The original patch becomes obsolete. Will somebody try this?

        Show
        Leo Li added a comment - The original patch becomes obsolete. Will somebody try this?
        Hide
        Paulex Yang added a comment -

        Leo, the last patch applied at revision r451108, thanks a lot for the continous enhancement.

        Richard, please verify the problem is fully resolved as you expected, thank you.

        Show
        Paulex Yang added a comment - Leo, the last patch applied at revision r451108, thanks a lot for the continous enhancement. Richard, please verify the problem is fully resolved as you expected, thank you.

          People

          • Assignee:
            Paulex Yang
            Reporter:
            Richard Liang
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development