mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2025-02-06 20:49:33 +00:00
Update Lispref for 30-bit integers.
* numbers.texi (Integer Basics, Bitwise Operations): * objects.texi (Integer Type): Update for integers now being 30-bit.
This commit is contained in:
parent
855dc98c53
commit
1ddd662297
@ -1,3 +1,8 @@
|
||||
2010-03-03 Glenn Morris <rgm@gnu.org>
|
||||
|
||||
* numbers.texi (Integer Basics, Bitwise Operations):
|
||||
* objects.texi (Integer Type): Update for integers now being 30-bit.
|
||||
|
||||
2010-02-27 Chong Yidong <cyd@stupidchicken.com>
|
||||
|
||||
* display.texi (Low-Level Font): Document :otf font-spec property.
|
||||
|
@ -1,7 +1,8 @@
|
||||
@c -*-texinfo-*-
|
||||
@c This is part of the GNU Emacs Lisp Reference Manual.
|
||||
@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001,
|
||||
@c 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
|
||||
@c 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
|
||||
@c Free Software Foundation, Inc.
|
||||
@c See the file elisp.texi for copying conditions.
|
||||
@setfilename ../../info/numbers
|
||||
@node Numbers, Strings and Characters, Lisp Data Types, Top
|
||||
@ -36,22 +37,22 @@ exact; they have a fixed, limited amount of precision.
|
||||
@section Integer Basics
|
||||
|
||||
The range of values for an integer depends on the machine. The
|
||||
minimum range is @minus{}268435456 to 268435455 (29 bits; i.e.,
|
||||
minimum range is @minus{}536870912 to 536870911 (30 bits; i.e.,
|
||||
@ifnottex
|
||||
-2**28
|
||||
-2**29
|
||||
@end ifnottex
|
||||
@tex
|
||||
@math{-2^{28}}
|
||||
@math{-2^{29}}
|
||||
@end tex
|
||||
to
|
||||
@ifnottex
|
||||
2**28 - 1),
|
||||
2**29 - 1),
|
||||
@end ifnottex
|
||||
@tex
|
||||
@math{2^{28}-1}),
|
||||
@math{2^{29}-1}),
|
||||
@end tex
|
||||
but some machines may provide a wider range. Many examples in this
|
||||
chapter assume an integer has 29 bits.
|
||||
chapter assume an integer has 30 bits.
|
||||
@cindex overflow
|
||||
|
||||
The Lisp reader reads an integer as a sequence of digits with optional
|
||||
@ -62,7 +63,7 @@ initial sign and optional final period.
|
||||
1. ; @r{The integer 1.}
|
||||
+1 ; @r{Also the integer 1.}
|
||||
-1 ; @r{The integer @minus{}1.}
|
||||
536870913 ; @r{Also the integer 1, due to overflow.}
|
||||
1073741825 ; @r{Also the integer 1, due to overflow.}
|
||||
0 ; @r{The integer 0.}
|
||||
-0 ; @r{The integer 0.}
|
||||
@end example
|
||||
@ -93,10 +94,10 @@ from 2 to 36. For example:
|
||||
bitwise operators (@pxref{Bitwise Operations}), it is often helpful to
|
||||
view the numbers in their binary form.
|
||||
|
||||
In 29-bit binary, the decimal integer 5 looks like this:
|
||||
In 30-bit binary, the decimal integer 5 looks like this:
|
||||
|
||||
@example
|
||||
0 0000 0000 0000 0000 0000 0000 0101
|
||||
00 0000 0000 0000 0000 0000 0000 0101
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
@ -106,12 +107,12 @@ between groups of 8 bits, to make the binary integer easier to read.)
|
||||
The integer @minus{}1 looks like this:
|
||||
|
||||
@example
|
||||
1 1111 1111 1111 1111 1111 1111 1111
|
||||
11 1111 1111 1111 1111 1111 1111 1111
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
@cindex two's complement
|
||||
@minus{}1 is represented as 29 ones. (This is called @dfn{two's
|
||||
@minus{}1 is represented as 30 ones. (This is called @dfn{two's
|
||||
complement} notation.)
|
||||
|
||||
The negative integer, @minus{}5, is creating by subtracting 4 from
|
||||
@ -119,24 +120,24 @@ complement} notation.)
|
||||
@minus{}5 looks like this:
|
||||
|
||||
@example
|
||||
1 1111 1111 1111 1111 1111 1111 1011
|
||||
11 1111 1111 1111 1111 1111 1111 1011
|
||||
@end example
|
||||
|
||||
In this implementation, the largest 29-bit binary integer value is
|
||||
268,435,455 in decimal. In binary, it looks like this:
|
||||
In this implementation, the largest 30-bit binary integer value is
|
||||
536,870,911 in decimal. In binary, it looks like this:
|
||||
|
||||
@example
|
||||
0 1111 1111 1111 1111 1111 1111 1111
|
||||
01 1111 1111 1111 1111 1111 1111 1111
|
||||
@end example
|
||||
|
||||
Since the arithmetic functions do not check whether integers go
|
||||
outside their range, when you add 1 to 268,435,455, the value is the
|
||||
negative integer @minus{}268,435,456:
|
||||
outside their range, when you add 1 to 536,870,911, the value is the
|
||||
negative integer @minus{}536,870,912:
|
||||
|
||||
@example
|
||||
(+ 1 268435455)
|
||||
@result{} -268435456
|
||||
@result{} 1 0000 0000 0000 0000 0000 0000 0000
|
||||
(+ 1 536870911)
|
||||
@result{} -536870912
|
||||
@result{} 10 0000 0000 0000 0000 0000 0000 0000
|
||||
@end example
|
||||
|
||||
Many of the functions described in this chapter accept markers for
|
||||
@ -820,19 +821,19 @@ value of a positive integer by two, rounding downward.
|
||||
The function @code{lsh}, like all Emacs Lisp arithmetic functions, does
|
||||
not check for overflow, so shifting left can discard significant bits
|
||||
and change the sign of the number. For example, left shifting
|
||||
268,435,455 produces @minus{}2 on a 29-bit machine:
|
||||
536,870,911 produces @minus{}2 on a 30-bit machine:
|
||||
|
||||
@example
|
||||
(lsh 268435455 1) ; @r{left shift}
|
||||
(lsh 536870911 1) ; @r{left shift}
|
||||
@result{} -2
|
||||
@end example
|
||||
|
||||
In binary, in the 29-bit implementation, the argument looks like this:
|
||||
In binary, in the 30-bit implementation, the argument looks like this:
|
||||
|
||||
@example
|
||||
@group
|
||||
;; @r{Decimal 268,435,455}
|
||||
0 1111 1111 1111 1111 1111 1111 1111
|
||||
;; @r{Decimal 536,870,911}
|
||||
01 1111 1111 1111 1111 1111 1111 1111
|
||||
@end group
|
||||
@end example
|
||||
|
||||
@ -842,7 +843,7 @@ which becomes the following when left shifted:
|
||||
@example
|
||||
@group
|
||||
;; @r{Decimal @minus{}2}
|
||||
1 1111 1111 1111 1111 1111 1111 1110
|
||||
11 1111 1111 1111 1111 1111 1111 1110
|
||||
@end group
|
||||
@end example
|
||||
@end defun
|
||||
@ -865,9 +866,9 @@ looks like this:
|
||||
@group
|
||||
(ash -6 -1) @result{} -3
|
||||
;; @r{Decimal @minus{}6 becomes decimal @minus{}3.}
|
||||
1 1111 1111 1111 1111 1111 1111 1010
|
||||
11 1111 1111 1111 1111 1111 1111 1010
|
||||
@result{}
|
||||
1 1111 1111 1111 1111 1111 1111 1101
|
||||
11 1111 1111 1111 1111 1111 1111 1101
|
||||
@end group
|
||||
@end example
|
||||
|
||||
@ -876,11 +877,11 @@ In contrast, shifting the pattern of bits one place to the right with
|
||||
|
||||
@example
|
||||
@group
|
||||
(lsh -6 -1) @result{} 268435453
|
||||
;; @r{Decimal @minus{}6 becomes decimal 268,435,453.}
|
||||
1 1111 1111 1111 1111 1111 1111 1010
|
||||
(lsh -6 -1) @result{} 536870909
|
||||
;; @r{Decimal @minus{}6 becomes decimal 536,870,909.}
|
||||
11 1111 1111 1111 1111 1111 1111 1010
|
||||
@result{}
|
||||
0 1111 1111 1111 1111 1111 1111 1101
|
||||
01 1111 1111 1111 1111 1111 1111 1101
|
||||
@end group
|
||||
@end example
|
||||
|
||||
@ -890,34 +891,34 @@ Here are other examples:
|
||||
@c with smallbook but not with regular book! --rjc 16mar92
|
||||
@smallexample
|
||||
@group
|
||||
; @r{ 29-bit binary values}
|
||||
; @r{ 30-bit binary values}
|
||||
|
||||
(lsh 5 2) ; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101}
|
||||
@result{} 20 ; = @r{0 0000 0000 0000 0000 0000 0001 0100}
|
||||
(lsh 5 2) ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
|
||||
@result{} 20 ; = @r{00 0000 0000 0000 0000 0000 0001 0100}
|
||||
@end group
|
||||
@group
|
||||
(ash 5 2)
|
||||
@result{} 20
|
||||
(lsh -5 2) ; -5 = @r{1 1111 1111 1111 1111 1111 1111 1011}
|
||||
@result{} -20 ; = @r{1 1111 1111 1111 1111 1111 1110 1100}
|
||||
(lsh -5 2) ; -5 = @r{11 1111 1111 1111 1111 1111 1111 1011}
|
||||
@result{} -20 ; = @r{11 1111 1111 1111 1111 1111 1110 1100}
|
||||
(ash -5 2)
|
||||
@result{} -20
|
||||
@end group
|
||||
@group
|
||||
(lsh 5 -2) ; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101}
|
||||
@result{} 1 ; = @r{0 0000 0000 0000 0000 0000 0000 0001}
|
||||
(lsh 5 -2) ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
|
||||
@result{} 1 ; = @r{00 0000 0000 0000 0000 0000 0000 0001}
|
||||
@end group
|
||||
@group
|
||||
(ash 5 -2)
|
||||
@result{} 1
|
||||
@end group
|
||||
@group
|
||||
(lsh -5 -2) ; -5 = @r{1 1111 1111 1111 1111 1111 1111 1011}
|
||||
@result{} 134217726 ; = @r{0 0111 1111 1111 1111 1111 1111 1110}
|
||||
(lsh -5 -2) ; -5 = @r{11 1111 1111 1111 1111 1111 1111 1011}
|
||||
@result{} 268435454 ; = @r{00 0111 1111 1111 1111 1111 1111 1110}
|
||||
@end group
|
||||
@group
|
||||
(ash -5 -2) ; -5 = @r{1 1111 1111 1111 1111 1111 1111 1011}
|
||||
@result{} -2 ; = @r{1 1111 1111 1111 1111 1111 1111 1110}
|
||||
(ash -5 -2) ; -5 = @r{11 1111 1111 1111 1111 1111 1111 1011}
|
||||
@result{} -2 ; = @r{11 1111 1111 1111 1111 1111 1111 1110}
|
||||
@end group
|
||||
@end smallexample
|
||||
@end defun
|
||||
@ -952,23 +953,23 @@ because its binary representation consists entirely of ones. If
|
||||
|
||||
@smallexample
|
||||
@group
|
||||
; @r{ 29-bit binary values}
|
||||
; @r{ 30-bit binary values}
|
||||
|
||||
(logand 14 13) ; 14 = @r{0 0000 0000 0000 0000 0000 0000 1110}
|
||||
; 13 = @r{0 0000 0000 0000 0000 0000 0000 1101}
|
||||
@result{} 12 ; 12 = @r{0 0000 0000 0000 0000 0000 0000 1100}
|
||||
(logand 14 13) ; 14 = @r{00 0000 0000 0000 0000 0000 0000 1110}
|
||||
; 13 = @r{00 0000 0000 0000 0000 0000 0000 1101}
|
||||
@result{} 12 ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100}
|
||||
@end group
|
||||
|
||||
@group
|
||||
(logand 14 13 4) ; 14 = @r{0 0000 0000 0000 0000 0000 0000 1110}
|
||||
; 13 = @r{0 0000 0000 0000 0000 0000 0000 1101}
|
||||
; 4 = @r{0 0000 0000 0000 0000 0000 0000 0100}
|
||||
@result{} 4 ; 4 = @r{0 0000 0000 0000 0000 0000 0000 0100}
|
||||
(logand 14 13 4) ; 14 = @r{00 0000 0000 0000 0000 0000 0000 1110}
|
||||
; 13 = @r{00 0000 0000 0000 0000 0000 0000 1101}
|
||||
; 4 = @r{00 0000 0000 0000 0000 0000 0000 0100}
|
||||
@result{} 4 ; 4 = @r{00 0000 0000 0000 0000 0000 0000 0100}
|
||||
@end group
|
||||
|
||||
@group
|
||||
(logand)
|
||||
@result{} -1 ; -1 = @r{1 1111 1111 1111 1111 1111 1111 1111}
|
||||
@result{} -1 ; -1 = @r{11 1111 1111 1111 1111 1111 1111 1111}
|
||||
@end group
|
||||
@end smallexample
|
||||
@end defun
|
||||
@ -982,18 +983,18 @@ passed just one argument, it returns that argument.
|
||||
|
||||
@smallexample
|
||||
@group
|
||||
; @r{ 29-bit binary values}
|
||||
; @r{ 30-bit binary values}
|
||||
|
||||
(logior 12 5) ; 12 = @r{0 0000 0000 0000 0000 0000 0000 1100}
|
||||
; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101}
|
||||
@result{} 13 ; 13 = @r{0 0000 0000 0000 0000 0000 0000 1101}
|
||||
(logior 12 5) ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100}
|
||||
; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
|
||||
@result{} 13 ; 13 = @r{00 0000 0000 0000 0000 0000 0000 1101}
|
||||
@end group
|
||||
|
||||
@group
|
||||
(logior 12 5 7) ; 12 = @r{0 0000 0000 0000 0000 0000 0000 1100}
|
||||
; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101}
|
||||
; 7 = @r{0 0000 0000 0000 0000 0000 0000 0111}
|
||||
@result{} 15 ; 15 = @r{0 0000 0000 0000 0000 0000 0000 1111}
|
||||
(logior 12 5 7) ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100}
|
||||
; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
|
||||
; 7 = @r{00 0000 0000 0000 0000 0000 0000 0111}
|
||||
@result{} 15 ; 15 = @r{00 0000 0000 0000 0000 0000 0000 1111}
|
||||
@end group
|
||||
@end smallexample
|
||||
@end defun
|
||||
@ -1007,18 +1008,18 @@ result is 0, which is an identity element for this operation. If
|
||||
|
||||
@smallexample
|
||||
@group
|
||||
; @r{ 29-bit binary values}
|
||||
; @r{ 30-bit binary values}
|
||||
|
||||
(logxor 12 5) ; 12 = @r{0 0000 0000 0000 0000 0000 0000 1100}
|
||||
; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101}
|
||||
@result{} 9 ; 9 = @r{0 0000 0000 0000 0000 0000 0000 1001}
|
||||
(logxor 12 5) ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100}
|
||||
; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
|
||||
@result{} 9 ; 9 = @r{00 0000 0000 0000 0000 0000 0000 1001}
|
||||
@end group
|
||||
|
||||
@group
|
||||
(logxor 12 5 7) ; 12 = @r{0 0000 0000 0000 0000 0000 0000 1100}
|
||||
; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101}
|
||||
; 7 = @r{0 0000 0000 0000 0000 0000 0000 0111}
|
||||
@result{} 14 ; 14 = @r{0 0000 0000 0000 0000 0000 0000 1110}
|
||||
(logxor 12 5 7) ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100}
|
||||
; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
|
||||
; 7 = @r{00 0000 0000 0000 0000 0000 0000 0111}
|
||||
@result{} 14 ; 14 = @r{00 0000 0000 0000 0000 0000 0000 1110}
|
||||
@end group
|
||||
@end smallexample
|
||||
@end defun
|
||||
@ -1031,9 +1032,9 @@ bit is one in the result if, and only if, the @var{n}th bit is zero in
|
||||
@example
|
||||
(lognot 5)
|
||||
@result{} -6
|
||||
;; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101}
|
||||
;; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101}
|
||||
;; @r{becomes}
|
||||
;; -6 = @r{1 1111 1111 1111 1111 1111 1111 1010}
|
||||
;; -6 = @r{11 1111 1111 1111 1111 1111 1111 1010}
|
||||
@end example
|
||||
@end defun
|
||||
|
||||
|
@ -165,24 +165,24 @@ latter are unique to Emacs Lisp.
|
||||
@node Integer Type
|
||||
@subsection Integer Type
|
||||
|
||||
The range of values for integers in Emacs Lisp is @minus{}268435456 to
|
||||
268435455 (29 bits; i.e.,
|
||||
The range of values for integers in Emacs Lisp is @minus{}536870912 to
|
||||
536870911 (30 bits; i.e.,
|
||||
@ifnottex
|
||||
-2**28
|
||||
-2**29
|
||||
@end ifnottex
|
||||
@tex
|
||||
@math{-2^{28}}
|
||||
@math{-2^{29}}
|
||||
@end tex
|
||||
to
|
||||
@ifnottex
|
||||
2**28 - 1)
|
||||
2**29 - 1)
|
||||
@end ifnottex
|
||||
@tex
|
||||
@math{2^{28}-1})
|
||||
@math{2^{29}-1})
|
||||
@end tex
|
||||
on most machines. (Some machines may provide a wider range.) It is
|
||||
important to note that the Emacs Lisp arithmetic functions do not check
|
||||
for overflow. Thus @code{(1+ 268435455)} is @minus{}268435456 on most
|
||||
for overflow. Thus @code{(1+ 536870911)} is @minus{}536870912 on most
|
||||
machines.
|
||||
|
||||
The read syntax for integers is a sequence of (base ten) digits with an
|
||||
@ -196,7 +196,7 @@ leading @samp{+} or a final @samp{.}.
|
||||
1 ; @r{The integer 1.}
|
||||
1. ; @r{Also the integer 1.}
|
||||
+1 ; @r{Also the integer 1.}
|
||||
536870913 ; @r{Also the integer 1 on a 29-bit implementation.}
|
||||
1073741825 ; @r{Also the integer 1 on a 30-bit implementation.}
|
||||
@end group
|
||||
@end example
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user