elisp: Integer Basics

 
 3.1 Integer Basics
 ==================
 
 The range of values for an integer depends on the machine.  The minimum
 range is −536,870,912 to 536,870,911 (30 bits; i.e., −2**29 to 2**29 −
 1), but many machines provide a wider range.  Many examples in this
 chapter assume the minimum integer width of 30 bits.
 
    The Lisp reader reads an integer as a sequence of digits with
 optional initial sign and optional final period.  An integer that is out
 of the Emacs range is treated as a floating-point number.
 
       1               ; The integer 1.
       1.              ; The integer 1.
      +1               ; Also the integer 1.
      -1               ; The integer −1.
       9000000000000000000
                       ; The floating-point number 9e18.
       0               ; The integer 0.
      -0               ; The integer 0.
 
    The syntax for integers in bases other than 10 uses ‘#’ followed by a
 letter that specifies the radix: ‘b’ for binary, ‘o’ for octal, ‘x’ for
 hex, or ‘RADIXr’ to specify radix RADIX.  Case is not significant for
 the letter that specifies the radix.  Thus, ‘#bINTEGER’ reads INTEGER in
 binary, and ‘#RADIXrINTEGER’ reads INTEGER in radix RADIX.  Allowed
 values of RADIX run from 2 to 36.  For example:
 
      #b101100 ⇒ 44
      #o54 ⇒ 44
      #x2c ⇒ 44
      #24r1k ⇒ 44
 
    To understand how various functions work on integers, especially the
 bitwise operators (SeeBitwise Operations), it is often helpful to
 view the numbers in their binary form.
 
    In 30-bit binary, the decimal integer 5 looks like this:
 
      0000...000101 (30 bits total)
 
 (The ‘...’ stands for enough bits to fill out a 30-bit word; in this
 case, ‘...’ stands for twenty 0 bits.  Later examples also use the ‘...’
 notation to make binary integers easier to read.)
 
    The integer −1 looks like this:
 
      1111...111111 (30 bits total)
 
 −1 is represented as 30 ones.  (This is called “two’s complement”
 notation.)
 
    Subtracting 4 from −1 returns the negative integer −5.  In binary,
 the decimal integer 4 is 100.  Consequently, −5 looks like this:
 
      1111...111011 (30 bits total)
 
    In this implementation, the largest 30-bit binary integer is
 536,870,911 in decimal.  In binary, it looks like this:
 
      0111...111111 (30 bits total)
 
    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
           ⇒ 1000...000000 (30 bits total)
 
    Many of the functions described in this chapter accept markers for
 arguments in place of numbers.  (SeeMarkers.)  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.  Typical values are 2**29 − 1 on 32-bit and 2**61 − 1
      on 64-bit platforms.
 
  -- Variable: most-negative-fixnum
      The value of this variable is the smallest integer that Emacs Lisp
      can handle.  It is negative.  Typical values are −2**29 on 32-bit
      and −2**61 on 64-bit platforms.
 
    In Emacs Lisp, text characters are represented by integers.  Any
 integer between zero and the value of ‘(max-char)’, inclusive, is
 considered to be valid as a character.  SeeCharacter Codes.