Next: , Previous: , Up: Numbers   [Contents][Index]


9.1 Integer Basics

The range of values for an integer depends on the machine. The minimum range is -134217728 to 134217727 (28 bits; i.e., to but some machines may provide a wider range. Many examples in this chapter assume an integer has 28 bits.

The Lisp reader reads an integer as a sequence of digits with optional initial sign and optional final period.

 1               ; The integer 1.
 1.              ; The integer 1.
+1               ; Also the integer 1.
-1               ; The integer -1.
 268435457       ; Also the integer 1, due to overflow.
 0               ; The integer 0.
-0               ; The integer 0.

To understand how various functions work on integers, especially the bitwise operators (see Bitwise Operations), it is often helpful to view the numbers in their binary form.

In 28-bit binary, the decimal integer 5 looks like this:

0000  0000 0000  0000 0000  0000 0101

(We have inserted spaces between groups of 4 bits, and two spaces between groups of 8 bits, to make the binary integer easier to read.)

The integer -1 looks like this:

1111  1111 1111  1111 1111  1111 1111

-1 is represented as 28 ones. (This is called two’s complement notation.)

The negative integer, -5, is creating by subtracting 4 from -1. In binary, the decimal integer 4 is 100. Consequently, -5 looks like this:

1111  1111 1111  1111 1111  1111 1011

In this implementation, the largest 28-bit binary integer is the decimal integer 134,217,727. In binary, it looks like this:

0111  1111 1111  1111 1111  1111 1111

Since the arithmetic functions do not check whether integers go outside their range, when you add 1 to 134,217,727, the value is the negative integer -134,217,728:

(+ 1 134217727)
     ⇒ -134217728
     ⇒ 1000  0000 0000  0000 0000  0000 0000

Many of the following functions accept markers for arguments as well as integers. (See Markers.) More precisely, the actual arguments to such functions may be either integers or markers, which is why we often give these arguments the name int-or-marker. When the argument value is a marker, its position value is used and its buffer is ignored.


Next: , Previous: , Up: Numbers   [Contents][Index]