annotate man/lispref/numbers.texi @ 257:65c19d2020f7 r20-5b27

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