numeric_literal = [ + | – ] ( 0 [ hex_number | binary_number | decimal_number | octal_number ] | decimal_literal )

decimal_literal = decimal_digits [ . decimal_digits ] [ ( e | E ) [ + | – ] decimal_digits ]

binary_number = ( b | B ) binary_digits
octal_number = ( o | O | _ ) octal_digits
decimal_number = ( d | D ) decimal_digits
hex_number = ( x | X ) hex_digitsbinary_digits = ( 0 | 1 ) [ [ _ ] binary_digits ]
octal_digits = ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 ) [ [ _ ] octal_digits ]
decimal_digits = ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ) [ [ _ ] decimal_digits ]
hex_digits = ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | A | b | B | c | C | d | D | e | E | f | F ) [ [ _ ] hex_digits ]
Note: A digit sequence cannot start or end with an underscore (_) or contain two adjacent underscores, except that an octal digit sequence can start with an underscore.

The value of all numeric literals is the conventional interpretation. Any decimal literal which contains a decimal point ( . ) or exponent (e or E) evaluates to a Float value. All other numeric literals evaluate to an integer – a Fixnum if it will fit, otherwise a Bignum.

Errata: Actually, Ruby 1.8.4 allows a wider (and wilder) syntax for octal and decimal literals, for example 0_177 is a valid octal literal (with value 127), and 0o.5 is a valid floating point literal (with value 0.5). Or, maybe these are bugs.
Unspecified: Precision and range of Floats, treatment of overflow and other possible conversion errors.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: