diff options
| author | Richard M. Stallman | 1995-01-02 06:51:21 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-01-02 06:51:21 +0000 |
| commit | 8be5e0fcc3559112ef6c047fcb68132961b1081c (patch) | |
| tree | dccba81822e4e988c8652a4e57692414bc3d1f02 | |
| parent | 32ce36ad51e3c0eb7a7c2eabe8ee88cf489dd02d (diff) | |
| download | emacs-8be5e0fcc3559112ef6c047fcb68132961b1081c.tar.gz emacs-8be5e0fcc3559112ef6c047fcb68132961b1081c.zip | |
Integers now at least 28 bits.
| -rw-r--r-- | lispref/numbers.texi | 142 |
1 files changed, 72 insertions, 70 deletions
diff --git a/lispref/numbers.texi b/lispref/numbers.texi index b083d73c4aa..dec1af1c93f 100644 --- a/lispref/numbers.texi +++ b/lispref/numbers.texi | |||
| @@ -39,23 +39,22 @@ where Emacs does not support them. | |||
| 39 | @section Integer Basics | 39 | @section Integer Basics |
| 40 | 40 | ||
| 41 | The range of values for an integer depends on the machine. The | 41 | The range of values for an integer depends on the machine. The |
| 42 | range is @minus{}8388608 to 8388607 (24 bits; i.e., | 42 | range is @minus{}8388608 to 8388607 (28 bits; i.e., |
| 43 | @ifinfo | 43 | @ifinfo |
| 44 | -2**23 | 44 | -2**27 |
| 45 | @end ifinfo | 45 | @end ifinfo |
| 46 | @tex | 46 | @tex |
| 47 | $-2^{23}$ | 47 | $-2^{27}$ |
| 48 | @end tex | 48 | @end tex |
| 49 | to | 49 | to |
| 50 | @ifinfo | 50 | @ifinfo |
| 51 | 2**23 - 1) | 51 | 2**27 - 1) |
| 52 | @end ifinfo | 52 | @end ifinfo |
| 53 | @tex | 53 | @tex |
| 54 | $2^{23}-1$) | 54 | $2^{27}-1$) |
| 55 | @end tex | 55 | @end tex |
| 56 | on most machines, but on others it is @minus{}16777216 to 16777215 (25 | 56 | on most machines, but some machines may have a wider range. Many |
| 57 | bits), or @minus{}33554432 to 33554431 (26 bits). Many examples in this | 57 | examples in this chapter assume an integer has 28 bits. |
| 58 | chapter assume an integer has 24 bits. | ||
| 59 | @cindex overflow | 58 | @cindex overflow |
| 60 | 59 | ||
| 61 | The Lisp reader reads an integer as a sequence of digits with optional | 60 | The Lisp reader reads an integer as a sequence of digits with optional |
| @@ -66,7 +65,7 @@ initial sign and optional final period. | |||
| 66 | 1. ; @r{The integer 1.} | 65 | 1. ; @r{The integer 1.} |
| 67 | +1 ; @r{Also the integer 1.} | 66 | +1 ; @r{Also the integer 1.} |
| 68 | -1 ; @r{The integer @minus{}1.} | 67 | -1 ; @r{The integer @minus{}1.} |
| 69 | 16777217 ; @r{Also the integer 1, due to overflow.} | 68 | 268435457 ; @r{Also the integer 1, due to overflow.} |
| 70 | 0 ; @r{The integer 0.} | 69 | 0 ; @r{The integer 0.} |
| 71 | -0 ; @r{The integer 0.} | 70 | -0 ; @r{The integer 0.} |
| 72 | @end example | 71 | @end example |
| @@ -75,10 +74,10 @@ initial sign and optional final period. | |||
| 75 | bitwise operators (@pxref{Bitwise Operations}), it is often helpful to | 74 | bitwise operators (@pxref{Bitwise Operations}), it is often helpful to |
| 76 | view the numbers in their binary form. | 75 | view the numbers in their binary form. |
| 77 | 76 | ||
| 78 | In 24-bit binary, the decimal integer 5 looks like this: | 77 | In 28-bit binary, the decimal integer 5 looks like this: |
| 79 | 78 | ||
| 80 | @example | 79 | @example |
| 81 | 0000 0000 0000 0000 0000 0101 | 80 | 0000 0000 0000 0000 0000 0000 0101 |
| 82 | @end example | 81 | @end example |
| 83 | 82 | ||
| 84 | @noindent | 83 | @noindent |
| @@ -88,12 +87,12 @@ between groups of 8 bits, to make the binary integer easier to read.) | |||
| 88 | The integer @minus{}1 looks like this: | 87 | The integer @minus{}1 looks like this: |
| 89 | 88 | ||
| 90 | @example | 89 | @example |
| 91 | 1111 1111 1111 1111 1111 1111 | 90 | 1111 1111 1111 1111 1111 1111 1111 |
| 92 | @end example | 91 | @end example |
| 93 | 92 | ||
| 94 | @noindent | 93 | @noindent |
| 95 | @cindex two's complement | 94 | @cindex two's complement |
| 96 | @minus{}1 is represented as 24 ones. (This is called @dfn{two's | 95 | @minus{}1 is represented as 28 ones. (This is called @dfn{two's |
| 97 | complement} notation.) | 96 | complement} notation.) |
| 98 | 97 | ||
| 99 | The negative integer, @minus{}5, is creating by subtracting 4 from | 98 | The negative integer, @minus{}5, is creating by subtracting 4 from |
| @@ -101,24 +100,24 @@ complement} notation.) | |||
| 101 | @minus{}5 looks like this: | 100 | @minus{}5 looks like this: |
| 102 | 101 | ||
| 103 | @example | 102 | @example |
| 104 | 1111 1111 1111 1111 1111 1011 | 103 | 1111 1111 1111 1111 1111 1111 1011 |
| 105 | @end example | 104 | @end example |
| 106 | 105 | ||
| 107 | In this implementation, the largest 24-bit binary integer is the | 106 | In this implementation, the largest 24-bit binary integer is the |
| 108 | decimal integer 8,388,607. In binary, it looks like this: | 107 | decimal integer 134,217,727. In binary, it looks like this: |
| 109 | 108 | ||
| 110 | @example | 109 | @example |
| 111 | 0111 1111 1111 1111 1111 1111 | 110 | 0111 1111 1111 1111 1111 1111 1111 |
| 112 | @end example | 111 | @end example |
| 113 | 112 | ||
| 114 | Since the arithmetic functions do not check whether integers go | 113 | Since the arithmetic functions do not check whether integers go |
| 115 | outside their range, when you add 1 to 8,388,607, the value is the | 114 | outside their range, when you add 1 to 134,217,727, the value is the |
| 116 | negative integer @minus{}8,388,608: | 115 | negative integer @minus{}134,217,728: |
| 117 | 116 | ||
| 118 | @example | 117 | @example |
| 119 | (+ 1 8388607) | 118 | (+ 1 134217727) |
| 120 | @result{} -8388608 | 119 | @result{} -134217728 |
| 121 | @result{} 1000 0000 0000 0000 0000 0000 | 120 | @result{} 1000 0000 0000 0000 0000 0000 0000 |
| 122 | @end example | 121 | @end example |
| 123 | 122 | ||
| 124 | Many of the following functions accept markers for arguments as well | 123 | Many of the following functions accept markers for arguments as well |
| @@ -651,12 +650,12 @@ produces @minus{}2 on a 24-bit machine: | |||
| 651 | @result{} -2 | 650 | @result{} -2 |
| 652 | @end example | 651 | @end example |
| 653 | 652 | ||
| 654 | In binary, in the 24-bit implementation, the argument looks like this: | 653 | In binary, in the 28-bit implementation, the argument looks like this: |
| 655 | 654 | ||
| 656 | @example | 655 | @example |
| 657 | @group | 656 | @group |
| 658 | ;; @r{Decimal 8,388,607} | 657 | ;; @r{Decimal 134.217,727} |
| 659 | 0111 1111 1111 1111 1111 1111 | 658 | 0111 1111 1111 1111 1111 1111 1111 |
| 660 | @end group | 659 | @end group |
| 661 | @end example | 660 | @end example |
| 662 | 661 | ||
| @@ -666,7 +665,7 @@ which becomes the following when left shifted: | |||
| 666 | @example | 665 | @example |
| 667 | @group | 666 | @group |
| 668 | ;; @r{Decimal @minus{}2} | 667 | ;; @r{Decimal @minus{}2} |
| 669 | 1111 1111 1111 1111 1111 1110 | 668 | 1111 1111 1111 1111 1111 1111 1110 |
| 670 | @end group | 669 | @end group |
| 671 | @end example | 670 | @end example |
| 672 | 671 | ||
| @@ -724,9 +723,9 @@ looks like this: | |||
| 724 | @group | 723 | @group |
| 725 | (ash -6 -1) @result{} -3 | 724 | (ash -6 -1) @result{} -3 |
| 726 | ;; @r{Decimal @minus{}6 becomes decimal @minus{}3.} | 725 | ;; @r{Decimal @minus{}6 becomes decimal @minus{}3.} |
| 727 | 1111 1111 1111 1111 1111 1010 | 726 | 1111 1111 1111 1111 1111 1111 1010 |
| 728 | @result{} | 727 | @result{} |
| 729 | 1111 1111 1111 1111 1111 1101 | 728 | 1111 1111 1111 1111 1111 1111 1101 |
| 730 | @end group | 729 | @end group |
| 731 | @end example | 730 | @end example |
| 732 | 731 | ||
| @@ -735,11 +734,11 @@ In contrast, shifting the pattern of bits one place to the right with | |||
| 735 | 734 | ||
| 736 | @example | 735 | @example |
| 737 | @group | 736 | @group |
| 738 | (lsh -6 -1) @result{} 8388605 | 737 | (lsh -6 -1) @result{} 134217725 |
| 739 | ;; @r{Decimal @minus{}6 becomes decimal 8,388,605.} | 738 | ;; @r{Decimal @minus{}6 becomes decimal 134,217,725.} |
| 740 | 1111 1111 1111 1111 1111 1010 | 739 | 1111 1111 1111 1111 1111 1111 1010 |
| 741 | @result{} | 740 | @result{} |
| 742 | 0111 1111 1111 1111 1111 1101 | 741 | 0111 1111 1111 1111 1111 1111 1101 |
| 743 | @end group | 742 | @end group |
| 744 | @end example | 743 | @end example |
| 745 | 744 | ||
| @@ -749,34 +748,34 @@ Here are other examples: | |||
| 749 | @c with smallbook but not with regular book! --rjc 16mar92 | 748 | @c with smallbook but not with regular book! --rjc 16mar92 |
| 750 | @smallexample | 749 | @smallexample |
| 751 | @group | 750 | @group |
| 752 | ; @r{ 24-bit binary values} | 751 | ; @r{ 28-bit binary values} |
| 753 | 752 | ||
| 754 | (lsh 5 2) ; 5 = @r{0000 0000 0000 0000 0000 0101} | 753 | (lsh 5 2) ; 5 = @r{0000 0000 0000 0000 0000 0000 0101} |
| 755 | @result{} 20 ; = @r{0000 0000 0000 0000 0001 0100} | 754 | @result{} 20 ; = @r{0000 0000 0000 0000 0000 0001 0100} |
| 756 | @end group | 755 | @end group |
| 757 | @group | 756 | @group |
| 758 | (ash 5 2) | 757 | (ash 5 2) |
| 759 | @result{} 20 | 758 | @result{} 20 |
| 760 | (lsh -5 2) ; -5 = @r{1111 1111 1111 1111 1111 1011} | 759 | (lsh -5 2) ; -5 = @r{1111 1111 1111 1111 1111 1111 1011} |
| 761 | @result{} -20 ; = @r{1111 1111 1111 1111 1110 1100} | 760 | @result{} -20 ; = @r{1111 1111 1111 1111 1111 1110 1100} |
| 762 | (ash -5 2) | 761 | (ash -5 2) |
| 763 | @result{} -20 | 762 | @result{} -20 |
| 764 | @end group | 763 | @end group |
| 765 | @group | 764 | @group |
| 766 | (lsh 5 -2) ; 5 = @r{0000 0000 0000 0000 0000 0101} | 765 | (lsh 5 -2) ; 5 = @r{0000 0000 0000 0000 0000 0000 0101} |
| 767 | @result{} 1 ; = @r{0000 0000 0000 0000 0000 0001} | 766 | @result{} 1 ; = @r{0000 0000 0000 0000 0000 0000 0001} |
| 768 | @end group | 767 | @end group |
| 769 | @group | 768 | @group |
| 770 | (ash 5 -2) | 769 | (ash 5 -2) |
| 771 | @result{} 1 | 770 | @result{} 1 |
| 772 | @end group | 771 | @end group |
| 773 | @group | 772 | @group |
| 774 | (lsh -5 -2) ; -5 = @r{1111 1111 1111 1111 1111 1011} | 773 | (lsh -5 -2) ; -5 = @r{1111 1111 1111 1111 1111 1111 1011} |
| 775 | @result{} 4194302 ; = @r{0011 1111 1111 1111 1111 1110} | 774 | @result{} 4194302 ; = @r{0011 1111 1111 1111 1111 1111 1110} |
| 776 | @end group | 775 | @end group |
| 777 | @group | 776 | @group |
| 778 | (ash -5 -2) ; -5 = @r{1111 1111 1111 1111 1111 1011} | 777 | (ash -5 -2) ; -5 = @r{1111 1111 1111 1111 1111 1111 1011} |
| 779 | @result{} -2 ; = @r{1111 1111 1111 1111 1111 1110} | 778 | @result{} -2 ; = @r{1111 1111 1111 1111 1111 1111 1110} |
| 780 | @end group | 779 | @end group |
| 781 | @end smallexample | 780 | @end smallexample |
| 782 | @end defun | 781 | @end defun |
| @@ -813,23 +812,23 @@ because its binary representation consists entirely of ones. If | |||
| 813 | 812 | ||
| 814 | @smallexample | 813 | @smallexample |
| 815 | @group | 814 | @group |
| 816 | ; @r{ 24-bit binary values} | 815 | ; @r{ 28-bit binary values} |
| 817 | 816 | ||
| 818 | (logand 14 13) ; 14 = @r{0000 0000 0000 0000 0000 1110} | 817 | (logand 14 13) ; 14 = @r{0000 0000 0000 0000 0000 0000 1110} |
| 819 | ; 13 = @r{0000 0000 0000 0000 0000 1101} | 818 | ; 13 = @r{0000 0000 0000 0000 0000 0000 1101} |
| 820 | @result{} 12 ; 12 = @r{0000 0000 0000 0000 0000 1100} | 819 | @result{} 12 ; 12 = @r{0000 0000 0000 0000 0000 0000 1100} |
| 821 | @end group | 820 | @end group |
| 822 | 821 | ||
| 823 | @group | 822 | @group |
| 824 | (logand 14 13 4) ; 14 = @r{0000 0000 0000 0000 0000 1110} | 823 | (logand 14 13 4) ; 14 = @r{0000 0000 0000 0000 0000 0000 1110} |
| 825 | ; 13 = @r{0000 0000 0000 0000 0000 1101} | 824 | ; 13 = @r{0000 0000 0000 0000 0000 0000 1101} |
| 826 | ; 4 = @r{0000 0000 0000 0000 0000 0100} | 825 | ; 4 = @r{0000 0000 0000 0000 0000 0000 0100} |
| 827 | @result{} 4 ; 4 = @r{0000 0000 0000 0000 0000 0100} | 826 | @result{} 4 ; 4 = @r{0000 0000 0000 0000 0000 0000 0100} |
| 828 | @end group | 827 | @end group |
| 829 | 828 | ||
| 830 | @group | 829 | @group |
| 831 | (logand) | 830 | (logand) |
| 832 | @result{} -1 ; -1 = @r{1111 1111 1111 1111 1111 1111} | 831 | @result{} -1 ; -1 = @r{1111 1111 1111 1111 1111 1111 1111} |
| 833 | @end group | 832 | @end group |
| 834 | @end smallexample | 833 | @end smallexample |
| 835 | @end defun | 834 | @end defun |
| @@ -845,18 +844,18 @@ passed just one argument, it returns that argument. | |||
| 845 | 844 | ||
| 846 | @smallexample | 845 | @smallexample |
| 847 | @group | 846 | @group |
| 848 | ; @r{ 24-bit binary values} | 847 | ; @r{ 28-bit binary values} |
| 849 | 848 | ||
| 850 | (logior 12 5) ; 12 = @r{0000 0000 0000 0000 0000 1100} | 849 | (logior 12 5) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100} |
| 851 | ; 5 = @r{0000 0000 0000 0000 0000 0101} | 850 | ; 5 = @r{0000 0000 0000 0000 0000 0000 0101} |
| 852 | @result{} 13 ; 13 = @r{0000 0000 0000 0000 0000 1101} | 851 | @result{} 13 ; 13 = @r{0000 0000 0000 0000 0000 0000 1101} |
| 853 | @end group | 852 | @end group |
| 854 | 853 | ||
| 855 | @group | 854 | @group |
| 856 | (logior 12 5 7) ; 12 = @r{0000 0000 0000 0000 0000 1100} | 855 | (logior 12 5 7) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100} |
| 857 | ; 5 = @r{0000 0000 0000 0000 0000 0101} | 856 | ; 5 = @r{0000 0000 0000 0000 0000 0000 0101} |
| 858 | ; 7 = @r{0000 0000 0000 0000 0000 0111} | 857 | ; 7 = @r{0000 0000 0000 0000 0000 0000 0111} |
| 859 | @result{} 15 ; 15 = @r{0000 0000 0000 0000 0000 1111} | 858 | @result{} 15 ; 15 = @r{0000 0000 0000 0000 0000 0000 1111} |
| 860 | @end group | 859 | @end group |
| 861 | @end smallexample | 860 | @end smallexample |
| 862 | @end defun | 861 | @end defun |
| @@ -872,18 +871,18 @@ result is 0, which is an identity element for this operation. If | |||
| 872 | 871 | ||
| 873 | @smallexample | 872 | @smallexample |
| 874 | @group | 873 | @group |
| 875 | ; @r{ 24-bit binary values} | 874 | ; @r{ 28-bit binary values} |
| 876 | 875 | ||
| 877 | (logxor 12 5) ; 12 = @r{0000 0000 0000 0000 0000 1100} | 876 | (logxor 12 5) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100} |
| 878 | ; 5 = @r{0000 0000 0000 0000 0000 0101} | 877 | ; 5 = @r{0000 0000 0000 0000 0000 0000 0101} |
| 879 | @result{} 9 ; 9 = @r{0000 0000 0000 0000 0000 1001} | 878 | @result{} 9 ; 9 = @r{0000 0000 0000 0000 0000 0000 1001} |
| 880 | @end group | 879 | @end group |
| 881 | 880 | ||
| 882 | @group | 881 | @group |
| 883 | (logxor 12 5 7) ; 12 = @r{0000 0000 0000 0000 0000 1100} | 882 | (logxor 12 5 7) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100} |
| 884 | ; 5 = @r{0000 0000 0000 0000 0000 0101} | 883 | ; 5 = @r{0000 0000 0000 0000 0000 0000 0101} |
| 885 | ; 7 = @r{0000 0000 0000 0000 0000 0111} | 884 | ; 7 = @r{0000 0000 0000 0000 0000 0000 0111} |
| 886 | @result{} 14 ; 14 = @r{0000 0000 0000 0000 0000 1110} | 885 | @result{} 14 ; 14 = @r{0000 0000 0000 0000 0000 0000 1110} |
| 887 | @end group | 886 | @end group |
| 888 | @end smallexample | 887 | @end smallexample |
| 889 | @end defun | 888 | @end defun |
| @@ -898,9 +897,9 @@ bit is one in the result if, and only if, the @var{n}th bit is zero in | |||
| 898 | @example | 897 | @example |
| 899 | (lognot 5) | 898 | (lognot 5) |
| 900 | @result{} -6 | 899 | @result{} -6 |
| 901 | ;; 5 = @r{0000 0000 0000 0000 0000 0101} | 900 | ;; 5 = @r{0000 0000 0000 0000 0000 0000 0101} |
| 902 | ;; @r{becomes} | 901 | ;; @r{becomes} |
| 903 | ;; -6 = @r{1111 1111 1111 1111 1111 1010} | 902 | ;; -6 = @r{1111 1111 1111 1111 1111 1111 1010} |
| 904 | @end example | 903 | @end example |
| 905 | @end defun | 904 | @end defun |
| 906 | 905 | ||
| @@ -970,7 +969,10 @@ This function returns the logarithm of @var{arg}, with base 10. If | |||
| 970 | @end defun | 969 | @end defun |
| 971 | 970 | ||
| 972 | @defun expt x y | 971 | @defun expt x y |
| 973 | This function returns @var{x} raised to power @var{y}. | 972 | This function returns @var{x} raised to power @var{y}. If both |
| 973 | arguments are integers and @var{y} is positive, the result is an | ||
| 974 | integer; in this case, it is truncated to fit the range of possible | ||
| 975 | integer values. | ||
| 974 | @end defun | 976 | @end defun |
| 975 | 977 | ||
| 976 | @defun sqrt arg | 978 | @defun sqrt arg |