diff options
| author | Stefan Monnier | 2003-10-20 21:38:50 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2003-10-20 21:38:50 +0000 |
| commit | e1e44180c1cfb20f00bc5c9db4d068746e9c7f73 (patch) | |
| tree | c7aacd4beed21178b179e6c7726a65e12b469ec7 | |
| parent | b1664339f4c1adac3f5d1e9a99c3850a28346100 (diff) | |
| download | emacs-e1e44180c1cfb20f00bc5c9db4d068746e9c7f73.tar.gz emacs-e1e44180c1cfb20f00bc5c9db4d068746e9c7f73.zip | |
Update for extra bit of integer range.
| -rw-r--r-- | lispref/numbers.texi | 144 |
1 files changed, 72 insertions, 72 deletions
diff --git a/lispref/numbers.texi b/lispref/numbers.texi index 177b229e160..3dc686f452a 100644 --- a/lispref/numbers.texi +++ b/lispref/numbers.texi | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | @c -*-texinfo-*- | 1 | @c -*-texinfo-*- |
| 2 | @c This is part of the GNU Emacs Lisp Reference Manual. | 2 | @c This is part of the GNU Emacs Lisp Reference Manual. |
| 3 | @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999 | 3 | @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2003 |
| 4 | @c Free Software Foundation, Inc. | 4 | @c Free Software Foundation, Inc. |
| 5 | @c See the file elisp.texi for copying conditions. | 5 | @c See the file elisp.texi for copying conditions. |
| 6 | @setfilename ../info/numbers | 6 | @setfilename ../info/numbers |
| @@ -36,22 +36,22 @@ 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 |
| 39 | minimum range is @minus{}134217728 to 134217727 (28 bits; i.e., | 39 | minimum range is @minus{}268435456 to 268435455 (29 bits; i.e., |
| 40 | @ifnottex | 40 | @ifnottex |
| 41 | -2**27 | 41 | -2**28 |
| 42 | @end ifnottex | 42 | @end ifnottex |
| 43 | @tex | 43 | @tex |
| 44 | @math{-2^{27}} | 44 | @math{-2^{28}} |
| 45 | @end tex | 45 | @end tex |
| 46 | to | 46 | to |
| 47 | @ifnottex | 47 | @ifnottex |
| 48 | 2**27 - 1), | 48 | 2**28 - 1), |
| 49 | @end ifnottex | 49 | @end ifnottex |
| 50 | @tex | 50 | @tex |
| 51 | @math{2^{27}-1}), | 51 | @math{2^{28}-1}), |
| 52 | @end tex | 52 | @end tex |
| 53 | but some machines may provide a wider range. Many examples in this | 53 | but some machines may provide a wider range. Many examples in this |
| 54 | chapter assume an integer has 28 bits. | 54 | chapter assume an integer has 29 bits. |
| 55 | @cindex overflow | 55 | @cindex overflow |
| 56 | 56 | ||
| 57 | The Lisp reader reads an integer as a sequence of digits with optional | 57 | The Lisp reader reads an integer as a sequence of digits with optional |
| @@ -86,10 +86,10 @@ inclusively). Case is not significant for the letter after @samp{#} | |||
| 86 | bitwise operators (@pxref{Bitwise Operations}), it is often helpful to | 86 | bitwise operators (@pxref{Bitwise Operations}), it is often helpful to |
| 87 | view the numbers in their binary form. | 87 | view the numbers in their binary form. |
| 88 | 88 | ||
| 89 | In 28-bit binary, the decimal integer 5 looks like this: | 89 | In 29-bit binary, the decimal integer 5 looks like this: |
| 90 | 90 | ||
| 91 | @example | 91 | @example |
| 92 | 0000 0000 0000 0000 0000 0000 0101 | 92 | 0 0000 0000 0000 0000 0000 0000 0101 |
| 93 | @end example | 93 | @end example |
| 94 | 94 | ||
| 95 | @noindent | 95 | @noindent |
| @@ -99,12 +99,12 @@ between groups of 8 bits, to make the binary integer easier to read.) | |||
| 99 | The integer @minus{}1 looks like this: | 99 | The integer @minus{}1 looks like this: |
| 100 | 100 | ||
| 101 | @example | 101 | @example |
| 102 | 1111 1111 1111 1111 1111 1111 1111 | 102 | 1 1111 1111 1111 1111 1111 1111 1111 |
| 103 | @end example | 103 | @end example |
| 104 | 104 | ||
| 105 | @noindent | 105 | @noindent |
| 106 | @cindex two's complement | 106 | @cindex two's complement |
| 107 | @minus{}1 is represented as 28 ones. (This is called @dfn{two's | 107 | @minus{}1 is represented as 29 ones. (This is called @dfn{two's |
| 108 | complement} notation.) | 108 | complement} notation.) |
| 109 | 109 | ||
| 110 | The negative integer, @minus{}5, is creating by subtracting 4 from | 110 | The negative integer, @minus{}5, is creating by subtracting 4 from |
| @@ -112,24 +112,24 @@ complement} notation.) | |||
| 112 | @minus{}5 looks like this: | 112 | @minus{}5 looks like this: |
| 113 | 113 | ||
| 114 | @example | 114 | @example |
| 115 | 1111 1111 1111 1111 1111 1111 1011 | 115 | 1 1111 1111 1111 1111 1111 1111 1011 |
| 116 | @end example | 116 | @end example |
| 117 | 117 | ||
| 118 | In this implementation, the largest 28-bit binary integer value is | 118 | In this implementation, the largest 29-bit binary integer value is |
| 119 | 134,217,727 in decimal. In binary, it looks like this: | 119 | 268,435,455 in decimal. In binary, it looks like this: |
| 120 | 120 | ||
| 121 | @example | 121 | @example |
| 122 | 0111 1111 1111 1111 1111 1111 1111 | 122 | 0 1111 1111 1111 1111 1111 1111 1111 |
| 123 | @end example | 123 | @end example |
| 124 | 124 | ||
| 125 | Since the arithmetic functions do not check whether integers go | 125 | Since the arithmetic functions do not check whether integers go |
| 126 | outside their range, when you add 1 to 134,217,727, the value is the | 126 | outside their range, when you add 1 to 268,435,455, the value is the |
| 127 | negative integer @minus{}134,217,728: | 127 | negative integer @minus{}268,435,456: |
| 128 | 128 | ||
| 129 | @example | 129 | @example |
| 130 | (+ 1 134217727) | 130 | (+ 1 268435455) |
| 131 | @result{} -134217728 | 131 | @result{} -268435456 |
| 132 | @result{} 1000 0000 0000 0000 0000 0000 0000 | 132 | @result{} 1 0000 0000 0000 0000 0000 0000 0000 |
| 133 | @end example | 133 | @end example |
| 134 | 134 | ||
| 135 | Many of the functions described in this chapter accept markers for | 135 | Many of the functions described in this chapter accept markers for |
| @@ -468,8 +468,8 @@ commonly used. | |||
| 468 | if any argument is floating. | 468 | if any argument is floating. |
| 469 | 469 | ||
| 470 | It is important to note that in Emacs Lisp, arithmetic functions | 470 | It is important to note that in Emacs Lisp, arithmetic functions |
| 471 | do not check for overflow. Thus @code{(1+ 134217727)} may evaluate to | 471 | do not check for overflow. Thus @code{(1+ 268435455)} may evaluate to |
| 472 | @minus{}134217728, depending on your hardware. | 472 | @minus{}268435456, depending on your hardware. |
| 473 | 473 | ||
| 474 | @defun 1+ number-or-marker | 474 | @defun 1+ number-or-marker |
| 475 | This function returns @var{number-or-marker} plus 1. | 475 | This function returns @var{number-or-marker} plus 1. |
| @@ -788,19 +788,19 @@ value of a positive integer by two, rounding downward. | |||
| 788 | The function @code{lsh}, like all Emacs Lisp arithmetic functions, does | 788 | The function @code{lsh}, like all Emacs Lisp arithmetic functions, does |
| 789 | not check for overflow, so shifting left can discard significant bits | 789 | not check for overflow, so shifting left can discard significant bits |
| 790 | and change the sign of the number. For example, left shifting | 790 | and change the sign of the number. For example, left shifting |
| 791 | 134,217,727 produces @minus{}2 on a 28-bit machine: | 791 | 268,435,455 produces @minus{}2 on a 29-bit machine: |
| 792 | 792 | ||
| 793 | @example | 793 | @example |
| 794 | (lsh 134217727 1) ; @r{left shift} | 794 | (lsh 268435455 1) ; @r{left shift} |
| 795 | @result{} -2 | 795 | @result{} -2 |
| 796 | @end example | 796 | @end example |
| 797 | 797 | ||
| 798 | In binary, in the 28-bit implementation, the argument looks like this: | 798 | In binary, in the 29-bit implementation, the argument looks like this: |
| 799 | 799 | ||
| 800 | @example | 800 | @example |
| 801 | @group | 801 | @group |
| 802 | ;; @r{Decimal 134,217,727} | 802 | ;; @r{Decimal 268,435,455} |
| 803 | 0111 1111 1111 1111 1111 1111 1111 | 803 | 0 1111 1111 1111 1111 1111 1111 1111 |
| 804 | @end group | 804 | @end group |
| 805 | @end example | 805 | @end example |
| 806 | 806 | ||
| @@ -810,7 +810,7 @@ which becomes the following when left shifted: | |||
| 810 | @example | 810 | @example |
| 811 | @group | 811 | @group |
| 812 | ;; @r{Decimal @minus{}2} | 812 | ;; @r{Decimal @minus{}2} |
| 813 | 1111 1111 1111 1111 1111 1111 1110 | 813 | 1 1111 1111 1111 1111 1111 1111 1110 |
| 814 | @end group | 814 | @end group |
| 815 | @end example | 815 | @end example |
| 816 | @end defun | 816 | @end defun |
| @@ -833,9 +833,9 @@ looks like this: | |||
| 833 | @group | 833 | @group |
| 834 | (ash -6 -1) @result{} -3 | 834 | (ash -6 -1) @result{} -3 |
| 835 | ;; @r{Decimal @minus{}6 becomes decimal @minus{}3.} | 835 | ;; @r{Decimal @minus{}6 becomes decimal @minus{}3.} |
| 836 | 1111 1111 1111 1111 1111 1111 1010 | 836 | 1 1111 1111 1111 1111 1111 1111 1010 |
| 837 | @result{} | 837 | @result{} |
| 838 | 1111 1111 1111 1111 1111 1111 1101 | 838 | 1 1111 1111 1111 1111 1111 1111 1101 |
| 839 | @end group | 839 | @end group |
| 840 | @end example | 840 | @end example |
| 841 | 841 | ||
| @@ -844,11 +844,11 @@ In contrast, shifting the pattern of bits one place to the right with | |||
| 844 | 844 | ||
| 845 | @example | 845 | @example |
| 846 | @group | 846 | @group |
| 847 | (lsh -6 -1) @result{} 134217725 | 847 | (lsh -6 -1) @result{} 268435453 |
| 848 | ;; @r{Decimal @minus{}6 becomes decimal 134,217,725.} | 848 | ;; @r{Decimal @minus{}6 becomes decimal 268,435,453.} |
| 849 | 1111 1111 1111 1111 1111 1111 1010 | 849 | 1 1111 1111 1111 1111 1111 1111 1010 |
| 850 | @result{} | 850 | @result{} |
| 851 | 0111 1111 1111 1111 1111 1111 1101 | 851 | 0 1111 1111 1111 1111 1111 1111 1101 |
| 852 | @end group | 852 | @end group |
| 853 | @end example | 853 | @end example |
| 854 | 854 | ||
| @@ -858,34 +858,34 @@ Here are other examples: | |||
| 858 | @c with smallbook but not with regular book! --rjc 16mar92 | 858 | @c with smallbook but not with regular book! --rjc 16mar92 |
| 859 | @smallexample | 859 | @smallexample |
| 860 | @group | 860 | @group |
| 861 | ; @r{ 28-bit binary values} | 861 | ; @r{ 29-bit binary values} |
| 862 | 862 | ||
| 863 | (lsh 5 2) ; 5 = @r{0000 0000 0000 0000 0000 0000 0101} | 863 | (lsh 5 2) ; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101} |
| 864 | @result{} 20 ; = @r{0000 0000 0000 0000 0000 0001 0100} | 864 | @result{} 20 ; = @r{0 0000 0000 0000 0000 0000 0001 0100} |
| 865 | @end group | 865 | @end group |
| 866 | @group | 866 | @group |
| 867 | (ash 5 2) | 867 | (ash 5 2) |
| 868 | @result{} 20 | 868 | @result{} 20 |
| 869 | (lsh -5 2) ; -5 = @r{1111 1111 1111 1111 1111 1111 1011} | 869 | (lsh -5 2) ; -5 = @r{1 1111 1111 1111 1111 1111 1111 1011} |
| 870 | @result{} -20 ; = @r{1111 1111 1111 1111 1111 1110 1100} | 870 | @result{} -20 ; = @r{1 1111 1111 1111 1111 1111 1110 1100} |
| 871 | (ash -5 2) | 871 | (ash -5 2) |
| 872 | @result{} -20 | 872 | @result{} -20 |
| 873 | @end group | 873 | @end group |
| 874 | @group | 874 | @group |
| 875 | (lsh 5 -2) ; 5 = @r{0000 0000 0000 0000 0000 0000 0101} | 875 | (lsh 5 -2) ; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101} |
| 876 | @result{} 1 ; = @r{0000 0000 0000 0000 0000 0000 0001} | 876 | @result{} 1 ; = @r{0 0000 0000 0000 0000 0000 0000 0001} |
| 877 | @end group | 877 | @end group |
| 878 | @group | 878 | @group |
| 879 | (ash 5 -2) | 879 | (ash 5 -2) |
| 880 | @result{} 1 | 880 | @result{} 1 |
| 881 | @end group | 881 | @end group |
| 882 | @group | 882 | @group |
| 883 | (lsh -5 -2) ; -5 = @r{1111 1111 1111 1111 1111 1111 1011} | 883 | (lsh -5 -2) ; -5 = @r{1 1111 1111 1111 1111 1111 1111 1011} |
| 884 | @result{} 4194302 ; = @r{0011 1111 1111 1111 1111 1111 1110} | 884 | @result{} 134217726 ; = @r{0 0111 1111 1111 1111 1111 1111 1110} |
| 885 | @end group | 885 | @end group |
| 886 | @group | 886 | @group |
| 887 | (ash -5 -2) ; -5 = @r{1111 1111 1111 1111 1111 1111 1011} | 887 | (ash -5 -2) ; -5 = @r{1 1111 1111 1111 1111 1111 1111 1011} |
| 888 | @result{} -2 ; = @r{1111 1111 1111 1111 1111 1111 1110} | 888 | @result{} -2 ; = @r{1 1111 1111 1111 1111 1111 1111 1110} |
| 889 | @end group | 889 | @end group |
| 890 | @end smallexample | 890 | @end smallexample |
| 891 | @end defun | 891 | @end defun |
| @@ -922,23 +922,23 @@ because its binary representation consists entirely of ones. If | |||
| 922 | 922 | ||
| 923 | @smallexample | 923 | @smallexample |
| 924 | @group | 924 | @group |
| 925 | ; @r{ 28-bit binary values} | 925 | ; @r{ 29-bit binary values} |
| 926 | 926 | ||
| 927 | (logand 14 13) ; 14 = @r{0000 0000 0000 0000 0000 0000 1110} | 927 | (logand 14 13) ; 14 = @r{0 0000 0000 0000 0000 0000 0000 1110} |
| 928 | ; 13 = @r{0000 0000 0000 0000 0000 0000 1101} | 928 | ; 13 = @r{0 0000 0000 0000 0000 0000 0000 1101} |
| 929 | @result{} 12 ; 12 = @r{0000 0000 0000 0000 0000 0000 1100} | 929 | @result{} 12 ; 12 = @r{0 0000 0000 0000 0000 0000 0000 1100} |
| 930 | @end group | 930 | @end group |
| 931 | 931 | ||
| 932 | @group | 932 | @group |
| 933 | (logand 14 13 4) ; 14 = @r{0000 0000 0000 0000 0000 0000 1110} | 933 | (logand 14 13 4) ; 14 = @r{0 0000 0000 0000 0000 0000 0000 1110} |
| 934 | ; 13 = @r{0000 0000 0000 0000 0000 0000 1101} | 934 | ; 13 = @r{0 0000 0000 0000 0000 0000 0000 1101} |
| 935 | ; 4 = @r{0000 0000 0000 0000 0000 0000 0100} | 935 | ; 4 = @r{0 0000 0000 0000 0000 0000 0000 0100} |
| 936 | @result{} 4 ; 4 = @r{0000 0000 0000 0000 0000 0000 0100} | 936 | @result{} 4 ; 4 = @r{0 0000 0000 0000 0000 0000 0000 0100} |
| 937 | @end group | 937 | @end group |
| 938 | 938 | ||
| 939 | @group | 939 | @group |
| 940 | (logand) | 940 | (logand) |
| 941 | @result{} -1 ; -1 = @r{1111 1111 1111 1111 1111 1111 1111} | 941 | @result{} -1 ; -1 = @r{1 1111 1111 1111 1111 1111 1111 1111} |
| 942 | @end group | 942 | @end group |
| 943 | @end smallexample | 943 | @end smallexample |
| 944 | @end defun | 944 | @end defun |
| @@ -954,18 +954,18 @@ passed just one argument, it returns that argument. | |||
| 954 | 954 | ||
| 955 | @smallexample | 955 | @smallexample |
| 956 | @group | 956 | @group |
| 957 | ; @r{ 28-bit binary values} | 957 | ; @r{ 29-bit binary values} |
| 958 | 958 | ||
| 959 | (logior 12 5) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100} | 959 | (logior 12 5) ; 12 = @r{0 0000 0000 0000 0000 0000 0000 1100} |
| 960 | ; 5 = @r{0000 0000 0000 0000 0000 0000 0101} | 960 | ; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101} |
| 961 | @result{} 13 ; 13 = @r{0000 0000 0000 0000 0000 0000 1101} | 961 | @result{} 13 ; 13 = @r{0 0000 0000 0000 0000 0000 0000 1101} |
| 962 | @end group | 962 | @end group |
| 963 | 963 | ||
| 964 | @group | 964 | @group |
| 965 | (logior 12 5 7) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100} | 965 | (logior 12 5 7) ; 12 = @r{0 0000 0000 0000 0000 0000 0000 1100} |
| 966 | ; 5 = @r{0000 0000 0000 0000 0000 0000 0101} | 966 | ; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101} |
| 967 | ; 7 = @r{0000 0000 0000 0000 0000 0000 0111} | 967 | ; 7 = @r{0 0000 0000 0000 0000 0000 0000 0111} |
| 968 | @result{} 15 ; 15 = @r{0000 0000 0000 0000 0000 0000 1111} | 968 | @result{} 15 ; 15 = @r{0 0000 0000 0000 0000 0000 0000 1111} |
| 969 | @end group | 969 | @end group |
| 970 | @end smallexample | 970 | @end smallexample |
| 971 | @end defun | 971 | @end defun |
| @@ -981,18 +981,18 @@ result is 0, which is an identity element for this operation. If | |||
| 981 | 981 | ||
| 982 | @smallexample | 982 | @smallexample |
| 983 | @group | 983 | @group |
| 984 | ; @r{ 28-bit binary values} | 984 | ; @r{ 29-bit binary values} |
| 985 | 985 | ||
| 986 | (logxor 12 5) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100} | 986 | (logxor 12 5) ; 12 = @r{0 0000 0000 0000 0000 0000 0000 1100} |
| 987 | ; 5 = @r{0000 0000 0000 0000 0000 0000 0101} | 987 | ; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101} |
| 988 | @result{} 9 ; 9 = @r{0000 0000 0000 0000 0000 0000 1001} | 988 | @result{} 9 ; 9 = @r{0 0000 0000 0000 0000 0000 0000 1001} |
| 989 | @end group | 989 | @end group |
| 990 | 990 | ||
| 991 | @group | 991 | @group |
| 992 | (logxor 12 5 7) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100} | 992 | (logxor 12 5 7) ; 12 = @r{0 0000 0000 0000 0000 0000 0000 1100} |
| 993 | ; 5 = @r{0000 0000 0000 0000 0000 0000 0101} | 993 | ; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101} |
| 994 | ; 7 = @r{0000 0000 0000 0000 0000 0000 0111} | 994 | ; 7 = @r{0 0000 0000 0000 0000 0000 0000 0111} |
| 995 | @result{} 14 ; 14 = @r{0000 0000 0000 0000 0000 0000 1110} | 995 | @result{} 14 ; 14 = @r{0 0000 0000 0000 0000 0000 0000 1110} |
| 996 | @end group | 996 | @end group |
| 997 | @end smallexample | 997 | @end smallexample |
| 998 | @end defun | 998 | @end defun |
| @@ -1007,9 +1007,9 @@ bit is one in the result if, and only if, the @var{n}th bit is zero in | |||
| 1007 | @example | 1007 | @example |
| 1008 | (lognot 5) | 1008 | (lognot 5) |
| 1009 | @result{} -6 | 1009 | @result{} -6 |
| 1010 | ;; 5 = @r{0000 0000 0000 0000 0000 0000 0101} | 1010 | ;; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101} |
| 1011 | ;; @r{becomes} | 1011 | ;; @r{becomes} |
| 1012 | ;; -6 = @r{1111 1111 1111 1111 1111 1111 1010} | 1012 | ;; -6 = @r{1 1111 1111 1111 1111 1111 1111 1010} |
| 1013 | @end example | 1013 | @end example |
| 1014 | @end defun | 1014 | @end defun |
| 1015 | 1015 | ||