[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] Changes to emacs/lispref/numbers.texi [lexbind]
From: |
Miles Bader |
Subject: |
[Emacs-diffs] Changes to emacs/lispref/numbers.texi [lexbind] |
Date: |
Thu, 20 Nov 2003 19:36:48 -0500 |
Index: emacs/lispref/numbers.texi
diff -c emacs/lispref/numbers.texi:1.21.4.2 emacs/lispref/numbers.texi:1.21.4.3
*** emacs/lispref/numbers.texi:1.21.4.2 Tue Oct 14 19:10:12 2003
--- emacs/lispref/numbers.texi Thu Nov 20 19:35:47 2003
***************
*** 1,6 ****
@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
! @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
@c Free Software Foundation, Inc.
@c See the file elisp.texi for copying conditions.
@setfilename ../info/numbers
--- 1,6 ----
@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
! @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2003
@c Free Software Foundation, Inc.
@c See the file elisp.texi for copying conditions.
@setfilename ../info/numbers
***************
*** 36,57 ****
@section Integer Basics
The range of values for an integer depends on the machine. The
! minimum range is @minus{}134217728 to 134217727 (28 bits; i.e.,
@ifnottex
! -2**27
@end ifnottex
@tex
! @math{-2^{27}}
@end tex
to
@ifnottex
! 2**27 - 1),
@end ifnottex
@tex
! @math{2^{27}-1}),
@end tex
but some machines may provide a wider range. Many examples in this
! chapter assume an integer has 28 bits.
@cindex overflow
The Lisp reader reads an integer as a sequence of digits with optional
--- 36,57 ----
@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.,
@ifnottex
! -2**28
@end ifnottex
@tex
! @math{-2^{28}}
@end tex
to
@ifnottex
! 2**28 - 1),
@end ifnottex
@tex
! @math{2^{28}-1}),
@end tex
but some machines may provide a wider range. Many examples in this
! chapter assume an integer has 29 bits.
@cindex overflow
The Lisp reader reads an integer as a sequence of digits with optional
***************
*** 62,68 ****
1. ; @r{The integer 1.}
+1 ; @r{Also the integer 1.}
-1 ; @r{The integer @minus{}1.}
! 268435457 ; @r{Also the integer 1, due to overflow.}
0 ; @r{The integer 0.}
-0 ; @r{The integer 0.}
@end example
--- 62,68 ----
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.}
0 ; @r{The integer 0.}
-0 ; @r{The integer 0.}
@end example
***************
*** 70,75 ****
--- 70,78 ----
@cindex integers in specific radix
@cindex radix for reading an integer
@cindex base for reading an integer
+ @cindex hex numbers
+ @cindex octal numbers
+ @cindex reading numbers in hex, octal, and binary
In addition, the Lisp reader recognizes a syntax for integers in
bases other than 10: @address@hidden reads @var{integer} in
binary (radix 2), @address@hidden reads @var{integer} in octal
***************
*** 83,92 ****
bitwise operators (@pxref{Bitwise Operations}), it is often helpful to
view the numbers in their binary form.
! In 28-bit binary, the decimal integer 5 looks like this:
@example
! 0000 0000 0000 0000 0000 0000 0101
@end example
@noindent
--- 86,95 ----
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:
@example
! 0 0000 0000 0000 0000 0000 0000 0101
@end example
@noindent
***************
*** 96,107 ****
The integer @minus{}1 looks like this:
@example
! 1111 1111 1111 1111 1111 1111 1111
@end example
@noindent
@cindex two's complement
! @minus{}1 is represented as 28 ones. (This is called @dfn{two's
complement} notation.)
The negative integer, @minus{}5, is creating by subtracting 4 from
--- 99,110 ----
The integer @minus{}1 looks like this:
@example
! 1 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
complement} notation.)
The negative integer, @minus{}5, is creating by subtracting 4 from
***************
*** 109,132 ****
@minus{}5 looks like this:
@example
! 1111 1111 1111 1111 1111 1111 1011
@end example
! In this implementation, the largest 28-bit binary integer value is
! 134,217,727 in decimal. In binary, it looks like this:
@example
! 0111 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 134,217,727, the value is the
! negative integer @minus{}134,217,728:
@example
! (+ 1 134217727)
! @result{} -134217728
! @result{} 1000 0000 0000 0000 0000 0000 0000
@end example
Many of the functions described in this chapter accept markers for
--- 112,135 ----
@minus{}5 looks like this:
@example
! 1 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:
@example
! 0 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:
@example
! (+ 1 268435455)
! @result{} -268435456
! @result{} 1 0000 0000 0000 0000 0000 0000 0000
@end example
Many of the functions described in this chapter accept markers for
***************
*** 160,172 ****
value is 1500. They are all equivalent. You can also use a minus sign
to write negative floating point numbers, as in @samp{-1.0}.
! @cindex IEEE floating point
@cindex positive infinity
@cindex negative infinity
@cindex infinity
@cindex NaN
! Most modern computers support the IEEE floating point standard, which
! provides for positive infinity and negative infinity as floating point
values. It also provides for a class of values called NaN or
``not-a-number''; numerical functions return such values in cases where
there is no correct answer. For example, @code{(sqrt -1.0)} returns a
--- 163,175 ----
value is 1500. They are all equivalent. You can also use a minus sign
to write negative floating point numbers, as in @samp{-1.0}.
! @cindex @acronym{IEEE} floating point
@cindex positive infinity
@cindex negative infinity
@cindex infinity
@cindex NaN
! Most modern computers support the @acronym{IEEE} floating point standard,
! which provides for positive infinity and negative infinity as floating point
values. It also provides for a class of values called NaN or
``not-a-number''; numerical functions return such values in cases where
there is no correct answer. For example, @code{(sqrt -1.0)} returns a
***************
*** 186,193 ****
@end table
In addition, the value @code{-0.0} is distinguishable from ordinary
! zero in IEEE floating point (although @code{equal} and @code{=} consider
! them equal values).
You can use @code{logb} to extract the binary exponent of a floating
point number (or estimate the logarithm of an integer):
--- 189,196 ----
@end table
In addition, the value @code{-0.0} is distinguishable from ordinary
! zero in @acronym{IEEE} floating point (although @code{equal} and
! @code{=} consider them equal values).
You can use @code{logb} to extract the binary exponent of a floating
point number (or estimate the logarithm of an integer):
***************
*** 376,385 ****
@end defun
There are four functions to convert floating point numbers to integers;
! they differ in how they round. These functions accept integer arguments
! also, and return such arguments unchanged.
! @defun truncate number
This returns @var{number}, converted to an integer by rounding towards
zero.
--- 379,394 ----
@end defun
There are four functions to convert floating point numbers to integers;
! they differ in how they round. All accept an argument @var{number}
! and an optional argument @var{divisor}. Both arguments may be
! integers or floating point numbers. @var{divisor} may also be
! @code{nil}. If @var{divisor} is @code{nil} or omitted, these
! functions convert @var{number} to an integer, or return it unchanged
! if it already is an integer. If @var{divisor} is address@hidden, they
! divide @var{number} by @var{divisor} and convert the result to an
! integer. An @code{arith-error} results if @var{divisor} is 0.
! @defun truncate number &optional divisor
This returns @var{number}, converted to an integer by rounding towards
zero.
***************
*** 399,408 ****
This returns @var{number}, converted to an integer by rounding downward
(towards negative infinity).
! If @var{divisor} is specified, @code{floor} divides @var{number} by
! @var{divisor} and then converts to an integer; this uses the kind of
! division operation that corresponds to @code{mod}, rounding downward.
! An @code{arith-error} results if @var{divisor} is 0.
@example
(floor 1.2)
--- 408,415 ----
This returns @var{number}, converted to an integer by rounding downward
(towards negative infinity).
! If @var{divisor} is specified, this uses the kind of division
! operation that corresponds to @code{mod}, rounding downward.
@example
(floor 1.2)
***************
*** 418,424 ****
@end example
@end defun
! @defun ceiling number
This returns @var{number}, converted to an integer by rounding upward
(towards positive infinity).
--- 425,431 ----
@end example
@end defun
! @defun ceiling number &optional divisor
This returns @var{number}, converted to an integer by rounding upward
(towards positive infinity).
***************
*** 434,440 ****
@end example
@end defun
! @defun round number
This returns @var{number}, converted to an integer by rounding towards the
nearest integer. Rounding a value equidistant between two integers
may choose the integer closer to zero, or it may prefer an even integer,
--- 441,447 ----
@end example
@end defun
! @defun round number &optional divisor
This returns @var{number}, converted to an integer by rounding towards the
nearest integer. Rounding a value equidistant between two integers
may choose the integer closer to zero, or it may prefer an even integer,
***************
*** 465,472 ****
if any argument is floating.
It is important to note that in Emacs Lisp, arithmetic functions
! do not check for overflow. Thus @code{(1+ 134217727)} may evaluate to
! @minus{}134217728, depending on your hardware.
@defun 1+ number-or-marker
This function returns @var{number-or-marker} plus 1.
--- 472,479 ----
if any argument is floating.
It is important to note that in Emacs Lisp, arithmetic functions
! do not check for overflow. Thus @code{(1+ 268435455)} may evaluate to
! @minus{}268435456, depending on your hardware.
@defun 1+ number-or-marker
This function returns @var{number-or-marker} plus 1.
***************
*** 562,568 ****
@cindex @code{arith-error} in division
If you divide an integer by 0, an @code{arith-error} error is signaled.
(@xref{Errors}.) Floating point division by zero returns either
! infinity or a NaN if your machine supports IEEE floating point;
otherwise, it signals an @code{arith-error} error.
@example
--- 569,575 ----
@cindex @code{arith-error} in division
If you divide an integer by 0, an @code{arith-error} error is signaled.
(@xref{Errors}.) Floating point division by zero returns either
! infinity or a NaN if your machine supports @acronym{IEEE} floating point;
otherwise, it signals an @code{arith-error} error.
@example
***************
*** 785,803 ****
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
! 134,217,727 produces @minus{}2 on a 28-bit machine:
@example
! (lsh 134217727 1) ; @r{left shift}
@result{} -2
@end example
! In binary, in the 28-bit implementation, the argument looks like this:
@example
@group
! ;; @r{Decimal 134,217,727}
! 0111 1111 1111 1111 1111 1111 1111
@end group
@end example
--- 792,810 ----
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:
@example
! (lsh 268435455 1) ; @r{left shift}
@result{} -2
@end example
! In binary, in the 29-bit implementation, the argument looks like this:
@example
@group
! ;; @r{Decimal 268,435,455}
! 0 1111 1111 1111 1111 1111 1111 1111
@end group
@end example
***************
*** 807,813 ****
@example
@group
;; @r{Decimal @minus{}2}
! 1111 1111 1111 1111 1111 1111 1110
@end group
@end example
@end defun
--- 814,820 ----
@example
@group
;; @r{Decimal @minus{}2}
! 1 1111 1111 1111 1111 1111 1111 1110
@end group
@end example
@end defun
***************
*** 830,838 ****
@group
(ash -6 -1) @result{} -3
;; @r{Decimal @minus{}6 becomes decimal @minus{}3.}
! 1111 1111 1111 1111 1111 1111 1010
@result{}
! 1111 1111 1111 1111 1111 1111 1101
@end group
@end example
--- 837,845 ----
@group
(ash -6 -1) @result{} -3
;; @r{Decimal @minus{}6 becomes decimal @minus{}3.}
! 1 1111 1111 1111 1111 1111 1111 1010
@result{}
! 1 1111 1111 1111 1111 1111 1111 1101
@end group
@end example
***************
*** 841,851 ****
@example
@group
! (lsh -6 -1) @result{} 134217725
! ;; @r{Decimal @minus{}6 becomes decimal 134,217,725.}
! 1111 1111 1111 1111 1111 1111 1010
@result{}
! 0111 1111 1111 1111 1111 1111 1101
@end group
@end example
--- 848,858 ----
@example
@group
! (lsh -6 -1) @result{} 268435453
! ;; @r{Decimal @minus{}6 becomes decimal 268,435,453.}
! 1 1111 1111 1111 1111 1111 1111 1010
@result{}
! 0 1111 1111 1111 1111 1111 1111 1101
@end group
@end example
***************
*** 855,888 ****
@c with smallbook but not with regular book! --rjc 16mar92
@smallexample
@group
! ; @r{ 28-bit binary values}
! (lsh 5 2) ; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
! @result{} 20 ; = @r{0000 0000 0000 0000 0000 0001 0100}
@end group
@group
(ash 5 2)
@result{} 20
! (lsh -5 2) ; -5 = @r{1111 1111 1111 1111 1111 1111 1011}
! @result{} -20 ; = @r{1111 1111 1111 1111 1111 1110 1100}
(ash -5 2)
@result{} -20
@end group
@group
! (lsh 5 -2) ; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
! @result{} 1 ; = @r{0000 0000 0000 0000 0000 0000 0001}
@end group
@group
(ash 5 -2)
@result{} 1
@end group
@group
! (lsh -5 -2) ; -5 = @r{1111 1111 1111 1111 1111 1111 1011}
! @result{} 4194302 ; = @r{0011 1111 1111 1111 1111 1111 1110}
@end group
@group
! (ash -5 -2) ; -5 = @r{1111 1111 1111 1111 1111 1111 1011}
! @result{} -2 ; = @r{1111 1111 1111 1111 1111 1111 1110}
@end group
@end smallexample
@end defun
--- 862,895 ----
@c with smallbook but not with regular book! --rjc 16mar92
@smallexample
@group
! ; @r{ 29-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}
@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}
(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}
@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}
@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}
@end group
@end smallexample
@end defun
***************
*** 919,941 ****
@smallexample
@group
! ; @r{ 28-bit binary values}
! (logand 14 13) ; 14 = @r{0000 0000 0000 0000 0000 0000 1110}
! ; 13 = @r{0000 0000 0000 0000 0000 0000 1101}
! @result{} 12 ; 12 = @r{0000 0000 0000 0000 0000 0000 1100}
@end group
@group
! (logand 14 13 4) ; 14 = @r{0000 0000 0000 0000 0000 0000 1110}
! ; 13 = @r{0000 0000 0000 0000 0000 0000 1101}
! ; 4 = @r{0000 0000 0000 0000 0000 0000 0100}
! @result{} 4 ; 4 = @r{0000 0000 0000 0000 0000 0000 0100}
@end group
@group
(logand)
! @result{} -1 ; -1 = @r{1111 1111 1111 1111 1111 1111 1111}
@end group
@end smallexample
@end defun
--- 926,948 ----
@smallexample
@group
! ; @r{ 29-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}
@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}
@end group
@group
(logand)
! @result{} -1 ; -1 = @r{1 1111 1111 1111 1111 1111 1111 1111}
@end group
@end smallexample
@end defun
***************
*** 951,968 ****
@smallexample
@group
! ; @r{ 28-bit binary values}
! (logior 12 5) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100}
! ; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
! @result{} 13 ; 13 = @r{0000 0000 0000 0000 0000 0000 1101}
@end group
@group
! (logior 12 5 7) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100}
! ; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
! ; 7 = @r{0000 0000 0000 0000 0000 0000 0111}
! @result{} 15 ; 15 = @r{0000 0000 0000 0000 0000 0000 1111}
@end group
@end smallexample
@end defun
--- 958,975 ----
@smallexample
@group
! ; @r{ 29-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}
@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}
@end group
@end smallexample
@end defun
***************
*** 978,995 ****
@smallexample
@group
! ; @r{ 28-bit binary values}
! (logxor 12 5) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100}
! ; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
! @result{} 9 ; 9 = @r{0000 0000 0000 0000 0000 0000 1001}
@end group
@group
! (logxor 12 5 7) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100}
! ; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
! ; 7 = @r{0000 0000 0000 0000 0000 0000 0111}
! @result{} 14 ; 14 = @r{0000 0000 0000 0000 0000 0000 1110}
@end group
@end smallexample
@end defun
--- 985,1002 ----
@smallexample
@group
! ; @r{ 29-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}
@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}
@end group
@end smallexample
@end defun
***************
*** 1004,1012 ****
@example
(lognot 5)
@result{} -6
! ;; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
;; @r{becomes}
! ;; -6 = @r{1111 1111 1111 1111 1111 1111 1010}
@end example
@end defun
--- 1011,1019 ----
@example
(lognot 5)
@result{} -6
! ;; 5 = @r{0 0000 0000 0000 0000 0000 0000 0101}
;; @r{becomes}
! ;; -6 = @r{1 1111 1111 1111 1111 1111 1111 1010}
@end example
@end defun
***************
*** 1163,1169 ****
If you want random numbers that don't always come out the same, execute
@code{(random t)}. This chooses a new seed based on the current time of
! day and on Emacs's process @sc{id} number.
@defun random &optional limit
This function returns a pseudo-random integer. Repeated calls return a
--- 1170,1176 ----
If you want random numbers that don't always come out the same, execute
@code{(random t)}. This chooses a new seed based on the current time of
! day and on Emacs's process @acronym{ID} number.
@defun random &optional limit
This function returns a pseudo-random integer. Repeated calls return a
***************
*** 1173,1179 ****
nonnegative and less than @var{limit}.
If @var{limit} is @code{t}, it means to choose a new seed based on the
! current time of day and on Emacs's process @sc{id} number.
@c "Emacs'" is incorrect usage!
On some machines, any integer representable in Lisp may be the result
--- 1180,1186 ----
nonnegative and less than @var{limit}.
If @var{limit} is @code{t}, it means to choose a new seed based on the
! current time of day and on Emacs's process @acronym{ID} number.
@c "Emacs'" is incorrect usage!
On some machines, any integer representable in Lisp may be the result
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] Changes to emacs/lispref/numbers.texi [lexbind],
Miles Bader <=