aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2011-06-03 11:49:33 -0700
committerPaul Eggert2011-06-03 11:49:33 -0700
commitbe14b9ab109c8deb5745dc47cbc471e97be06486 (patch)
tree1926a234ed0eabcba764462e4b99c1ea58b2fcb7
parentb047e7acb5d18ccabb7548e3e7d79eba711008bf (diff)
downloademacs-be14b9ab109c8deb5745dc47cbc471e97be06486.tar.gz
emacs-be14b9ab109c8deb5745dc47cbc471e97be06486.zip
Document wide integers better.
* files.texi (File Attributes): Document ino_t values better. * numbers.texi (Integer Basics, Integer Basics, Arithmetic Operations): (Bitwise Operations): * objects.texi (Integer Type): Integers are typically 62 bits now. * os.texi (Time Conversion): Document time_t values better.
-rw-r--r--doc/lispref/ChangeLog9
-rw-r--r--doc/lispref/files.texi11
-rw-r--r--doc/lispref/numbers.texi154
-rw-r--r--doc/lispref/objects.texi25
-rw-r--r--doc/lispref/os.texi8
5 files changed, 108 insertions, 99 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 83cee10f899..16d175c338b 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,12 @@
12011-06-03 Paul Eggert <eggert@cs.ucla.edu>
2
3 Document wide integers better.
4 * files.texi (File Attributes): Document ino_t values better.
5 * numbers.texi (Integer Basics, Integer Basics, Arithmetic Operations):
6 (Bitwise Operations):
7 * objects.texi (Integer Type): Integers are typically 62 bits now.
8 * os.texi (Time Conversion): Document time_t values better.
9
12011-05-31 Lars Magne Ingebrigtsen <larsi@gnus.org> 102011-05-31 Lars Magne Ingebrigtsen <larsi@gnus.org>
2 11
3 * processes.texi (Process Information): Document 12 * processes.texi (Process Information): Document
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index 72f39f681ae..ed282349573 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -1236,12 +1236,13 @@ deleted and recreated; @code{nil} otherwise.
1236 1236
1237@item 1237@item
1238The file's inode number. If possible, this is an integer. If the 1238The file's inode number. If possible, this is an integer. If the
1239inode number is too large to be represented as an integer in Emacs 1239inode number @math{N} is too large to be represented as an integer in
1240Lisp, but still fits into a 32-bit integer, then the value has the 1240Emacs Lisp, but @math{N / 2^16} is representable, then the value has
1241form @code{(@var{high} . @var{low})}, where @var{low} holds the low 16 1241the form @code{(@var{high} . @var{low})}, where @var{high} holds the
1242bits. If the inode is wider than 32 bits, the value is of the form 1242high bits (i.e., excluding the low-order bits) and @var{low} the low
124316 bits. If the inode number is even larger, the value is of the form
1243@code{(@var{high} @var{middle} . @var{low})}, where @code{high} holds 1244@code{(@var{high} @var{middle} . @var{low})}, where @code{high} holds
1244the high 24 bits, @var{middle} the next 24 bits, and @var{low} the low 1245the high bits, @var{middle} the next 24 bits, and @var{low} the low
124516 bits. 124616 bits.
1246 1247
1247@item 1248@item
diff --git a/doc/lispref/numbers.texi b/doc/lispref/numbers.texi
index 2c73a03a26c..ff057c22254 100644
--- a/doc/lispref/numbers.texi
+++ b/doc/lispref/numbers.texi
@@ -36,22 +36,24 @@ exact; they have a fixed, limited amount of precision.
36@section Integer Basics 36@section Integer Basics
37 37
38 The range of values for an integer depends on the machine. The 38 The range of values for an integer depends on the machine. The
39minimum range is @minus{}536870912 to 536870911 (30 bits; i.e., 39typical range is @minus{}2305843009213693952 to 2305843009213693951
40(62 bits; i.e.,
40@ifnottex 41@ifnottex
41-2**29 42-2**61
42@end ifnottex 43@end ifnottex
43@tex 44@tex
44@math{-2^{29}} 45@math{-2^{61}}
45@end tex 46@end tex
46to 47to
47@ifnottex 48@ifnottex
482**29 - 1), 492**61 - 1)
49@end ifnottex 50@end ifnottex
50@tex 51@tex
51@math{2^{29}-1}), 52@math{2^{61}-1})
52@end tex 53@end tex
53but some machines may provide a wider range. Many examples in this 54but some older machines provide only 30 bits. Many examples in this
54chapter assume an integer has 30 bits. 55chapter assume that an integer has 62 bits and that floating point
56numbers are IEEE double precision.
55@cindex overflow 57@cindex overflow
56 58
57 The Lisp reader reads an integer as a sequence of digits with optional 59 The Lisp reader reads an integer as a sequence of digits with optional
@@ -63,7 +65,8 @@ Emacs range is treated as a floating-point number.
63 1. ; @r{The integer 1.} 65 1. ; @r{The integer 1.}
64+1 ; @r{Also the integer 1.} 66+1 ; @r{Also the integer 1.}
65-1 ; @r{The integer @minus{}1.} 67-1 ; @r{The integer @minus{}1.}
66 1073741825 ; @r{The floating point number 1073741825.0.} 68 4611686018427387904
69 ; @r{The floating point number 4.611686018427388e+18.}
67 0 ; @r{The integer 0.} 70 0 ; @r{The integer 0.}
68-0 ; @r{The integer 0.} 71-0 ; @r{The integer 0.}
69@end example 72@end example
@@ -94,25 +97,21 @@ from 2 to 36. For example:
94bitwise operators (@pxref{Bitwise Operations}), it is often helpful to 97bitwise operators (@pxref{Bitwise Operations}), it is often helpful to
95view the numbers in their binary form. 98view the numbers in their binary form.
96 99
97 In 30-bit binary, the decimal integer 5 looks like this: 100 In 62-bit binary, the decimal integer 5 looks like this:
98 101
99@example 102@example
10000 0000 0000 0000 0000 0000 0000 0101 1030000...000101 (62 bits total)
101@end example 104@end example
102 105
103@noindent
104(We have inserted spaces between groups of 4 bits, and two spaces
105between groups of 8 bits, to make the binary integer easier to read.)
106
107 The integer @minus{}1 looks like this: 106 The integer @minus{}1 looks like this:
108 107
109@example 108@example
11011 1111 1111 1111 1111 1111 1111 1111 1091111...111111 (62 bits total)
111@end example 110@end example
112 111
113@noindent 112@noindent
114@cindex two's complement 113@cindex two's complement
115@minus{}1 is represented as 30 ones. (This is called @dfn{two's 114@minus{}1 is represented as 62 ones. (This is called @dfn{two's
116complement} notation.) 115complement} notation.)
117 116
118 The negative integer, @minus{}5, is creating by subtracting 4 from 117 The negative integer, @minus{}5, is creating by subtracting 4 from
@@ -120,24 +119,24 @@ complement} notation.)
120@minus{}5 looks like this: 119@minus{}5 looks like this:
121 120
122@example 121@example
12311 1111 1111 1111 1111 1111 1111 1011 1221111...111011 (62 bits total)
124@end example 123@end example
125 124
126 In this implementation, the largest 30-bit binary integer value is 125 In this implementation, the largest 62-bit binary integer value is
127536,870,911 in decimal. In binary, it looks like this: 1262,305,843,009,213,693,951 in decimal. In binary, it looks like this:
128 127
129@example 128@example
13001 1111 1111 1111 1111 1111 1111 1111 1290111...111111 (62 bits total)
131@end example 130@end example
132 131
133 Since the arithmetic functions do not check whether integers go 132 Since the arithmetic functions do not check whether integers go
134outside their range, when you add 1 to 536,870,911, the value is the 133outside their range, when you add 1 to 2,305,843,009,213,693,951, the value is the
135negative integer @minus{}536,870,912: 134negative integer @minus{}2,305,843,009,213,693,952:
136 135
137@example 136@example
138(+ 1 536870911) 137(+ 1 2305843009213693951)
139 @result{} -536870912 138 @result{} -2305843009213693952
140 @result{} 10 0000 0000 0000 0000 0000 0000 0000 139 @result{} 1000...000000 (62 bits total)
141@end example 140@end example
142 141
143 Many of the functions described in this chapter accept markers for 142 Many of the functions described in this chapter accept markers for
@@ -508,8 +507,8 @@ commonly used.
508if any argument is floating. 507if any argument is floating.
509 508
510 It is important to note that in Emacs Lisp, arithmetic functions 509 It is important to note that in Emacs Lisp, arithmetic functions
511do not check for overflow. Thus @code{(1+ 268435455)} may evaluate to 510do not check for overflow. Thus @code{(1+ 2305843009213693951)} may
512@minus{}268435456, depending on your hardware. 511evaluate to @minus{}2305843009213693952, depending on your hardware.
513 512
514@defun 1+ number-or-marker 513@defun 1+ number-or-marker
515This function returns @var{number-or-marker} plus 1. 514This function returns @var{number-or-marker} plus 1.
@@ -829,19 +828,19 @@ value of a positive integer by two, rounding downward.
829The function @code{lsh}, like all Emacs Lisp arithmetic functions, does 828The function @code{lsh}, like all Emacs Lisp arithmetic functions, does
830not check for overflow, so shifting left can discard significant bits 829not check for overflow, so shifting left can discard significant bits
831and change the sign of the number. For example, left shifting 830and change the sign of the number. For example, left shifting
832536,870,911 produces @minus{}2 on a 30-bit machine: 8312,305,843,009,213,693,951 produces @minus{}2 on a typical machine:
833 832
834@example 833@example
835(lsh 536870911 1) ; @r{left shift} 834(lsh 2305843009213693951 1) ; @r{left shift}
836 @result{} -2 835 @result{} -2
837@end example 836@end example
838 837
839In binary, in the 30-bit implementation, the argument looks like this: 838In binary, in the 62-bit implementation, the argument looks like this:
840 839
841@example 840@example
842@group 841@group
843;; @r{Decimal 536,870,911} 842;; @r{Decimal 2,305,843,009,213,693,951}
84401 1111 1111 1111 1111 1111 1111 1111 8430111...111111 (62 bits total)
845@end group 844@end group
846@end example 845@end example
847 846
@@ -851,7 +850,7 @@ which becomes the following when left shifted:
851@example 850@example
852@group 851@group
853;; @r{Decimal @minus{}2} 852;; @r{Decimal @minus{}2}
85411 1111 1111 1111 1111 1111 1111 1110 8531111...111110 (62 bits total)
855@end group 854@end group
856@end example 855@end example
857@end defun 856@end defun
@@ -874,9 +873,9 @@ looks like this:
874@group 873@group
875(ash -6 -1) @result{} -3 874(ash -6 -1) @result{} -3
876;; @r{Decimal @minus{}6 becomes decimal @minus{}3.} 875;; @r{Decimal @minus{}6 becomes decimal @minus{}3.}
87711 1111 1111 1111 1111 1111 1111 1010 8761111...111010 (62 bits total)
878 @result{} 877 @result{}
87911 1111 1111 1111 1111 1111 1111 1101 8781111...111101 (62 bits total)
880@end group 879@end group
881@end example 880@end example
882 881
@@ -885,11 +884,11 @@ In contrast, shifting the pattern of bits one place to the right with
885 884
886@example 885@example
887@group 886@group
888(lsh -6 -1) @result{} 536870909 887(lsh -6 -1) @result{} 2305843009213693949
889;; @r{Decimal @minus{}6 becomes decimal 536,870,909.} 888;; @r{Decimal @minus{}6 becomes decimal 2,305,843,009,213,693,949.}
89011 1111 1111 1111 1111 1111 1111 1010 8891111...111010 (62 bits total)
891 @result{} 890 @result{}
89201 1111 1111 1111 1111 1111 1111 1101 8910111...111101 (62 bits total)
893@end group 892@end group
894@end example 893@end example
895 894
@@ -899,34 +898,35 @@ Here are other examples:
899@c with smallbook but not with regular book! --rjc 16mar92 898@c with smallbook but not with regular book! --rjc 16mar92
900@smallexample 899@smallexample
901@group 900@group
902 ; @r{ 30-bit binary values} 901 ; @r{ 62-bit binary values}
903 902
904(lsh 5 2) ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101} 903(lsh 5 2) ; 5 = @r{0000...000101}
905 @result{} 20 ; = @r{00 0000 0000 0000 0000 0000 0001 0100} 904 @result{} 20 ; = @r{0000...010100}
906@end group 905@end group
907@group 906@group
908(ash 5 2) 907(ash 5 2)
909 @result{} 20 908 @result{} 20
910(lsh -5 2) ; -5 = @r{11 1111 1111 1111 1111 1111 1111 1011} 909(lsh -5 2) ; -5 = @r{1111...111011}
911 @result{} -20 ; = @r{11 1111 1111 1111 1111 1111 1110 1100} 910 @result{} -20 ; = @r{1111...101100}
912(ash -5 2) 911(ash -5 2)
913 @result{} -20 912 @result{} -20
914@end group 913@end group
915@group 914@group
916(lsh 5 -2) ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101} 915(lsh 5 -2) ; 5 = @r{0000...000101}
917 @result{} 1 ; = @r{00 0000 0000 0000 0000 0000 0000 0001} 916 @result{} 1 ; = @r{0000...000001}
918@end group 917@end group
919@group 918@group
920(ash 5 -2) 919(ash 5 -2)
921 @result{} 1 920 @result{} 1
922@end group 921@end group
923@group 922@group
924(lsh -5 -2) ; -5 = @r{11 1111 1111 1111 1111 1111 1111 1011} 923(lsh -5 -2) ; -5 = @r{1111...111011}
925 @result{} 268435454 ; = @r{00 0111 1111 1111 1111 1111 1111 1110} 924 @result{} 1152921504606846974
925 ; = @r{0011...111110}
926@end group 926@end group
927@group 927@group
928(ash -5 -2) ; -5 = @r{11 1111 1111 1111 1111 1111 1111 1011} 928(ash -5 -2) ; -5 = @r{1111...111011}
929 @result{} -2 ; = @r{11 1111 1111 1111 1111 1111 1111 1110} 929 @result{} -2 ; = @r{1111...111110}
930@end group 930@end group
931@end smallexample 931@end smallexample
932@end defun 932@end defun
@@ -961,23 +961,23 @@ because its binary representation consists entirely of ones. If
961 961
962@smallexample 962@smallexample
963@group 963@group
964 ; @r{ 30-bit binary values} 964 ; @r{ 62-bit binary values}
965 965
966(logand 14 13) ; 14 = @r{00 0000 0000 0000 0000 0000 0000 1110} 966(logand 14 13) ; 14 = @r{0000...001110}
967 ; 13 = @r{00 0000 0000 0000 0000 0000 0000 1101} 967 ; 13 = @r{0000...001101}
968 @result{} 12 ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100} 968 @result{} 12 ; 12 = @r{0000...001100}
969@end group 969@end group
970 970
971@group 971@group
972(logand 14 13 4) ; 14 = @r{00 0000 0000 0000 0000 0000 0000 1110} 972(logand 14 13 4) ; 14 = @r{0000...001110}
973 ; 13 = @r{00 0000 0000 0000 0000 0000 0000 1101} 973 ; 13 = @r{0000...001101}
974 ; 4 = @r{00 0000 0000 0000 0000 0000 0000 0100} 974 ; 4 = @r{0000...000100}
975 @result{} 4 ; 4 = @r{00 0000 0000 0000 0000 0000 0000 0100} 975 @result{} 4 ; 4 = @r{0000...000100}
976@end group 976@end group
977 977
978@group 978@group
979(logand) 979(logand)
980 @result{} -1 ; -1 = @r{11 1111 1111 1111 1111 1111 1111 1111} 980 @result{} -1 ; -1 = @r{1111...111111}
981@end group 981@end group
982@end smallexample 982@end smallexample
983@end defun 983@end defun
@@ -991,18 +991,18 @@ passed just one argument, it returns that argument.
991 991
992@smallexample 992@smallexample
993@group 993@group
994 ; @r{ 30-bit binary values} 994 ; @r{ 62-bit binary values}
995 995
996(logior 12 5) ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100} 996(logior 12 5) ; 12 = @r{0000...001100}
997 ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101} 997 ; 5 = @r{0000...000101}
998 @result{} 13 ; 13 = @r{00 0000 0000 0000 0000 0000 0000 1101} 998 @result{} 13 ; 13 = @r{0000...001101}
999@end group 999@end group
1000 1000
1001@group 1001@group
1002(logior 12 5 7) ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100} 1002(logior 12 5 7) ; 12 = @r{0000...001100}
1003 ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101} 1003 ; 5 = @r{0000...000101}
1004 ; 7 = @r{00 0000 0000 0000 0000 0000 0000 0111} 1004 ; 7 = @r{0000...000111}
1005 @result{} 15 ; 15 = @r{00 0000 0000 0000 0000 0000 0000 1111} 1005 @result{} 15 ; 15 = @r{0000...001111}
1006@end group 1006@end group
1007@end smallexample 1007@end smallexample
1008@end defun 1008@end defun
@@ -1016,18 +1016,18 @@ result is 0, which is an identity element for this operation. If
1016 1016
1017@smallexample 1017@smallexample
1018@group 1018@group
1019 ; @r{ 30-bit binary values} 1019 ; @r{ 62-bit binary values}
1020 1020
1021(logxor 12 5) ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100} 1021(logxor 12 5) ; 12 = @r{0000...001100}
1022 ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101} 1022 ; 5 = @r{0000...000101}
1023 @result{} 9 ; 9 = @r{00 0000 0000 0000 0000 0000 0000 1001} 1023 @result{} 9 ; 9 = @r{0000...001001}
1024@end group 1024@end group
1025 1025
1026@group 1026@group
1027(logxor 12 5 7) ; 12 = @r{00 0000 0000 0000 0000 0000 0000 1100} 1027(logxor 12 5 7) ; 12 = @r{0000...001100}
1028 ; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101} 1028 ; 5 = @r{0000...000101}
1029 ; 7 = @r{00 0000 0000 0000 0000 0000 0000 0111} 1029 ; 7 = @r{0000...000111}
1030 @result{} 14 ; 14 = @r{00 0000 0000 0000 0000 0000 0000 1110} 1030 @result{} 14 ; 14 = @r{0000...001110}
1031@end group 1031@end group
1032@end smallexample 1032@end smallexample
1033@end defun 1033@end defun
@@ -1040,9 +1040,9 @@ bit is one in the result if, and only if, the @var{n}th bit is zero in
1040@example 1040@example
1041(lognot 5) 1041(lognot 5)
1042 @result{} -6 1042 @result{} -6
1043;; 5 = @r{00 0000 0000 0000 0000 0000 0000 0101} 1043;; 5 = @r{0000...000101} (62 bits total)
1044;; @r{becomes} 1044;; @r{becomes}
1045;; -6 = @r{11 1111 1111 1111 1111 1111 1111 1010} 1045;; -6 = @r{1111...111010} (62 bits total)
1046@end example 1046@end example
1047@end defun 1047@end defun
1048 1048
diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi
index c58d54f13fc..d5aa51098e7 100644
--- a/doc/lispref/objects.texi
+++ b/doc/lispref/objects.texi
@@ -164,25 +164,25 @@ latter are unique to Emacs Lisp.
164@node Integer Type 164@node Integer Type
165@subsection Integer Type 165@subsection Integer Type
166 166
167 The range of values for integers in Emacs Lisp is @minus{}536870912 to 167 The range of values for integers in Emacs Lisp is
168536870911 (30 bits; i.e., 168@minus{}2305843009213693952 to 2305843009213693951 (62 bits; i.e.,
169@ifnottex 169@ifnottex
170-2**29 170-2**61
171@end ifnottex 171@end ifnottex
172@tex 172@tex
173@math{-2^{29}} 173@math{-2^{61}}
174@end tex 174@end tex
175to 175to
176@ifnottex 176@ifnottex
1772**29 - 1) 1772**61 - 1)
178@end ifnottex 178@end ifnottex
179@tex 179@tex
180@math{2^{29}-1}) 180@math{2^{61}-1})
181@end tex 181@end tex
182on most machines. (Some machines may provide a wider range.) It is 182on most machines. Some machines may provide a narrower or wider
183important to note that the Emacs Lisp arithmetic functions do not check 183range; all machines provide at least 30 bits. Emacs Lisp arithmetic
184for overflow. Thus @code{(1+ 536870911)} is @minus{}536870912 on most 184functions do not check for overflow. Thus @code{(1+
185machines. 1852305843009213693951)} is @minus{}2305843009213693952 on most machines.
186 186
187 The read syntax for integers is a sequence of (base ten) digits with an 187 The read syntax for integers is a sequence of (base ten) digits with an
188optional sign at the beginning and an optional period at the end. The 188optional sign at the beginning and an optional period at the end. The
@@ -195,7 +195,6 @@ leading @samp{+} or a final @samp{.}.
1951 ; @r{The integer 1.} 1951 ; @r{The integer 1.}
1961. ; @r{Also the integer 1.} 1961. ; @r{Also the integer 1.}
197+1 ; @r{Also the integer 1.} 197+1 ; @r{Also the integer 1.}
1981073741825 ; @r{Also the integer 1 on a 30-bit implementation.}
199@end group 198@end group
200@end example 199@end example
201 200
@@ -203,8 +202,8 @@ leading @samp{+} or a final @samp{.}.
203As a special exception, if a sequence of digits specifies an integer 202As a special exception, if a sequence of digits specifies an integer
204too large or too small to be a valid integer object, the Lisp reader 203too large or too small to be a valid integer object, the Lisp reader
205reads it as a floating-point number (@pxref{Floating Point Type}). 204reads it as a floating-point number (@pxref{Floating Point Type}).
206For instance, on most machines @code{536870912} is read as the 205For instance, on most machines @code{2305843009213693952} is read as the
207floating-point number @code{536870912.0}. 206floating-point number @code{2.305843009213694e+18}.
208 207
209 @xref{Numbers}, for more information. 208 @xref{Numbers}, for more information.
210 209
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index b226d676462..5f422065c5b 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -1193,11 +1193,11 @@ to calendrical information and vice versa. You can get time values
1193from the functions @code{current-time} (@pxref{Time of Day}) and 1193from the functions @code{current-time} (@pxref{Time of Day}) and
1194@code{file-attributes} (@pxref{Definition of file-attributes}). 1194@code{file-attributes} (@pxref{Definition of file-attributes}).
1195 1195
1196 Many operating systems are limited to time values that contain 32 bits 1196 Many 32-bit operating systems are limited to time values that contain 32 bits
1197of information; these systems typically handle only the times from 1197of information; these systems typically handle only the times from
11981901-12-13 20:45:52 UTC through 2038-01-19 03:14:07 UTC. However, some 11981901-12-13 20:45:52 UTC through 2038-01-19 03:14:07 UTC. However, 64-bit
1199operating systems have larger time values, and can represent times far 1199and some 32-bit operating systems have larger time values, and can
1200in the past or future. 1200represent times far in the past or future.
1201 1201
1202 Time conversion functions always use the Gregorian calendar, even 1202 Time conversion functions always use the Gregorian calendar, even
1203for dates before the Gregorian calendar was introduced. Year numbers 1203for dates before the Gregorian calendar was introduced. Year numbers