Skip to content

Clarification on numeric literals #171

Answered by zkat
benjreinhart asked this question in Q&A
Discussion options

You must be logged in to vote

Spec ref:

decimal := integer ('.' [0-9] [0-9_]*)? exponent?
exponent := ('e' | 'E') integer
integer := sign? [0-9] [0-9_]*
sign := '+' | '-'

hex := sign? '0x' hex-digit (hex-digit | '_')*
octal := sign? '0o' [0-7] [0-7_]*
binary := sign? '0b' ('0' | '1') ('0' | '1' | '_')*

Translation:

  1. Correct, that is illegal. ('0x' hex-digit (hex-digit | '_')*)
  2. Trailing underscores are a valid part of numbers
  3. You can have multiple underscores.
  4. Yes, after the first post-E digit (see definition for exponent above)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by zkat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #170 on September 16, 2021 20:47.