Web Hosting by 1＆1

3.1 Integer Basics

The range of values for an integer depends on the machine. The minimum range is −536870912 to 536870911 (30 bits; i.e., -2**29 to 2**29 - 1), but some machines may provide a wider range. Many examples in this chapter assume an integer has 30 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.
1073741825      ; Also the integer 1, due to overflow.
0               ; The integer 0.
-0               ; The integer 0.
```

```     #b101100 ⇒ 44
#o54 ⇒ 44
#x2c ⇒ 44
#24r1k ⇒ 44
```

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 30-bit binary, the decimal integer 5 looks like this:

```     00 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:

```     11 1111  1111 1111  1111 1111  1111 1111
```

−1 is represented as 30 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:

```     11 1111  1111 1111  1111 1111  1111 1011
```

In this implementation, the largest 30-bit binary integer value is 536,870,911 in decimal. In binary, it looks like this:

```     01 1111  1111 1111  1111 1111  1111 1111
```

Since the arithmetic functions do not check whether integers go outside their range, when you add 1 to 536,870,911, the value is the negative integer −536,870,912:

```     (+ 1 536870911)
⇒ -536870912
⇒ 10 0000  0000 0000  0000 0000  0000 0000
```

Many of the functions described in this chapter accept markers for arguments in place of numbers. (See Markers.) Since the actual arguments to such functions may be either numbers or markers, we often give these arguments the name number-or-marker. When the argument value is a marker, its position value is used and its buffer is ignored.

— Variable: most-positive-fixnum

The value of this variable is the largest integer that Emacs Lisp can handle.

— Variable: most-negative-fixnum

The value of this variable is the smallest integer that Emacs Lisp can handle. It is negative.

See max-char, for the maximum value of a valid character codepoint.