annotate man/lispref/numbers.texi @ 177:6075d714658b r20-3b15

Import from CVS: tag r20-3b15
author cvs
date Mon, 13 Aug 2007 09:51:16 +0200
parents 54cc21c15cbb
children 65c19d2020f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 @c -*-texinfo-*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 @c This is part of the XEmacs Lisp Reference Manual.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 @c See the file lispref.texi for copying conditions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 @setfilename ../../info/numbers.info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 @node Numbers, Strings and Characters, Lisp Data Types, Top
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 @chapter Numbers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 @cindex integers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 @cindex numbers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs supports two numeric data types: @dfn{integers} and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 @dfn{floating point numbers}. Integers are whole numbers such as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 @minus{}3, 0, 7, 13, and 511. Their values are exact. Floating point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 numbers are numbers with fractional parts, such as @minus{}4.5, 0.0, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 2.71828. They can also be expressed in exponential notation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 1.5e2 equals 150; in this example, @samp{e2} stands for ten to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 second power, and is multiplied by 1.5. Floating point values are not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 exact; they have a fixed, limited amount of precision.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 @menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 * Integer Basics:: Representation and range of integers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 * Float Basics:: Representation and range of floating point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 * Predicates on Numbers:: Testing for numbers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 * Comparison of Numbers:: Equality and inequality predicates.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 * Numeric Conversions:: Converting float to integer and vice versa.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 * Arithmetic Operations:: How to add, subtract, multiply and divide.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 * Rounding Operations:: Explicitly rounding floating point numbers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 * Bitwise Operations:: Logical and, or, not, shifting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 * Math Functions:: Trig, exponential and logarithmic functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 * Random Numbers:: Obtaining random integers, predictable or not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 @end menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 @node Integer Basics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 @section Integer Basics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 The range of values for an integer depends on the machine. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 minimum range is @minus{}134217728 to 134217727 (28 bits; i.e.,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 @ifinfo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 -2**27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 @end ifinfo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 @tex
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 $-2^{27}$
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 @end tex
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 @ifinfo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 2**27 - 1),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 @end ifinfo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 @tex
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 $2^{27}-1$),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 @end tex
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 but some machines may provide a wider range. Many examples in this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 chapter assume an integer has 28 bits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 @cindex overflow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 The Lisp reader reads an integer as a sequence of digits with optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 initial sign and optional final period.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 1 ; @r{The integer 1.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 1. ; @r{The integer 1.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 +1 ; @r{Also the integer 1.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 -1 ; @r{The integer @minus{}1.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 268435457 ; @r{Also the integer 1, due to overflow.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 0 ; @r{The integer 0.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 -0 ; @r{The integer 0.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 To understand how various functions work on integers, especially the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 bitwise operators (@pxref{Bitwise Operations}), it is often helpful to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 view the numbers in their binary form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 In 28-bit binary, the decimal integer 5 looks like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 0000 0000 0000 0000 0000 0000 0101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (We have inserted spaces between groups of 4 bits, and two spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 between groups of 8 bits, to make the binary integer easier to read.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 The integer @minus{}1 looks like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 1111 1111 1111 1111 1111 1111 1111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 @cindex two's complement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 @minus{}1 is represented as 28 ones. (This is called @dfn{two's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 complement} notation.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 The negative integer, @minus{}5, is creating by subtracting 4 from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 @minus{}1. In binary, the decimal integer 4 is 100. Consequently,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 @minus{}5 looks like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 1111 1111 1111 1111 1111 1111 1011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 In this implementation, the largest 28-bit binary integer is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 decimal integer 134,217,727. In binary, it looks like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 0111 1111 1111 1111 1111 1111 1111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 Since the arithmetic functions do not check whether integers go
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 outside their range, when you add 1 to 134,217,727, the value is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 negative integer @minus{}134,217,728:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (+ 1 134217727)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 @result{} -134217728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 @result{} 1000 0000 0000 0000 0000 0000 0000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 Many of the following functions accept markers for arguments as well
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 as integers. (@xref{Markers}.) More precisely, the actual arguments to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 such functions may be either integers or markers, which is why we often
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 give these arguments the name @var{int-or-marker}. When the argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 value is a marker, its position value is used and its buffer is ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 @ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 In version 19, except where @emph{integer} is specified as an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 argument, all of the functions for markers and integers also work for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 floating point numbers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 @end ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 @node Float Basics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 @section Floating Point Basics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 XEmacs supports floating point numbers. The precise range of floating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 point numbers is machine-specific; it is the same as the range of the C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 data type @code{double} on the machine in question.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 The printed representation for floating point numbers requires either
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 a decimal point (with at least one digit following), an exponent, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 both. For example, @samp{1500.0}, @samp{15e2}, @samp{15.0e2},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 @samp{1.5e3}, and @samp{.15e4} are five ways of writing a floating point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 number whose value is 1500. They are all equivalent. You can also use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 a minus sign to write negative floating point numbers, as in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 @samp{-1.0}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 @cindex IEEE floating point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 @cindex positive infinity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 @cindex negative infinity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 @cindex infinity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 @cindex NaN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 Most modern computers support the IEEE floating point standard, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 provides for positive infinity and negative infinity as floating point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 values. It also provides for a class of values called NaN or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ``not-a-number''; numerical functions return such values in cases where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 there is no correct answer. For example, @code{(sqrt -1.0)} returns a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 NaN. For practical purposes, there's no significant difference between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 different NaN values in XEmacs Lisp, and there's no rule for precisely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 which NaN value should be used in a particular case, so this manual
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 doesn't try to distinguish them. XEmacs Lisp has no read syntax for NaNs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 or infinities; perhaps we should create a syntax in the future.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 You can use @code{logb} to extract the binary exponent of a floating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 point number (or estimate the logarithm of an integer):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 @defun logb number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 This function returns the binary exponent of @var{number}. More
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 precisely, the value is the logarithm of @var{number} base 2, rounded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 down to an integer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 @node Predicates on Numbers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 @section Type Predicates for Numbers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 The functions in this section test whether the argument is a number or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 whether it is a certain sort of number. The functions @code{integerp}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 and @code{floatp} can take any type of Lisp object as argument (the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 predicates would not be of much use otherwise); but the @code{zerop}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 predicate requires a number as its argument. See also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 @code{integer-or-marker-p}, @code{integer-char-or-marker-p},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 @code{number-or-marker-p} and @code{number-char-or-marker-p}, in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 @ref{Predicates on Markers}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 @defun floatp object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 This predicate tests whether its argument is a floating point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 number and returns @code{t} if so, @code{nil} otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 @code{floatp} does not exist in Emacs versions 18 and earlier.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 @defun integerp object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 This predicate tests whether its argument is an integer, and returns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 @code{t} if so, @code{nil} otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 @defun numberp object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 This predicate tests whether its argument is a number (either integer or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 floating point), and returns @code{t} if so, @code{nil} otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 @defun natnump object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 @cindex natural numbers
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
201 The @code{natnump} predicate (whose name comes from the phrase
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ``natural-number-p'') tests to see whether its argument is a nonnegative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 integer, and returns @code{t} if so, @code{nil} otherwise. 0 is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 considered non-negative.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 @defun zerop number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 This predicate tests whether its argument is zero, and returns @code{t}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 if so, @code{nil} otherwise. The argument must be a number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 These two forms are equivalent: @code{(zerop x)} @equiv{} @code{(= x 0)}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 @node Comparison of Numbers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 @section Comparison of Numbers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 @cindex number equality
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 To test numbers for numerical equality, you should normally use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 @code{=}, not @code{eq}. There can be many distinct floating point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 number objects with the same numeric value. If you use @code{eq} to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 compare them, then you test whether two values are the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 @emph{object}. By contrast, @code{=} compares only the numeric values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 of the objects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 At present, each integer value has a unique Lisp object in XEmacs Lisp.
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
226 Therefore, @code{eq} is equivalent to @code{=} where integers are
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 concerned. It is sometimes convenient to use @code{eq} for comparing an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 unknown value with an integer, because @code{eq} does not report an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 error if the unknown value is not a number---it accepts arguments of any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 type. By contrast, @code{=} signals an error if the arguments are not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 numbers or markers. However, it is a good idea to use @code{=} if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 can, even for comparing integers, just in case we change the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 representation of integers in a future XEmacs version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 There is another wrinkle: because floating point arithmetic is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 exact, it is often a bad idea to check for equality of two floating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 point values. Usually it is better to test for approximate equality.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 Here's a function to do this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (defvar fuzz-factor 1.0e-6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (defun approx-equal (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (or (and (= x 0) (= y 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (< (/ (abs (- x y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (max (abs x) (abs y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 fuzz-factor)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 @cindex CL note---integers vrs @code{eq}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 @quotation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 @b{Common Lisp note:} Comparing numbers in Common Lisp always requires
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 @code{=} because Common Lisp implements multi-word integers, and two
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 distinct integer objects can have the same numeric value. XEmacs Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 can have just one integer object for any given value because it has a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 limited range of integer values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 @end quotation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 @defun = number-or-marker1 number-or-marker2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 This function tests whether its arguments are numerically equal, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 returns @code{t} if so, @code{nil} otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 @defun /= number-or-marker1 number-or-marker2
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 0
diff changeset
264 This function tests whether its arguments are numerically not equal. It
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 0
diff changeset
265 returns @code{t} if so, and @code{nil} otherwise.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 @defun < number-or-marker1 number-or-marker2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 This function tests whether its first argument is strictly less than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 its second argument. It returns @code{t} if so, @code{nil} otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 @defun <= number-or-marker1 number-or-marker2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 This function tests whether its first argument is less than or equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 to its second argument. It returns @code{t} if so, @code{nil}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 @defun > number-or-marker1 number-or-marker2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 This function tests whether its first argument is strictly greater
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 than its second argument. It returns @code{t} if so, @code{nil}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 @defun >= number-or-marker1 number-or-marker2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 This function tests whether its first argument is greater than or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 equal to its second argument. It returns @code{t} if so, @code{nil}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 @defun max number-or-marker &rest numbers-or-markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 This function returns the largest of its arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (max 20)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 @result{} 20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (max 1 2.5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 @result{} 2.5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (max 1 3 2.5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 @result{} 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 @defun min number-or-marker &rest numbers-or-markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 This function returns the smallest of its arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (min -4 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 @result{} -4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 @node Numeric Conversions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 @section Numeric Conversions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 @cindex rounding in conversions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 To convert an integer to floating point, use the function @code{float}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 @defun float number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 This returns @var{number} converted to floating point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 If @var{number} is already a floating point number, @code{float} returns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 it unchanged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 There are four functions to convert floating point numbers to integers;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 they differ in how they round. These functions accept integer arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 also, and return such arguments unchanged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 @defun truncate number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 This returns @var{number}, converted to an integer by rounding towards
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 @defun floor number &optional divisor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 This returns @var{number}, converted to an integer by rounding downward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (towards negative infinity).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 If @var{divisor} is specified, @var{number} is divided by @var{divisor}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 before the floor is taken; this is the division operation that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 corresponds to @code{mod}. An @code{arith-error} results if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 @var{divisor} is 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 @defun ceiling number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 This returns @var{number}, converted to an integer by rounding upward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (towards positive infinity).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 @defun round number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 This returns @var{number}, converted to an integer by rounding towards the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 nearest integer. Rounding a value equidistant between two integers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 may choose the integer closer to zero, or it may prefer an even integer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 depending on your machine.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 @node Arithmetic Operations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 @section Arithmetic Operations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 XEmacs Lisp provides the traditional four arithmetic operations:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 addition, subtraction, multiplication, and division. Remainder and modulus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 functions supplement the division functions. The functions to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 add or subtract 1 are provided because they are traditional in Lisp and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 commonly used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 All of these functions except @code{%} return a floating point value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 if any argument is floating.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 It is important to note that in XEmacs Lisp, arithmetic functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 do not check for overflow. Thus @code{(1+ 134217727)} may evaluate to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 @minus{}134217728, depending on your hardware.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 @defun 1+ number-or-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 This function returns @var{number-or-marker} plus 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 For example,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (setq foo 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 @result{} 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (1+ foo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 @result{} 5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 This function is not analogous to the C operator @code{++}---it does not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 increment a variable. It just computes a sum. Thus, if we continue,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 @result{} 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 If you want to increment the variable, you must use @code{setq},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (setq foo (1+ foo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 @result{} 5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 @end example
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
398
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
399 Now that the @code{cl} package is always available from lisp code, a
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
400 more convenient and natural way to increment a variable is
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
401 @w{@code{(incf foo)}}.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 @defun 1- number-or-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 This function returns @var{number-or-marker} minus 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 @defun abs number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 This returns the absolute value of @var{number}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 @defun + &rest numbers-or-markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 This function adds its arguments together. When given no arguments,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 @code{+} returns 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (+)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 @result{} 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (+ 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 @result{} 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (+ 1 2 3 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 @result{} 10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 @defun - &optional number-or-marker &rest other-numbers-or-markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 The @code{-} function serves two purposes: negation and subtraction.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 When @code{-} has a single argument, the value is the negative of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 argument. When there are multiple arguments, @code{-} subtracts each of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 the @var{other-numbers-or-markers} from @var{number-or-marker},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 cumulatively. If there are no arguments, the result is 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (- 10 1 2 3 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 @result{} 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (- 10)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 @result{} -10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 @result{} 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 @defun * &rest numbers-or-markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 This function multiplies its arguments together, and returns the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 product. When given no arguments, @code{*} returns 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 @result{} 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (* 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 @result{} 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (* 1 2 3 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 @result{} 24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 @defun / dividend divisor &rest divisors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 This function divides @var{dividend} by @var{divisor} and returns the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 quotient. If there are additional arguments @var{divisors}, then it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 divides @var{dividend} by each divisor in turn. Each argument may be a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 number or a marker.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 If all the arguments are integers, then the result is an integer too.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 This means the result has to be rounded. On most machines, the result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 is rounded towards zero after each division, but some machines may round
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 differently with negative arguments. This is because the Lisp function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 @code{/} is implemented using the C division operator, which also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 permits machine-dependent rounding. As a practical matter, all known
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 machines round in the standard fashion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 @cindex @code{arith-error} in division
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 If you divide by 0, an @code{arith-error} error is signaled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (@xref{Errors}.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (/ 6 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 @result{} 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (/ 5 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 @result{} 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (/ 25 3 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 @result{} 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (/ -17 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 @result{} -2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 The result of @code{(/ -17 6)} could in principle be -3 on some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 machines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 @defun % dividend divisor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 @cindex remainder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 This function returns the integer remainder after division of @var{dividend}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 by @var{divisor}. The arguments must be integers or markers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 For negative arguments, the remainder is in principle machine-dependent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 since the quotient is; but in practice, all known machines behave alike.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 An @code{arith-error} results if @var{divisor} is 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (% 9 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 @result{} 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (% -9 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 @result{} -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (% 9 -4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 @result{} 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (% -9 -4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 @result{} -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 For any two integers @var{dividend} and @var{divisor},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (+ (% @var{dividend} @var{divisor})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (* (/ @var{dividend} @var{divisor}) @var{divisor}))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 always equals @var{dividend}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 @defun mod dividend divisor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 @cindex modulus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 This function returns the value of @var{dividend} modulo @var{divisor};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 in other words, the remainder after division of @var{dividend}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 by @var{divisor}, but with the same sign as @var{divisor}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 The arguments must be numbers or markers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 Unlike @code{%}, @code{mod} returns a well-defined result for negative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 arguments. It also permits floating point arguments; it rounds the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 quotient downward (towards minus infinity) to an integer, and uses that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 quotient to compute the remainder.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 An @code{arith-error} results if @var{divisor} is 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (mod 9 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 @result{} 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (mod -9 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 @result{} 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (mod 9 -4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 @result{} -3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (mod -9 -4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 @result{} -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (mod 5.5 2.5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 @result{} .5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 For any two numbers @var{dividend} and @var{divisor},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (+ (mod @var{dividend} @var{divisor})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (* (floor @var{dividend} @var{divisor}) @var{divisor}))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 always equals @var{dividend}, subject to rounding error if either
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 argument is floating point. For @code{floor}, see @ref{Numeric
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 Conversions}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 @node Rounding Operations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 @section Rounding Operations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 @cindex rounding without conversion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 The functions @code{ffloor}, @code{fceiling}, @code{fround} and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 @code{ftruncate} take a floating point argument and return a floating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 point result whose value is a nearby integer. @code{ffloor} returns the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 nearest integer below; @code{fceiling}, the nearest integer above;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 @code{ftruncate}, the nearest integer in the direction towards zero;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 @code{fround}, the nearest integer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 @defun ffloor float
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 This function rounds @var{float} to the next lower integral value, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 returns that value as a floating point number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 @defun fceiling float
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 This function rounds @var{float} to the next higher integral value, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 returns that value as a floating point number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 @defun ftruncate float
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 This function rounds @var{float} towards zero to an integral value, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 returns that value as a floating point number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 @defun fround float
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 This function rounds @var{float} to the nearest integral value,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 and returns that value as a floating point number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 @node Bitwise Operations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 @section Bitwise Operations on Integers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 In a computer, an integer is represented as a binary number, a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 sequence of @dfn{bits} (digits which are either zero or one). A bitwise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 operation acts on the individual bits of such a sequence. For example,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 @dfn{shifting} moves the whole sequence left or right one or more places,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 reproducing the same pattern ``moved over''.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 The bitwise operations in XEmacs Lisp apply only to integers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 @defun lsh integer1 count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 @cindex logical shift
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 @code{lsh}, which is an abbreviation for @dfn{logical shift}, shifts the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 bits in @var{integer1} to the left @var{count} places, or to the right
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 if @var{count} is negative, bringing zeros into the vacated bits. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 @var{count} is negative, @code{lsh} shifts zeros into the leftmost
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (most-significant) bit, producing a positive result even if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 @var{integer1} is negative. Contrast this with @code{ash}, below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 Here are two examples of @code{lsh}, shifting a pattern of bits one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 place to the left. We show only the low-order eight bits of the binary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 pattern; the rest are all zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (lsh 5 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 @result{} 10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 ;; @r{Decimal 5 becomes decimal 10.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 00000101 @result{} 00001010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (lsh 7 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 @result{} 14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ;; @r{Decimal 7 becomes decimal 14.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 00000111 @result{} 00001110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 As the examples illustrate, shifting the pattern of bits one place to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 the left produces a number that is twice the value of the previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 Shifting a pattern of bits two places to the left produces results
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 like this (with 8-bit binary numbers):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (lsh 3 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 @result{} 12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 ;; @r{Decimal 3 becomes decimal 12.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 00000011 @result{} 00001100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 On the other hand, shifting one place to the right looks like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (lsh 6 -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 @result{} 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 ;; @r{Decimal 6 becomes decimal 3.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 00000110 @result{} 00000011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (lsh 5 -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 @result{} 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 ;; @r{Decimal 5 becomes decimal 2.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 00000101 @result{} 00000010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 As the example illustrates, shifting one place to the right divides the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 value of a positive integer by two, rounding downward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 The function @code{lsh}, like all XEmacs Lisp arithmetic functions, does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 not check for overflow, so shifting left can discard significant bits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 and change the sign of the number. For example, left shifting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 134,217,727 produces @minus{}2 on a 28-bit machine:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (lsh 134217727 1) ; @r{left shift}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 @result{} -2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 In binary, in the 28-bit implementation, the argument looks like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 ;; @r{Decimal 134,217,727}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 0111 1111 1111 1111 1111 1111 1111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 which becomes the following when left shifted:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 ;; @r{Decimal @minus{}2}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 1111 1111 1111 1111 1111 1111 1110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 @defun ash integer1 count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 @cindex arithmetic shift
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 @code{ash} (@dfn{arithmetic shift}) shifts the bits in @var{integer1}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 to the left @var{count} places, or to the right if @var{count}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 is negative.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 @code{ash} gives the same results as @code{lsh} except when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 @var{integer1} and @var{count} are both negative. In that case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 @code{ash} puts ones in the empty bit positions on the left, while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 @code{lsh} puts zeros in those bit positions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 Thus, with @code{ash}, shifting the pattern of bits one place to the right
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 looks like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (ash -6 -1) @result{} -3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 ;; @r{Decimal @minus{}6 becomes decimal @minus{}3.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 1111 1111 1111 1111 1111 1111 1010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 @result{}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 1111 1111 1111 1111 1111 1111 1101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 In contrast, shifting the pattern of bits one place to the right with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 @code{lsh} looks like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (lsh -6 -1) @result{} 134217725
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 ;; @r{Decimal @minus{}6 becomes decimal 134,217,725.}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 1111 1111 1111 1111 1111 1111 1010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 @result{}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 0111 1111 1111 1111 1111 1111 1101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 Here are other examples:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 @c !!! Check if lined up in smallbook format! XDVI shows problem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 @c with smallbook but not with regular book! --rjc 16mar92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 @smallexample
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 ; @r{ 28-bit binary values}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (lsh 5 2) ; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 @result{} 20 ; = @r{0000 0000 0000 0000 0000 0001 0100}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (ash 5 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 @result{} 20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (lsh -5 2) ; -5 = @r{1111 1111 1111 1111 1111 1111 1011}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 @result{} -20 ; = @r{1111 1111 1111 1111 1111 1110 1100}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (ash -5 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 @result{} -20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (lsh 5 -2) ; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 @result{} 1 ; = @r{0000 0000 0000 0000 0000 0000 0001}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (ash 5 -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 @result{} 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (lsh -5 -2) ; -5 = @r{1111 1111 1111 1111 1111 1111 1011}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 @result{} 4194302 ; = @r{0011 1111 1111 1111 1111 1111 1110}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (ash -5 -2) ; -5 = @r{1111 1111 1111 1111 1111 1111 1011}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 @result{} -2 ; = @r{1111 1111 1111 1111 1111 1111 1110}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 @end smallexample
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 @defun logand &rest ints-or-markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 @cindex logical and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 @cindex bitwise and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 This function returns the ``logical and'' of the arguments: the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 @var{n}th bit is set in the result if, and only if, the @var{n}th bit is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 set in all the arguments. (``Set'' means that the value of the bit is 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 rather than 0.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 For example, using 4-bit binary numbers, the ``logical and'' of 13 and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 12 is 12: 1101 combined with 1100 produces 1100.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 In both the binary numbers, the leftmost two bits are set (i.e., they
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 are 1's), so the leftmost two bits of the returned value are set.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 However, for the rightmost two bits, each is zero in at least one of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 the arguments, so the rightmost two bits of the returned value are 0's.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 Therefore,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (logand 13 12)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 @result{} 12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 If @code{logand} is not passed any argument, it returns a value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 @minus{}1. This number is an identity element for @code{logand}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 because its binary representation consists entirely of ones. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 @code{logand} is passed just one argument, it returns that argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 @smallexample
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 ; @r{ 28-bit binary values}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (logand 14 13) ; 14 = @r{0000 0000 0000 0000 0000 0000 1110}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 ; 13 = @r{0000 0000 0000 0000 0000 0000 1101}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 @result{} 12 ; 12 = @r{0000 0000 0000 0000 0000 0000 1100}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (logand 14 13 4) ; 14 = @r{0000 0000 0000 0000 0000 0000 1110}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 ; 13 = @r{0000 0000 0000 0000 0000 0000 1101}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 ; 4 = @r{0000 0000 0000 0000 0000 0000 0100}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 @result{} 4 ; 4 = @r{0000 0000 0000 0000 0000 0000 0100}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (logand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 @result{} -1 ; -1 = @r{1111 1111 1111 1111 1111 1111 1111}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 @end smallexample
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 @defun logior &rest ints-or-markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 @cindex logical inclusive or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 @cindex bitwise or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 This function returns the ``inclusive or'' of its arguments: the @var{n}th bit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 is set in the result if, and only if, the @var{n}th bit is set in at least
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 one of the arguments. If there are no arguments, the result is zero,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 which is an identity element for this operation. If @code{logior} is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 passed just one argument, it returns that argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 @smallexample
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 ; @r{ 28-bit binary values}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (logior 12 5) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 ; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 @result{} 13 ; 13 = @r{0000 0000 0000 0000 0000 0000 1101}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (logior 12 5 7) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 ; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 ; 7 = @r{0000 0000 0000 0000 0000 0000 0111}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 @result{} 15 ; 15 = @r{0000 0000 0000 0000 0000 0000 1111}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 @end smallexample
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 @defun logxor &rest ints-or-markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 @cindex bitwise exclusive or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 @cindex logical exclusive or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 This function returns the ``exclusive or'' of its arguments: the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 @var{n}th bit is set in the result if, and only if, the @var{n}th bit is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 set in an odd number of the arguments. If there are no arguments, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 result is 0, which is an identity element for this operation. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 @code{logxor} is passed just one argument, it returns that argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 @smallexample
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 ; @r{ 28-bit binary values}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (logxor 12 5) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 ; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 @result{} 9 ; 9 = @r{0000 0000 0000 0000 0000 0000 1001}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 @group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (logxor 12 5 7) ; 12 = @r{0000 0000 0000 0000 0000 0000 1100}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 ; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 ; 7 = @r{0000 0000 0000 0000 0000 0000 0111}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 @result{} 14 ; 14 = @r{0000 0000 0000 0000 0000 0000 1110}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 @end group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 @end smallexample
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 @defun lognot integer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 @cindex logical not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 @cindex bitwise not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 This function returns the logical complement of its argument: the @var{n}th
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 bit is one in the result if, and only if, the @var{n}th bit is zero in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 @var{integer}, and vice-versa.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (lognot 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 @result{} -6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 ;; 5 = @r{0000 0000 0000 0000 0000 0000 0101}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 ;; @r{becomes}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 ;; -6 = @r{1111 1111 1111 1111 1111 1111 1010}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 @node Math Functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 @section Standard Mathematical Functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 @cindex transcendental functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 @cindex mathematical functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 These mathematical functions are available if floating point is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 supported (which is the normal state of affairs). They allow integers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 as well as floating point numbers as arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 @defun sin arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 @defunx cos arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 @defunx tan arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 These are the ordinary trigonometric functions, with argument measured
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 in radians.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 @defun asin arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 The value of @code{(asin @var{arg})} is a number between @minus{}pi/2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 and pi/2 (inclusive) whose sine is @var{arg}; if, however, @var{arg}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 is out of range (outside [-1, 1]), then the result is a NaN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 @defun acos arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 The value of @code{(acos @var{arg})} is a number between 0 and pi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (inclusive) whose cosine is @var{arg}; if, however, @var{arg}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 is out of range (outside [-1, 1]), then the result is a NaN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 @defun atan arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 The value of @code{(atan @var{arg})} is a number between @minus{}pi/2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 and pi/2 (exclusive) whose tangent is @var{arg}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 @defun sinh arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 @defunx cosh arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 @defunx tanh arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 These are the ordinary hyperbolic trigonometric functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 @defun asinh arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 @defunx acosh arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 @defunx atanh arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 These are the inverse hyperbolic trigonometric functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 @defun exp arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 This is the exponential function; it returns @i{e} to the power
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 @var{arg}. @i{e} is a fundamental mathematical constant also called the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 base of natural logarithms.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 @defun log arg &optional base
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 This function returns the logarithm of @var{arg}, with base @var{base}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 If you don't specify @var{base}, the base @var{e} is used. If @var{arg}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 is negative, the result is a NaN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 @ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 @defun expm1 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 This function returns @code{(1- (exp @var{arg}))}, but it is more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 accurate than that when @var{arg} is negative and @code{(exp @var{arg})}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 is close to 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 @defun log1p arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 This function returns @code{(log (1+ @var{arg}))}, but it is more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 accurate than that when @var{arg} is so small that adding 1 to it would
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 lose accuracy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 @end ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 @defun log10 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 This function returns the logarithm of @var{arg}, with base 10. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 @var{arg} is negative, the result is a NaN. @code{(log10 @var{x})}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 @equiv{} @code{(log @var{x} 10)}, at least approximately.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 @defun expt x y
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 This function returns @var{x} raised to power @var{y}. If both
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 arguments are integers and @var{y} is positive, the result is an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 integer; in this case, it is truncated to fit the range of possible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 integer values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 @defun sqrt arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 This returns the square root of @var{arg}. If @var{arg} is negative,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 the value is a NaN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 @defun cube-root arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 This returns the cube root of @var{arg}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 @end defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 @node Random Numbers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 @section Random Numbers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 @cindex random numbers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 A deterministic computer program cannot generate true random numbers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 For most purposes, @dfn{pseudo-random numbers} suffice. A series of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 pseudo-random numbers is generated in a deterministic fashion. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 numbers are not truly random, but they have certain properties that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 mimic a random series. For example, all possible values occur equally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 often in a pseudo-random series.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 In XEmacs, pseudo-random numbers are generated from a ``seed'' number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 Starting from any given seed, the @code{random} function always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 generates the same sequence of numbers. XEmacs always starts with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 same seed value, so the sequence of values of @code{random} is actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 the same in each XEmacs run! For example, in one operating system, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 first call to @code{(random)} after you start XEmacs always returns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 -1457731, and the second one always returns -7692030. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 repeatability is helpful for debugging.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 If you want truly unpredictable random numbers, execute @code{(random
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 t)}. This chooses a new seed based on the current time of day and on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 XEmacs's process @sc{id} number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 @defun random &optional limit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 This function returns a pseudo-random integer. Repeated calls return a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 series of pseudo-random integers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 If @var{limit} is a positive integer, the value is chosen to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 nonnegative and less than @var{limit}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 If @var{limit} is @code{t}, it means to choose a new seed based on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 current time of day and on XEmacs's process @sc{id} number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 @c "XEmacs'" is incorrect usage!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 On some machines, any integer representable in Lisp may be the result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 of @code{random}. On other machines, the result can never be larger
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 than a certain maximum or less than a certain (negative) minimum.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 @end defun