Next: , Previous: Numbers as Tokens, Up: Interpretation of Tokens

#### 2.3.2 Constructing Numbers from Tokens

A real is constructed directly from a corresponding numeric token; see Figure 2.9.

A complex is notated as a `#C` (or `#c`) followed by a list of two reals; see Section 2.4.8.11 (Sharpsign C).

The reader macros `#B`, `#O`, `#X`, and `#R` may also be useful in controlling the input radix in which rationals are parsed; see Section 2.4.8.7 (Sharpsign B), Section 2.4.8.8 (Sharpsign O), Section 2.4.8.9 (Sharpsign X), and Section 2.4.8.10 (Sharpsign R).

This section summarizes the full syntax for numbers.

##### 2.3.2.1.1 Syntax of an Integer

Integers can be written as a sequence of digits, optionally preceded by a sign and optionally followed by a decimal point; see Figure 2.9. When a decimal point is used, the digits are taken to be in radix `10`; when no decimal point is used, the digits are taken to be in radix given by the current input base.

For information on how integers are printed, see Section 22.1.3.1.1 (Printing Integers).

##### 2.3.2.1.2 Syntax of a Ratio

Ratios can be written as an optional sign followed by two non-empty sequences of digits separated by a slash; see Figure 2.9. The second sequence may not consist entirely of zeros. Examples of ratios are in the next figure.

 `2/3` ;This is in canonical form `4/6` ;A non-canonical form for 2/3 `-17/23` ;A ratio preceded by a sign `-30517578125/32768` ;This is (-5/2)^15 `10/5` ;The canonical form for this is `2` `#o-101/75` ;Octal notation for -65/61 `#3r120/21` ;Ternary notation for 15/7 `#Xbc/ad` ;Hexadecimal notation for 188/173 `#xFADED/FACADE` ;Hexadecimal notation for 1027565/16435934

Figure 2.13: Examples of Ratios

For information on how ratios are printed, see Section 22.1.3.1.2 (Printing Ratios).

##### 2.3.2.2 Syntax of a Float

Floats can be written in either decimal fraction or computerized scientific notation: an optional sign, then a non-empty sequence of digits with an embedded decimal point, then an optional decimal exponent specification. If there is no exponent specifier, then the decimal point is required, and there must be digits after it. The exponent specifier consists of an exponent marker, an optional sign, and a non-empty sequence of digits. If no exponent specifier is present, or if the exponent marker `e` (or `E`) is used, then the format specified by `*read-default-float-format*` is used. See Figure 2.9.

An implementation may provide one or more kinds of float that collectively make up the type `float`. The letters `s`, `f`, `d`, and `l` (or their respective uppercase equivalents) explicitly specify the use of the types `short-float`, `single-float`, `double-float`, and `long-float`, respectively.

The internal format used for an external representation depends only on the exponent marker, and not on the number of decimal digits in the external representation.

The next figure contains examples of notations for floats:

 `0.0` ;Floating-point zero in default format `0E0` ;As input, this is also floating-point zero in default format. ;As output, this would appear as `0.0`. `0e0` ;As input, this is also floating-point zero in default format. ;As output, this would appear as `0.0`. `-.0` ;As input, this might be a zero or a minus zero, ; depending on whether the implementation supports ; a distinct minus zero. ;As output, `0.0` is zero and `-0.0` is minus zero. `0.` ;On input, the integer zero—not a floating-point number! ;Whether this appears as `0` or `0.` on output depends ;on the value of `*print-radix*`. `0.0s0` ;A floating-point zero in short format `0s0` ;As input, this is a floating-point zero in short format. ;As output, such a zero would appear as `0.0s0` ; (or as `0.0` if short-float was the default format). `6.02E+23` ;Avogadro's number, in default format `602E+21` ;Also Avogadro's number, in default format

Figure 2.14: Examples of Floating-point numbers

For information on how floats are printed, see Section 22.1.3.1.3 (Printing Floats).

##### 2.3.2.3 Syntax of a Complex

A complex has a Cartesian structure, with a real part and an imaginary part each of which is a real. The parts of a complex are not necessarily floats but both parts must be of the same type:

either both are rationals, or both are of the same float subtype. When constructing a complex, if the specified parts are not the same type, the parts are converted to be the same type internally (i.e., the rational part is converted to a float). An object of type `(complex rational)` is converted internally and represented thereafter as a rational if its imaginary part is an integer whose value is 0.

For further information, see Section 2.4.8.11 (Sharpsign C) and Section 22.1.3.1.4 (Printing Complexes).