QDox
  1. QDox
  2. QDOX-185

Support Underscores in Numbers (java7)

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0
    • Component/s: Parser
    • Labels:
      None
    • Number of attachments :
      0

      Description

      For details see http://mail.openjdk.java.net/pipermail/coin-dev/2009-April/001628.html

      Some examples:

      long creditCardNumber = 1234_5678_9012_3456L;
      long socialSecurityNumbers = 999_99_9999L;
      float monetaryAmount = 12_345_132.12;
      long hexBytes = 0xFF_EC_DE_5E;
      long hexWords = 0xFFEC_DE5E;
      long maxLong = 0x7fff_ffff_ffff_ffffL;
      long alsoMaxLong = 9_223_372_036_854_775_807L;
      double whyWouldYouEverDoThis = 0x1_.ffff_ffff_ffff_fp10_23;
      
      // Additionally, if binary literals are ever added to the Java language, the following might also be possible...
         byte nybbles = 0b0010_0101;
         long bytes = 0b11010010_01101001_10010100_10010010;
         int weirdBitfields = 0b000_10_101;
      
      
      // Note that according to this proposal, underscores can only be placed between digits. They cannot be placed by themselves in positions where a string of digits would normally be expected:
      
      int x1 = _52;  // This is an identifier, not a numeric literal.
      int x2 = 5_2;  // OK. (Decimal literal)
      int x2 = 52_;  // Illegal. (Underscores must always be between digits)
      int x3 = 5_______2; // OK. (Decimal literal.)
      
      int x4 = 0_x52;  // Illegal. Can't put underscores in the "0x" radix prefix.
      int x5 = 0x_52;  // Illegal. (Underscores must always be between digits)
      int x6 = 0x5_2;  // OK. (Hexadecimal literal)
      int x6 = 0x52_;  // Illegal. (Underscores must always be between digits)
      int x6 = 0x_;    // Illegal. (Not valid with the underscore removed)
      
      int x7 = 0_52;   // OK. (Octal literal)
      int x7 = 05_2;   // OK. (Octal literal)
      int x8 = 052_;   // Illegal. (Underscores must always be between digits)
      

        Activity

        Hide
        Robert Scholte added a comment -

        First part done in rev. 1244
        There's a newer version of the specs, although still informative
        http://cr.openjdk.java.net/~darcy/ProjectCoin/ProjectCoin-Documentation-v0.83.html#literals

        Show
        Robert Scholte added a comment - First part done in rev. 1244 There's a newer version of the specs, although still informative http://cr.openjdk.java.net/~darcy/ProjectCoin/ProjectCoin-Documentation-v0.83.html#literals
        Hide
        Robert Scholte added a comment -

        Fix in rev. 1253

        Show
        Robert Scholte added a comment - Fix in rev. 1253
        Robert Scholte made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.0 [ 15636 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Robert Scholte
            Reporter:
            Robert Scholte
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: