GNU Info

Info Node: (elisp)Integer Basics

(elisp)Integer Basics


Next: Float Basics Up: Numbers
Enter node , (file) or (file)node

Integer Basics
==============

   The range of values for an integer depends on the machine.  The
minimum range is -134217728 to 134217727 (28 bits; i.e., -2**27 to
2**27 - 1), 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.

   In addition, the Lisp reader recognizes a syntax for integers in
bases other than 10: `#BINTEGER' reads INTEGER in binary (radix 2),
`#OINTEGER' reads INTEGER in octal (radix 8), `#XINTEGER' reads INTEGER
in hexadecimal (radix 16), and `#RADIXrINTEGER' reads INTEGER in radix
RADIX (where RADIX is between 2 and 36, inclusivley).  Case is not
significant for the letter after `#' (`B', `O', etc.) that denotes the
radix.

   To understand how various functions work on integers, especially the
bitwise operators (Note: 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 value is
134,217,727 in decimal.  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 functions described in this chapter accept markers for
arguments in place of numbers.  (Note: 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.


automatically generated by info2www version 1.2.2.9