Numeric Literals (Summary 4)

[email protected] (Michael Lazzaro) Thu, 21 Nov 2002 13:02:57 -0800
Newsgroups perl.perl6.documentation
Message-ID <[email protected]>
With the very latest corrections.  The last remaining known "numeric 
literals" issue is whether we want to allow '.' in explicit radix, e.g. 
10#1.234, or whether we want to disallow it as being Way Too Creepy.  
Am I missing anything else, or is this part done?

--- Numeric Literals ---

decimal notation:
      123       # int 123
     0123       # int 123   (not octal!)
     123.0      # num 123.0
     -123       # int -123

    0_1.2_3     # ok
    _01.23      # wrong
    01.23_      # wrong
    01_._23     # wrong
    1__2        # wrong

exponential notation:
    -1.23e4     # num
    -1.23E4     # num (identical)
    1.23_e_4    # wrong

bin/oct/hex notation:

    0d6789      # decimal
    0b0110      # bin
    0o0123      # oct
    0x00ff      # hex
    0x00fF      # hex, == 0x00ff
    0x00FF      # hex, == 0x00ff

    -0xff       # ok
    -0x00ff     # ok

    0xf_f       # ok
    0x_ff       # wrong

    0B0110      # wrong, should be 0b0110
    0O0123      # wrong, should be 0o0123
    0X00FF      # wrong, should be 0x00FF

explicit radix:

    (radix 2-36)

    20#1gj       # base 20
    20#1GJ       # base 20 (identical)
    20#1:G:J     # base 20 (identical)
    20#1_G_J     # base 20 (identical)
    20#1:16:19   # base 20 (identical)
    20#1_16_19   # NOT identical, == 20:11619
    20#1:1_6:19  # WRONG: colon form may not have underlines

    20#1_G.J     # w/ radix point (e.g. float)
    20#1:16.19   # (identical)

    -20#1GJ      # base 20 (negative)
    -20#1:16:19  # base 20 (negative)

   (radix 37-RADIX_MAX)

   256#0:253:254:255   # base 256
   256#0_253_254_255   # base 256, NOT identical!


Other issues w/ literals:

- radix <= 36, alpha digits may be upper or lowercase
- radix > 36, only colon form is allowed, not alpha digits
- underlines may appear ONLY between digits
- colon form may therefore not have underlines
- radix < 2 throws error
- negative sign goes before radix, e.g. -20#1GJ.
- need to specify RADIX_MAX
- explicit radix form may have radix point, '.',
     but cannot use exponential notation ('e')

- can't have runtime radix, e.g. 2**8#10, because # binds tighter.
- can't say (2**8)#10, because not a literal.

MikeL