Integer and long integer literals are described by the following lexical definitions:
整数和长整数型字面值可以用以下词法定义:
longinteger |
::= |
integer ("l" | "L") |
integer |
::= |
decimalinteger |
octinteger |
hexinteger |
decimalinteger |
::= |
nonzerodigit
digit* | "0" |
octinteger |
::= | "0"
octdigit+ |
hexinteger |
::= | "0" ("x" | "X")
hexdigit+ |
nonzerodigit |
::= | "1"..."9" |
octdigit |
::= | "0"..."7" |
hexdigit |
::= |
digit | "a"..."f" | "A"..."F" |
Although both lower case "l" and upper case "L" are allowed as suffix for long integers, it is strongly recommended to always use "L", since the letter "l" looks too much like the digit "1".
虽然小写的"l"的大写的"L"都可以作为长整数的后缀, 但强烈火推荐使用"L", 因为字母"l"看来太像数字1了.
Plain integer literals that are above the largest representable plain integer (e.g., 2147483647 when using 32-bit arithmetic) are accepted as if they were long integers instead.2.1 There is no limit for long integer literals apart from what can be stored in available memory.
普通十进制整数最大可以为2147483647(也就是使用32位比特数字的最大值),普通的八进制和十六进制数可以4294967295, 但大于2147483647的数就通过减4294967295变为负数了.长整数的大小是没有限制的, 仅仅受制于可用的内存容量.
Some examples of plain integer literals (first row) and long integer literals (second and third rows):
下面是一些普通和长整数的例子:
7 2147483647 0177
3L 79228162514264337593543950336L 0377L 0x100000000L
79228162514264337593543950336 0xdeadbeef
Floating point literals are described by the following lexical definitions:
浮点型的字面值可以用以下词法定义描述:
floatnumber |
::= |
pointfloat |
exponentfloat |
pointfloat |
::= | [intpart]
fraction |
intpart "." |
exponentfloat |
::= | (intpart
|
pointfloat)
exponent |
intpart |
::= |
digit+ |
fraction |
::= | "."
digit+ |
exponent |
::= | ("e" | "E") ["+" | "-"]
digit+ |
Note that the integer and exponent parts of floating point numbers can look like octal integers, but are interpreted using radix 10. For example, "077e010" is legal, and denotes the same number as "77e10". The allowed range of floating point literals is implementation-dependent. Some examples of floating point literals:
注意浮点数的整数部分的指数部分可以看起来像是个八进制数, 但实际上仍作为十进制处理, 例如,"077e010"是合法的, 它等价于"77e10".浮点数的允许范围是依赖于实现的,确良以是一些浮点数的例子:
3.14 10. .001 1e100 3.14e-10 0e0
Note that numeric literals do not include a sign; a phrase like
-1 is actually an expression composed of the operator
- and the literal 1.
注意数值型的字面值不包括符号(译注:正负号), 像-1实际上是个组合了一元运算符"-"和字面值1的表达式.
Imaginary literals are described by the following lexical definitions:
虚数的字面值可以用下面的词法定义描述:
imagnumber |
::= | (floatnumber
|
intpart) ("j" | "J") |
An imaginary literal yields a complex number with a real part of
0.0. Complex numbers are represented as a pair of floating point
numbers and have the same restrictions on their range. To create a
complex number with a nonzero real part, add a floating point
number to it, e.g., (3+4j). Some examples of imaginary
literals:
虚数是实部为零的复数, 复数表达成一对有着相同取值范围的浮点数对.为了创建一个有着非零实部的复数,可以对它增加一个浮点数,例如,(3+4j). 下面是一些例子:
3.14j 10.j 10j .001j 1e100j 3.14e-10j