XEmacs 21.2.28 "Hermes".
[chise/xemacs-chise.git.1] / info / lispref.info-4
1 This is ../info/lispref.info, produced by makeinfo version 4.0 from
2 lispref/lispref.texi.
3
4 INFO-DIR-SECTION XEmacs Editor
5 START-INFO-DIR-ENTRY
6 * Lispref: (lispref).           XEmacs Lisp Reference Manual.
7 END-INFO-DIR-ENTRY
8
9    Edition History:
10
11    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
12 Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
13 Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
14 XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
15 GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
16 Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
17 Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
18 Reference Manual (for 19.15 and 20.1, 20.2, 20.3) v3.2, April, May,
19 November 1997 XEmacs Lisp Reference Manual (for 21.0) v3.3, April 1998
20
21    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
22 Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
23 Copyright (C) 1995, 1996 Ben Wing.
24
25    Permission is granted to make and distribute verbatim copies of this
26 manual provided the copyright notice and this permission notice are
27 preserved on all copies.
28
29    Permission is granted to copy and distribute modified versions of
30 this manual under the conditions for verbatim copying, provided that the
31 entire resulting derived work is distributed under the terms of a
32 permission notice identical to this one.
33
34    Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that this permission notice may be stated in a
37 translation approved by the Foundation.
38
39    Permission is granted to copy and distribute modified versions of
40 this manual under the conditions for verbatim copying, provided also
41 that the section entitled "GNU General Public License" is included
42 exactly as in the original, and provided that the entire resulting
43 derived work is distributed under the terms of a permission notice
44 identical to this one.
45
46    Permission is granted to copy and distribute translations of this
47 manual into another language, under the above conditions for modified
48 versions, except that the section entitled "GNU General Public License"
49 may be included in a translation approved by the Free Software
50 Foundation instead of in the original English.
51
52 \1f
53 File: lispref.info,  Node: Specifier Type,  Next: Font Instance Type,  Prev: Glyph Type,  Up: Window-System Types
54
55 Specifier Type
56 --------------
57
58    (not yet documented)
59
60 \1f
61 File: lispref.info,  Node: Font Instance Type,  Next: Color Instance Type,  Prev: Specifier Type,  Up: Window-System Types
62
63 Font Instance Type
64 ------------------
65
66    (not yet documented)
67
68 \1f
69 File: lispref.info,  Node: Color Instance Type,  Next: Image Instance Type,  Prev: Font Instance Type,  Up: Window-System Types
70
71 Color Instance Type
72 -------------------
73
74    (not yet documented)
75
76 \1f
77 File: lispref.info,  Node: Image Instance Type,  Next: Toolbar Button Type,  Prev: Color Instance Type,  Up: Window-System Types
78
79 Image Instance Type
80 -------------------
81
82    (not yet documented)
83
84 \1f
85 File: lispref.info,  Node: Toolbar Button Type,  Next: Subwindow Type,  Prev: Image Instance Type,  Up: Window-System Types
86
87 Toolbar Button Type
88 -------------------
89
90    (not yet documented)
91
92 \1f
93 File: lispref.info,  Node: Subwindow Type,  Next: X Resource Type,  Prev: Toolbar Button Type,  Up: Window-System Types
94
95 Subwindow Type
96 --------------
97
98    (not yet documented)
99
100 \1f
101 File: lispref.info,  Node: X Resource Type,  Prev: Subwindow Type,  Up: Window-System Types
102
103 X Resource Type
104 ---------------
105
106    (not yet documented)
107
108 \1f
109 File: lispref.info,  Node: Type Predicates,  Next: Equality Predicates,  Prev: Window-System Types,  Up: Lisp Data Types
110
111 Type Predicates
112 ===============
113
114    The XEmacs Lisp interpreter itself does not perform type checking on
115 the actual arguments passed to functions when they are called.  It could
116 not do so, since function arguments in Lisp do not have declared data
117 types, as they do in other programming languages.  It is therefore up to
118 the individual function to test whether each actual argument belongs to
119 a type that the function can use.
120
121    All built-in functions do check the types of their actual arguments
122 when appropriate, and signal a `wrong-type-argument' error if an
123 argument is of the wrong type.  For example, here is what happens if you
124 pass an argument to `+' that it cannot handle:
125
126      (+ 2 'a)
127           error--> Wrong type argument: integer-or-marker-p, a
128
129    If you want your program to handle different types differently, you
130 must do explicit type checking.  The most common way to check the type
131 of an object is to call a "type predicate" function.  Emacs has a type
132 predicate for each type, as well as some predicates for combinations of
133 types.
134
135    A type predicate function takes one argument; it returns `t' if the
136 argument belongs to the appropriate type, and `nil' otherwise.
137 Following a general Lisp convention for predicate functions, most type
138 predicates' names end with `p'.
139
140    Here is an example which uses the predicates `listp' to check for a
141 list and `symbolp' to check for a symbol.
142
143      (defun add-on (x)
144        (cond ((symbolp x)
145               ;; If X is a symbol, put it on LIST.
146               (setq list (cons x list)))
147              ((listp x)
148               ;; If X is a list, add its elements to LIST.
149               (setq list (append x list)))
150              (t
151               ;; We only handle symbols and lists.
152               (error "Invalid argument %s in add-on" x))))
153
154    Here is a table of predefined type predicates, in alphabetical order,
155 with references to further information.
156
157 `annotationp'
158      *Note annotationp: Annotation Primitives.
159
160 `arrayp'
161      *Note arrayp: Array Functions.
162
163 `atom'
164      *Note atom: List-related Predicates.
165
166 `bit-vector-p'
167      *Note bit-vector-p: Bit Vector Functions.
168
169 `bitp'
170      *Note bitp: Bit Vector Functions.
171
172 `boolean-specifier-p'
173      *Note boolean-specifier-p: Specifier Types.
174
175 `buffer-glyph-p'
176      *Note buffer-glyph-p: Glyph Types.
177
178 `buffer-live-p'
179      *Note buffer-live-p: Killing Buffers.
180
181 `bufferp'
182      *Note bufferp: Buffer Basics.
183
184 `button-event-p'
185      *Note button-event-p: Event Predicates.
186
187 `button-press-event-p'
188      *Note button-press-event-p: Event Predicates.
189
190 `button-release-event-p'
191      *Note button-release-event-p: Event Predicates.
192
193 `case-table-p'
194      *Note case-table-p: Case Tables.
195
196 `char-int-p'
197      *Note char-int-p: Character Codes.
198
199 `char-or-char-int-p'
200      *Note char-or-char-int-p: Character Codes.
201
202 `char-or-string-p'
203      *Note char-or-string-p: Predicates for Strings.
204
205 `char-table-p'
206      *Note char-table-p: Char Tables.
207
208 `characterp'
209      *Note characterp: Predicates for Characters.
210
211 `color-instance-p'
212      *Note color-instance-p: Colors.
213
214 `color-pixmap-image-instance-p'
215      *Note color-pixmap-image-instance-p: Image Instance Types.
216
217 `color-specifier-p'
218      *Note color-specifier-p: Specifier Types.
219
220 `commandp'
221      *Note commandp: Interactive Call.
222
223 `compiled-function-p'
224      *Note compiled-function-p: Compiled-Function Type.
225
226 `console-live-p'
227      *Note console-live-p: Connecting to a Console or Device.
228
229 `consolep'
230      *Note consolep: Consoles and Devices.
231
232 `consp'
233      *Note consp: List-related Predicates.
234
235 `database-live-p'
236      *Note database-live-p: Connecting to a Database.
237
238 `databasep'
239      *Note databasep: Databases.
240
241 `device-live-p'
242      *Note device-live-p: Connecting to a Console or Device.
243
244 `device-or-frame-p'
245      *Note device-or-frame-p: Basic Device Functions.
246
247 `devicep'
248      *Note devicep: Consoles and Devices.
249
250 `eval-event-p'
251      *Note eval-event-p: Event Predicates.
252
253 `event-live-p'
254      *Note event-live-p: Event Predicates.
255
256 `eventp'
257      *Note eventp: Events.
258
259 `extent-live-p'
260      *Note extent-live-p: Creating and Modifying Extents.
261
262 `extentp'
263      *Note extentp: Extents.
264
265 `face-boolean-specifier-p'
266      *Note face-boolean-specifier-p: Specifier Types.
267
268 `facep'
269      *Note facep: Basic Face Functions.
270
271 `floatp'
272      *Note floatp: Predicates on Numbers.
273
274 `font-instance-p'
275      *Note font-instance-p: Fonts.
276
277 `font-specifier-p'
278      *Note font-specifier-p: Specifier Types.
279
280 `frame-live-p'
281      *Note frame-live-p: Deleting Frames.
282
283 `framep'
284      *Note framep: Frames.
285
286 `functionp'
287      (not yet documented)
288
289 `generic-specifier-p'
290      *Note generic-specifier-p: Specifier Types.
291
292 `glyphp'
293      *Note glyphp: Glyphs.
294
295 `hash-table-p'
296      *Note hash-table-p: Hash Tables.
297
298 `icon-glyph-p'
299      *Note icon-glyph-p: Glyph Types.
300
301 `image-instance-p'
302      *Note image-instance-p: Images.
303
304 `image-specifier-p'
305      *Note image-specifier-p: Specifier Types.
306
307 `integer-char-or-marker-p'
308      *Note integer-char-or-marker-p: Predicates on Markers.
309
310 `integer-or-char-p'
311      *Note integer-or-char-p: Predicates for Characters.
312
313 `integer-or-marker-p'
314      *Note integer-or-marker-p: Predicates on Markers.
315
316 `integer-specifier-p'
317      *Note integer-specifier-p: Specifier Types.
318
319 `integerp'
320      *Note integerp: Predicates on Numbers.
321
322 `itimerp'
323      (not yet documented)
324
325 `key-press-event-p'
326      *Note key-press-event-p: Event Predicates.
327
328 `keymapp'
329      *Note keymapp: Creating Keymaps.
330
331 `keywordp'
332      (not yet documented)
333
334 `listp'
335      *Note listp: List-related Predicates.
336
337 `markerp'
338      *Note markerp: Predicates on Markers.
339
340 `misc-user-event-p'
341      *Note misc-user-event-p: Event Predicates.
342
343 `mono-pixmap-image-instance-p'
344      *Note mono-pixmap-image-instance-p: Image Instance Types.
345
346 `motion-event-p'
347      *Note motion-event-p: Event Predicates.
348
349 `mouse-event-p'
350      *Note mouse-event-p: Event Predicates.
351
352 `natnum-specifier-p'
353      *Note natnum-specifier-p: Specifier Types.
354
355 `natnump'
356      *Note natnump: Predicates on Numbers.
357
358 `nlistp'
359      *Note nlistp: List-related Predicates.
360
361 `nothing-image-instance-p'
362      *Note nothing-image-instance-p: Image Instance Types.
363
364 `number-char-or-marker-p'
365      *Note number-char-or-marker-p: Predicates on Markers.
366
367 `number-or-marker-p'
368      *Note number-or-marker-p: Predicates on Markers.
369
370 `numberp'
371      *Note numberp: Predicates on Numbers.
372
373 `pointer-glyph-p'
374      *Note pointer-glyph-p: Glyph Types.
375
376 `pointer-image-instance-p'
377      *Note pointer-image-instance-p: Image Instance Types.
378
379 `process-event-p'
380      *Note process-event-p: Event Predicates.
381
382 `processp'
383      *Note processp: Processes.
384
385 `range-table-p'
386      *Note range-table-p: Range Tables.
387
388 `ringp'
389      (not yet documented)
390
391 `sequencep'
392      *Note sequencep: Sequence Functions.
393
394 `specifierp'
395      *Note specifierp: Specifiers.
396
397 `stringp'
398      *Note stringp: Predicates for Strings.
399
400 `subrp'
401      *Note subrp: Function Cells.
402
403 `subwindow-image-instance-p'
404      *Note subwindow-image-instance-p: Image Instance Types.
405
406 `subwindowp'
407      *Note subwindowp: Subwindows.
408
409 `symbolp'
410      *Note symbolp: Symbols.
411
412 `syntax-table-p'
413      *Note syntax-table-p: Syntax Tables.
414
415 `text-image-instance-p'
416      *Note text-image-instance-p: Image Instance Types.
417
418 `timeout-event-p'
419      *Note timeout-event-p: Event Predicates.
420
421 `toolbar-button-p'
422      *Note toolbar-button-p: Toolbar.
423
424 `toolbar-specifier-p'
425      *Note toolbar-specifier-p: Toolbar.
426
427 `user-variable-p'
428      *Note user-variable-p: Defining Variables.
429
430 `vectorp'
431      *Note vectorp: Vectors.
432
433 `weak-list-p'
434      *Note weak-list-p: Weak Lists.
435
436 `window-configuration-p'
437      *Note window-configuration-p: Window Configurations.
438
439 `window-live-p'
440      *Note window-live-p: Deleting Windows.
441
442 `windowp'
443      *Note windowp: Basic Windows.
444
445    The most general way to check the type of an object is to call the
446 function `type-of'.  Recall that each object belongs to one and only
447 one primitive type; `type-of' tells you which one (*note Lisp Data
448 Types::).  But `type-of' knows nothing about non-primitive types.  In
449 most cases, it is more convenient to use type predicates than `type-of'.
450
451  - Function: type-of object
452      This function returns a symbol naming the primitive type of
453      OBJECT.  The value is one of `bit-vector', `buffer', `char-table',
454      `character', `charset', `coding-system', `cons', `color-instance',
455      `compiled-function', `console', `database', `device', `event',
456      `extent', `face', `float', `font-instance', `frame', `glyph',
457      `hash-table', `image-instance', `integer', `keymap', `marker',
458      `process', `range-table', `specifier', `string', `subr',
459      `subwindow', `symbol', `toolbar-button', `tooltalk-message',
460      `tooltalk-pattern', `vector', `weak-list', `window',
461      `window-configuration', or `x-resource'.
462
463           (type-of 1)
464                => integer
465           (type-of 'nil)
466                => symbol
467           (type-of '())    ; `()' is `nil'.
468                => symbol
469           (type-of '(x))
470                => cons
471
472 \1f
473 File: lispref.info,  Node: Equality Predicates,  Prev: Type Predicates,  Up: Lisp Data Types
474
475 Equality Predicates
476 ===================
477
478    Here we describe two functions that test for equality between any two
479 objects.  Other functions test equality between objects of specific
480 types, e.g., strings.  For these predicates, see the appropriate chapter
481 describing the data type.
482
483  - Function: eq object1 object2
484      This function returns `t' if OBJECT1 and OBJECT2 are the same
485      object, `nil' otherwise.  The "same object" means that a change in
486      one will be reflected by the same change in the other.
487
488      `eq' returns `t' if OBJECT1 and OBJECT2 are integers with the same
489      value.  Also, since symbol names are normally unique, if the
490      arguments are symbols with the same name, they are `eq'.  For
491      other types (e.g., lists, vectors, strings), two arguments with
492      the same contents or elements are not necessarily `eq' to each
493      other: they are `eq' only if they are the same object.
494
495      (The `make-symbol' function returns an uninterned symbol that is
496      not interned in the standard `obarray'.  When uninterned symbols
497      are in use, symbol names are no longer unique.  Distinct symbols
498      with the same name are not `eq'.  *Note Creating Symbols::.)
499
500      NOTE: Under XEmacs 19, characters are really just integers, and
501      thus characters and integers are `eq'.  Under XEmacs 20, it was
502      necessary to preserve remnants of this in function such as `old-eq'
503      in order to maintain byte-code compatibility.  Byte code compiled
504      under any Emacs 19 will automatically have calls to `eq' mapped to
505      `old-eq' when executed under XEmacs 20.
506
507           (eq 'foo 'foo)
508                => t
509           
510           (eq 456 456)
511                => t
512           
513           (eq "asdf" "asdf")
514                => nil
515           
516           (eq '(1 (2 (3))) '(1 (2 (3))))
517                => nil
518           
519           (setq foo '(1 (2 (3))))
520                => (1 (2 (3)))
521           (eq foo foo)
522                => t
523           (eq foo '(1 (2 (3))))
524                => nil
525           
526           (eq [(1 2) 3] [(1 2) 3])
527                => nil
528           
529           (eq (point-marker) (point-marker))
530                => nil
531
532
533  - Function: old-eq obj1 obj2
534      This function exists under XEmacs 20 and is exactly like `eq'
535      except that it suffers from the char-int confoundance disease.  In
536      other words, it returns `t' if given a character and the
537      equivalent integer, even though the objects are of different types!
538      You should _not_ ever call this function explicitly in your code.
539      However, be aware that all calls to `eq' in byte code compiled
540      under version 19 map to `old-eq' in XEmacs 20.  (Likewise for
541      `old-equal', `old-memq', `old-member', `old-assq' and
542      `old-assoc'.)
543
544           ;; Remember, this does not apply under XEmacs 19.
545           ?A
546                => ?A
547           (char-int ?A)
548                => 65
549           (old-eq ?A 65)
550                => t               ; Eek, we've been infected.
551           (eq ?A 65)
552                => nil             ; We are still healthy.
553
554  - Function: equal object1 object2
555      This function returns `t' if OBJECT1 and OBJECT2 have equal
556      components, `nil' otherwise.  Whereas `eq' tests if its arguments
557      are the same object, `equal' looks inside nonidentical arguments
558      to see if their elements are the same.  So, if two objects are
559      `eq', they are `equal', but the converse is not always true.
560
561           (equal 'foo 'foo)
562                => t
563           
564           (equal 456 456)
565                => t
566           
567           (equal "asdf" "asdf")
568                => t
569           (eq "asdf" "asdf")
570                => nil
571           
572           (equal '(1 (2 (3))) '(1 (2 (3))))
573                => t
574           (eq '(1 (2 (3))) '(1 (2 (3))))
575                => nil
576           
577           (equal [(1 2) 3] [(1 2) 3])
578                => t
579           (eq [(1 2) 3] [(1 2) 3])
580                => nil
581           
582           (equal (point-marker) (point-marker))
583                => t
584           
585           (eq (point-marker) (point-marker))
586                => nil
587
588      Comparison of strings is case-sensitive.
589
590      Note that in FSF GNU Emacs, comparison of strings takes into
591      account their text properties, and you have to use `string-equal'
592      if you want only the strings themselves compared.  This difference
593      does not exist in XEmacs; `equal' and `string-equal' always return
594      the same value on the same strings.
595
596           (equal "asdf" "ASDF")
597                => nil
598
599      Two distinct buffers are never `equal', even if their contents are
600      the same.
601
602    The test for equality is implemented recursively, and circular lists
603 may therefore cause infinite recursion (leading to an error).
604
605 \1f
606 File: lispref.info,  Node: Numbers,  Next: Strings and Characters,  Prev: Lisp Data Types,  Up: Top
607
608 Numbers
609 *******
610
611    XEmacs supports two numeric data types: "integers" and "floating
612 point numbers".  Integers are whole numbers such as -3, 0, #b0111,
613 #xFEED, #o744.  Their values are exact.  The number prefixes `#b',
614 `#o', and `#x' are supported to represent numbers in binary, octal, and
615 hexadecimal notation (or radix).  Floating point numbers are numbers
616 with fractional parts, such as -4.5, 0.0, or 2.71828.  They can also be
617 expressed in exponential notation: 1.5e2 equals 150; in this example,
618 `e2' stands for ten to the second power, and is multiplied by 1.5.
619 Floating point values are not exact; they have a fixed, limited amount
620 of precision.
621
622 * Menu:
623
624 * Integer Basics::            Representation and range of integers.
625 * Float Basics::              Representation and range of floating point.
626 * Predicates on Numbers::     Testing for numbers.
627 * Comparison of Numbers::     Equality and inequality predicates.
628 * Numeric Conversions::       Converting float to integer and vice versa.
629 * Arithmetic Operations::     How to add, subtract, multiply and divide.
630 * Rounding Operations::       Explicitly rounding floating point numbers.
631 * Bitwise Operations::        Logical and, or, not, shifting.
632 * Math Functions::            Trig, exponential and logarithmic functions.
633 * Random Numbers::            Obtaining random integers, predictable or not.
634
635 \1f
636 File: lispref.info,  Node: Integer Basics,  Next: Float Basics,  Up: Numbers
637
638 Integer Basics
639 ==============
640
641    The range of values for an integer depends on the machine.  The
642 minimum range is -134217728 to 134217727 (28 bits; i.e., -2**27 to
643 2**27 - 1), but some machines may provide a wider range.  Many examples
644 in this chapter assume an integer has 28 bits.
645
646    The Lisp reader reads an integer as a sequence of digits with
647 optional initial sign and optional final period.
648
649       1               ; The integer 1.
650       1.              ; The integer 1.
651      +1               ; Also the integer 1.
652      -1               ; The integer -1.
653       268435457       ; Also the integer 1, due to overflow.
654       0               ; The integer 0.
655      -0               ; The integer 0.
656
657    To understand how various functions work on integers, especially the
658 bitwise operators (*note Bitwise Operations::), it is often helpful to
659 view the numbers in their binary form.
660
661    In 28-bit binary, the decimal integer 5 looks like this:
662
663      0000  0000 0000  0000 0000  0000 0101
664
665 (We have inserted spaces between groups of 4 bits, and two spaces
666 between groups of 8 bits, to make the binary integer easier to read.)
667
668    The integer -1 looks like this:
669
670      1111  1111 1111  1111 1111  1111 1111
671
672 -1 is represented as 28 ones.  (This is called "two's complement"
673 notation.)
674
675    The negative integer, -5, is creating by subtracting 4 from -1.  In
676 binary, the decimal integer 4 is 100.  Consequently, -5 looks like this:
677
678      1111  1111 1111  1111 1111  1111 1011
679
680    In this implementation, the largest 28-bit binary integer is the
681 decimal integer 134,217,727.  In binary, it looks like this:
682
683      0111  1111 1111  1111 1111  1111 1111
684
685    Since the arithmetic functions do not check whether integers go
686 outside their range, when you add 1 to 134,217,727, the value is the
687 negative integer -134,217,728:
688
689      (+ 1 134217727)
690           => -134217728
691           => 1000  0000 0000  0000 0000  0000 0000
692
693    Many of the following functions accept markers for arguments as well
694 as integers.  (*Note Markers::.)  More precisely, the actual arguments
695 to such functions may be either integers or markers, which is why we
696 often give these arguments the name INT-OR-MARKER.  When the argument
697 value is a marker, its position value is used and its buffer is ignored.
698
699 \1f
700 File: lispref.info,  Node: Float Basics,  Next: Predicates on Numbers,  Prev: Integer Basics,  Up: Numbers
701
702 Floating Point Basics
703 =====================
704
705    XEmacs supports floating point numbers.  The precise range of
706 floating point numbers is machine-specific; it is the same as the range
707 of the C data type `double' on the machine in question.
708
709    The printed representation for floating point numbers requires either
710 a decimal point (with at least one digit following), an exponent, or
711 both.  For example, `1500.0', `15e2', `15.0e2', `1.5e3', and `.15e4'
712 are five ways of writing a floating point number whose value is 1500.
713 They are all equivalent.  You can also use a minus sign to write
714 negative floating point numbers, as in `-1.0'.
715
716    Most modern computers support the IEEE floating point standard, which
717 provides for positive infinity and negative infinity as floating point
718 values.  It also provides for a class of values called NaN or
719 "not-a-number"; numerical functions return such values in cases where
720 there is no correct answer.  For example, `(sqrt -1.0)' returns a NaN.
721 For practical purposes, there's no significant difference between
722 different NaN values in XEmacs Lisp, and there's no rule for precisely
723 which NaN value should be used in a particular case, so this manual
724 doesn't try to distinguish them.  XEmacs Lisp has no read syntax for
725 NaNs or infinities; perhaps we should create a syntax in the future.
726
727    You can use `logb' to extract the binary exponent of a floating
728 point number (or estimate the logarithm of an integer):
729
730  - Function: logb number
731      This function returns the binary exponent of NUMBER.  More
732      precisely, the value is the logarithm of NUMBER base 2, rounded
733      down to an integer.
734
735 \1f
736 File: lispref.info,  Node: Predicates on Numbers,  Next: Comparison of Numbers,  Prev: Float Basics,  Up: Numbers
737
738 Type Predicates for Numbers
739 ===========================
740
741    The functions in this section test whether the argument is a number
742 or whether it is a certain sort of number.  The functions `integerp'
743 and `floatp' can take any type of Lisp object as argument (the
744 predicates would not be of much use otherwise); but the `zerop'
745 predicate requires a number as its argument.  See also
746 `integer-or-marker-p', `integer-char-or-marker-p', `number-or-marker-p'
747 and `number-char-or-marker-p', in *Note Predicates on Markers::.
748
749  - Function: floatp object
750      This predicate tests whether its argument is a floating point
751      number and returns `t' if so, `nil' otherwise.
752
753      `floatp' does not exist in Emacs versions 18 and earlier.
754
755  - Function: integerp object
756      This predicate tests whether its argument is an integer, and
757      returns `t' if so, `nil' otherwise.
758
759  - Function: numberp object
760      This predicate tests whether its argument is a number (either
761      integer or floating point), and returns `t' if so, `nil' otherwise.
762
763  - Function: natnump object
764      The `natnump' predicate (whose name comes from the phrase
765      "natural-number-p") tests to see whether its argument is a
766      nonnegative integer, and returns `t' if so, `nil' otherwise.  0 is
767      considered non-negative.
768
769  - Function: zerop number
770      This predicate tests whether its argument is zero, and returns `t'
771      if so, `nil' otherwise.  The argument must be a number.
772
773      These two forms are equivalent: `(zerop x)' == `(= x 0)'.
774
775 \1f
776 File: lispref.info,  Node: Comparison of Numbers,  Next: Numeric Conversions,  Prev: Predicates on Numbers,  Up: Numbers
777
778 Comparison of Numbers
779 =====================
780
781    To test numbers for numerical equality, you should normally use `=',
782 not `eq'.  There can be many distinct floating point number objects
783 with the same numeric value.  If you use `eq' to compare them, then you
784 test whether two values are the same _object_.  By contrast, `='
785 compares only the numeric values of the objects.
786
787    At present, each integer value has a unique Lisp object in XEmacs
788 Lisp.  Therefore, `eq' is equivalent to `=' where integers are
789 concerned.  It is sometimes convenient to use `eq' for comparing an
790 unknown value with an integer, because `eq' does not report an error if
791 the unknown value is not a number--it accepts arguments of any type.
792 By contrast, `=' signals an error if the arguments are not numbers or
793 markers.  However, it is a good idea to use `=' if you can, even for
794 comparing integers, just in case we change the representation of
795 integers in a future XEmacs version.
796
797    There is another wrinkle: because floating point arithmetic is not
798 exact, it is often a bad idea to check for equality of two floating
799 point values.  Usually it is better to test for approximate equality.
800 Here's a function to do this:
801
802      (defconst fuzz-factor 1.0e-6)
803      (defun approx-equal (x y)
804        (or (and (= x 0) (= y 0))
805            (< (/ (abs (- x y))
806                  (max (abs x) (abs y)))
807               fuzz-factor)))
808
809      Common Lisp note: Comparing numbers in Common Lisp always requires
810      `=' because Common Lisp implements multi-word integers, and two
811      distinct integer objects can have the same numeric value.  XEmacs
812      Lisp can have just one integer object for any given value because
813      it has a limited range of integer values.
814
815    In addition to numbers, all of the following functions also accept
816 characters and markers as arguments, and treat them as their number
817 equivalents.
818
819  - Function: = number &rest more-numbers
820      This function returns `t' if all of its arguments are numerically
821      equal, `nil' otherwise.
822
823           (= 5)
824                => t
825           (= 5 6)
826                => nil
827           (= 5 5.0)
828                => t
829           (= 5 5 6)
830                => nil
831
832  - Function: /= number &rest more-numbers
833      This function returns `t' if no two arguments are numerically
834      equal, `nil' otherwise.
835
836           (/= 5 6)
837                => t
838           (/= 5 5 6)
839                => nil
840           (/= 5 6 1)
841                => t
842
843  - Function: < number &rest more-numbers
844      This function returns `t' if the sequence of its arguments is
845      monotonically increasing, `nil' otherwise.
846
847           (< 5 6)
848                => t
849           (< 5 6 6)
850                => nil
851           (< 5 6 7)
852                => t
853
854  - Function: <= number &rest more-numbers
855      This function returns `t' if the sequence of its arguments is
856      monotonically nondecreasing, `nil' otherwise.
857
858           (<= 5 6)
859                => t
860           (<= 5 6 6)
861                => t
862           (<= 5 6 5)
863                => nil
864
865  - Function: > number &rest more-numbers
866      This function returns `t' if the sequence of its arguments is
867      monotonically decreasing, `nil' otherwise.
868
869  - Function: >= number &rest more-numbers
870      This function returns `t' if the sequence of its arguments is
871      monotonically nonincreasing, `nil' otherwise.
872
873  - Function: max number &rest more-numbers
874      This function returns the largest of its arguments.
875
876           (max 20)
877                => 20
878           (max 1 2.5)
879                => 2.5
880           (max 1 3 2.5)
881                => 3
882
883  - Function: min number &rest more-numbers
884      This function returns the smallest of its arguments.
885
886           (min -4 1)
887                => -4
888
889 \1f
890 File: lispref.info,  Node: Numeric Conversions,  Next: Arithmetic Operations,  Prev: Comparison of Numbers,  Up: Numbers
891
892 Numeric Conversions
893 ===================
894
895    To convert an integer to floating point, use the function `float'.
896
897  - Function: float number
898      This returns NUMBER converted to floating point.  If NUMBER is
899      already a floating point number, `float' returns it unchanged.
900
901    There are four functions to convert floating point numbers to
902 integers; they differ in how they round.  These functions accept
903 integer arguments also, and return such arguments unchanged.
904
905  - Function: truncate number
906      This returns NUMBER, converted to an integer by rounding towards
907      zero.
908
909  - Function: floor number &optional divisor
910      This returns NUMBER, converted to an integer by rounding downward
911      (towards negative infinity).
912
913      If DIVISOR is specified, NUMBER is divided by DIVISOR before the
914      floor is taken; this is the division operation that corresponds to
915      `mod'.  An `arith-error' results if DIVISOR is 0.
916
917  - Function: ceiling number
918      This returns NUMBER, converted to an integer by rounding upward
919      (towards positive infinity).
920
921  - Function: round number
922      This returns NUMBER, converted to an integer by rounding towards
923      the nearest integer.  Rounding a value equidistant between two
924      integers may choose the integer closer to zero, or it may prefer
925      an even integer, depending on your machine.
926
927 \1f
928 File: lispref.info,  Node: Arithmetic Operations,  Next: Rounding Operations,  Prev: Numeric Conversions,  Up: Numbers
929
930 Arithmetic Operations
931 =====================
932
933    XEmacs Lisp provides the traditional four arithmetic operations:
934 addition, subtraction, multiplication, and division.  Remainder and
935 modulus functions supplement the division functions.  The functions to
936 add or subtract 1 are provided because they are traditional in Lisp and
937 commonly used.
938
939    All of these functions except `%' return a floating point value if
940 any argument is floating.
941
942    It is important to note that in XEmacs Lisp, arithmetic functions do
943 not check for overflow.  Thus `(1+ 134217727)' may evaluate to
944 -134217728, depending on your hardware.
945
946  - Function: 1+ number-or-marker
947      This function returns NUMBER-OR-MARKER plus 1.  For example,
948
949           (setq foo 4)
950                => 4
951           (1+ foo)
952                => 5
953
954      This function is not analogous to the C operator `++'--it does not
955      increment a variable.  It just computes a sum.  Thus, if we
956      continue,
957
958           foo
959                => 4
960
961      If you want to increment the variable, you must use `setq', like
962      this:
963
964           (setq foo (1+ foo))
965                => 5
966
967      Now that the `cl' package is always available from lisp code, a
968      more convenient and natural way to increment a variable is
969      `(incf foo)'.
970
971  - Function: 1- number-or-marker
972      This function returns NUMBER-OR-MARKER minus 1.
973
974  - Function: abs number
975      This returns the absolute value of NUMBER.
976
977  - Function: + &rest numbers-or-markers
978      This function adds its arguments together.  When given no
979      arguments, `+' returns 0.
980
981           (+)
982                => 0
983           (+ 1)
984                => 1
985           (+ 1 2 3 4)
986                => 10
987
988  - Function: - &optional number-or-marker &rest other-numbers-or-markers
989      The `-' function serves two purposes: negation and subtraction.
990      When `-' has a single argument, the value is the negative of the
991      argument.  When there are multiple arguments, `-' subtracts each of
992      the OTHER-NUMBERS-OR-MARKERS from NUMBER-OR-MARKER, cumulatively.
993      If there are no arguments, the result is 0.
994
995           (- 10 1 2 3 4)
996                => 0
997           (- 10)
998                => -10
999           (-)
1000                => 0
1001
1002  - Function: * &rest numbers-or-markers
1003      This function multiplies its arguments together, and returns the
1004      product.  When given no arguments, `*' returns 1.
1005
1006           (*)
1007                => 1
1008           (* 1)
1009                => 1
1010           (* 1 2 3 4)
1011                => 24
1012
1013  - Function: / dividend divisor &rest divisors
1014      This function divides DIVIDEND by DIVISOR and returns the
1015      quotient.  If there are additional arguments DIVISORS, then it
1016      divides DIVIDEND by each divisor in turn.  Each argument may be a
1017      number or a marker.
1018
1019      If all the arguments are integers, then the result is an integer
1020      too.  This means the result has to be rounded.  On most machines,
1021      the result is rounded towards zero after each division, but some
1022      machines may round differently with negative arguments.  This is
1023      because the Lisp function `/' is implemented using the C division
1024      operator, which also permits machine-dependent rounding.  As a
1025      practical matter, all known machines round in the standard fashion.
1026
1027      If you divide by 0, an `arith-error' error is signaled.  (*Note
1028      Errors::.)
1029
1030           (/ 6 2)
1031                => 3
1032           (/ 5 2)
1033                => 2
1034           (/ 25 3 2)
1035                => 4
1036           (/ -17 6)
1037                => -2
1038
1039      The result of `(/ -17 6)' could in principle be -3 on some
1040      machines.
1041
1042  - Function: % dividend divisor
1043      This function returns the integer remainder after division of
1044      DIVIDEND by DIVISOR.  The arguments must be integers or markers.
1045
1046      For negative arguments, the remainder is in principle
1047      machine-dependent since the quotient is; but in practice, all
1048      known machines behave alike.
1049
1050      An `arith-error' results if DIVISOR is 0.
1051
1052           (% 9 4)
1053                => 1
1054           (% -9 4)
1055                => -1
1056           (% 9 -4)
1057                => 1
1058           (% -9 -4)
1059                => -1
1060
1061      For any two integers DIVIDEND and DIVISOR,
1062
1063           (+ (% DIVIDEND DIVISOR)
1064              (* (/ DIVIDEND DIVISOR) DIVISOR))
1065
1066      always equals DIVIDEND.
1067
1068  - Function: mod dividend divisor
1069      This function returns the value of DIVIDEND modulo DIVISOR; in
1070      other words, the remainder after division of DIVIDEND by DIVISOR,
1071      but with the same sign as DIVISOR.  The arguments must be numbers
1072      or markers.
1073
1074      Unlike `%', `mod' returns a well-defined result for negative
1075      arguments.  It also permits floating point arguments; it rounds the
1076      quotient downward (towards minus infinity) to an integer, and uses
1077      that quotient to compute the remainder.
1078
1079      An `arith-error' results if DIVISOR is 0.
1080
1081           (mod 9 4)
1082                => 1
1083           (mod -9 4)
1084                => 3
1085           (mod 9 -4)
1086                => -3
1087           (mod -9 -4)
1088                => -1
1089           (mod 5.5 2.5)
1090                => .5
1091
1092      For any two numbers DIVIDEND and DIVISOR,
1093
1094           (+ (mod DIVIDEND DIVISOR)
1095              (* (floor DIVIDEND DIVISOR) DIVISOR))
1096
1097      always equals DIVIDEND, subject to rounding error if either
1098      argument is floating point.  For `floor', see *Note Numeric
1099      Conversions::.
1100
1101 \1f
1102 File: lispref.info,  Node: Rounding Operations,  Next: Bitwise Operations,  Prev: Arithmetic Operations,  Up: Numbers
1103
1104 Rounding Operations
1105 ===================
1106
1107    The functions `ffloor', `fceiling', `fround' and `ftruncate' take a
1108 floating point argument and return a floating point result whose value
1109 is a nearby integer.  `ffloor' returns the nearest integer below;
1110 `fceiling', the nearest integer above; `ftruncate', the nearest integer
1111 in the direction towards zero; `fround', the nearest integer.
1112
1113  - Function: ffloor float
1114      This function rounds FLOAT to the next lower integral value, and
1115      returns that value as a floating point number.
1116
1117  - Function: fceiling float
1118      This function rounds FLOAT to the next higher integral value, and
1119      returns that value as a floating point number.
1120
1121  - Function: ftruncate float
1122      This function rounds FLOAT towards zero to an integral value, and
1123      returns that value as a floating point number.
1124
1125  - Function: fround float
1126      This function rounds FLOAT to the nearest integral value, and
1127      returns that value as a floating point number.
1128
1129 \1f
1130 File: lispref.info,  Node: Bitwise Operations,  Next: Math Functions,  Prev: Rounding Operations,  Up: Numbers
1131
1132 Bitwise Operations on Integers
1133 ==============================
1134
1135    In a computer, an integer is represented as a binary number, a
1136 sequence of "bits" (digits which are either zero or one).  A bitwise
1137 operation acts on the individual bits of such a sequence.  For example,
1138 "shifting" moves the whole sequence left or right one or more places,
1139 reproducing the same pattern "moved over".
1140
1141    The bitwise operations in XEmacs Lisp apply only to integers.
1142
1143  - Function: lsh integer1 count
1144      `lsh', which is an abbreviation for "logical shift", shifts the
1145      bits in INTEGER1 to the left COUNT places, or to the right if
1146      COUNT is negative, bringing zeros into the vacated bits.  If COUNT
1147      is negative, `lsh' shifts zeros into the leftmost
1148      (most-significant) bit, producing a positive result even if
1149      INTEGER1 is negative.  Contrast this with `ash', below.
1150
1151      Here are two examples of `lsh', shifting a pattern of bits one
1152      place to the left.  We show only the low-order eight bits of the
1153      binary pattern; the rest are all zero.
1154
1155           (lsh 5 1)
1156                => 10
1157           ;; Decimal 5 becomes decimal 10.
1158           00000101 => 00001010
1159           
1160           (lsh 7 1)
1161                => 14
1162           ;; Decimal 7 becomes decimal 14.
1163           00000111 => 00001110
1164
1165      As the examples illustrate, shifting the pattern of bits one place
1166      to the left produces a number that is twice the value of the
1167      previous number.
1168
1169      Shifting a pattern of bits two places to the left produces results
1170      like this (with 8-bit binary numbers):
1171
1172           (lsh 3 2)
1173                => 12
1174           ;; Decimal 3 becomes decimal 12.
1175           00000011 => 00001100
1176
1177      On the other hand, shifting one place to the right looks like this:
1178
1179           (lsh 6 -1)
1180                => 3
1181           ;; Decimal 6 becomes decimal 3.
1182           00000110 => 00000011
1183           
1184           (lsh 5 -1)
1185                => 2
1186           ;; Decimal 5 becomes decimal 2.
1187           00000101 => 00000010
1188
1189      As the example illustrates, shifting one place to the right
1190      divides the value of a positive integer by two, rounding downward.
1191
1192      The function `lsh', like all XEmacs Lisp arithmetic functions, does
1193      not check for overflow, so shifting left can discard significant
1194      bits and change the sign of the number.  For example, left shifting
1195      134,217,727 produces -2 on a 28-bit machine:
1196
1197           (lsh 134217727 1)          ; left shift
1198                => -2
1199
1200      In binary, in the 28-bit implementation, the argument looks like
1201      this:
1202
1203           ;; Decimal 134,217,727
1204           0111  1111 1111  1111 1111  1111 1111
1205
1206      which becomes the following when left shifted:
1207
1208           ;; Decimal -2
1209           1111  1111 1111  1111 1111  1111 1110
1210
1211  - Function: ash integer1 count
1212      `ash' ("arithmetic shift") shifts the bits in INTEGER1 to the left
1213      COUNT places, or to the right if COUNT is negative.
1214
1215      `ash' gives the same results as `lsh' except when INTEGER1 and
1216      COUNT are both negative.  In that case, `ash' puts ones in the
1217      empty bit positions on the left, while `lsh' puts zeros in those
1218      bit positions.
1219
1220      Thus, with `ash', shifting the pattern of bits one place to the
1221      right looks like this:
1222
1223           (ash -6 -1) => -3
1224           ;; Decimal -6 becomes decimal -3.
1225           1111  1111 1111  1111 1111  1111 1010
1226                =>
1227           1111  1111 1111  1111 1111  1111 1101
1228
1229      In contrast, shifting the pattern of bits one place to the right
1230      with `lsh' looks like this:
1231
1232           (lsh -6 -1) => 134217725
1233           ;; Decimal -6 becomes decimal 134,217,725.
1234           1111  1111 1111  1111 1111  1111 1010
1235                =>
1236           0111  1111 1111  1111 1111  1111 1101
1237
1238      Here are other examples:
1239
1240                              ;               28-bit binary values
1241           
1242           (lsh 5 2)          ;   5  =  0000  0000 0000  0000 0000  0000 0101
1243                => 20         ;      =  0000  0000 0000  0000 0000  0001 0100
1244           (ash 5 2)
1245                => 20
1246           (lsh -5 2)         ;  -5  =  1111  1111 1111  1111 1111  1111 1011
1247                => -20        ;      =  1111  1111 1111  1111 1111  1110 1100
1248           (ash -5 2)
1249                => -20
1250           (lsh 5 -2)         ;   5  =  0000  0000 0000  0000 0000  0000 0101
1251                => 1          ;      =  0000  0000 0000  0000 0000  0000 0001
1252           (ash 5 -2)
1253                => 1
1254           (lsh -5 -2)        ;  -5  =  1111  1111 1111  1111 1111  1111 1011
1255                => 4194302    ;      =  0011  1111 1111  1111 1111  1111 1110
1256           (ash -5 -2)        ;  -5  =  1111  1111 1111  1111 1111  1111 1011
1257                => -2         ;      =  1111  1111 1111  1111 1111  1111 1110
1258
1259  - Function: logand &rest ints-or-markers
1260      This function returns the "logical and" of the arguments: the Nth
1261      bit is set in the result if, and only if, the Nth bit is set in
1262      all the arguments.  ("Set" means that the value of the bit is 1
1263      rather than 0.)
1264
1265      For example, using 4-bit binary numbers, the "logical and" of 13
1266      and 12 is 12: 1101 combined with 1100 produces 1100.  In both the
1267      binary numbers, the leftmost two bits are set (i.e., they are
1268      1's), so the leftmost two bits of the returned value are set.
1269      However, for the rightmost two bits, each is zero in at least one
1270      of the arguments, so the rightmost two bits of the returned value
1271      are 0's.
1272
1273      Therefore,
1274
1275           (logand 13 12)
1276                => 12
1277
1278      If `logand' is not passed any argument, it returns a value of -1.
1279      This number is an identity element for `logand' because its binary
1280      representation consists entirely of ones.  If `logand' is passed
1281      just one argument, it returns that argument.
1282
1283                              ;                28-bit binary values
1284           
1285           (logand 14 13)     ; 14  =  0000  0000 0000  0000 0000  0000 1110
1286                              ; 13  =  0000  0000 0000  0000 0000  0000 1101
1287                => 12         ; 12  =  0000  0000 0000  0000 0000  0000 1100
1288           
1289           (logand 14 13 4)   ; 14  =  0000  0000 0000  0000 0000  0000 1110
1290                              ; 13  =  0000  0000 0000  0000 0000  0000 1101
1291                              ;  4  =  0000  0000 0000  0000 0000  0000 0100
1292                => 4          ;  4  =  0000  0000 0000  0000 0000  0000 0100
1293           
1294           (logand)
1295                => -1         ; -1  =  1111  1111 1111  1111 1111  1111 1111
1296
1297  - Function: logior &rest ints-or-markers
1298      This function returns the "inclusive or" of its arguments: the Nth
1299      bit is set in the result if, and only if, the Nth bit is set in at
1300      least one of the arguments.  If there are no arguments, the result
1301      is zero, which is an identity element for this operation.  If
1302      `logior' is passed just one argument, it returns that argument.
1303
1304                              ;               28-bit binary values
1305           
1306           (logior 12 5)      ; 12  =  0000  0000 0000  0000 0000  0000 1100
1307                              ;  5  =  0000  0000 0000  0000 0000  0000 0101
1308                => 13         ; 13  =  0000  0000 0000  0000 0000  0000 1101
1309           
1310           (logior 12 5 7)    ; 12  =  0000  0000 0000  0000 0000  0000 1100
1311                              ;  5  =  0000  0000 0000  0000 0000  0000 0101
1312                              ;  7  =  0000  0000 0000  0000 0000  0000 0111
1313                => 15         ; 15  =  0000  0000 0000  0000 0000  0000 1111
1314
1315  - Function: logxor &rest ints-or-markers
1316      This function returns the "exclusive or" of its arguments: the Nth
1317      bit is set in the result if, and only if, the Nth bit is set in an
1318      odd number of the arguments.  If there are no arguments, the
1319      result is 0, which is an identity element for this operation.  If
1320      `logxor' is passed just one argument, it returns that argument.
1321
1322                              ;               28-bit binary values
1323           
1324           (logxor 12 5)      ; 12  =  0000  0000 0000  0000 0000  0000 1100
1325                              ;  5  =  0000  0000 0000  0000 0000  0000 0101
1326                => 9          ;  9  =  0000  0000 0000  0000 0000  0000 1001
1327           
1328           (logxor 12 5 7)    ; 12  =  0000  0000 0000  0000 0000  0000 1100
1329                              ;  5  =  0000  0000 0000  0000 0000  0000 0101
1330                              ;  7  =  0000  0000 0000  0000 0000  0000 0111
1331                => 14         ; 14  =  0000  0000 0000  0000 0000  0000 1110
1332
1333  - Function: lognot integer
1334      This function returns the logical complement of its argument: the
1335      Nth bit is one in the result if, and only if, the Nth bit is zero
1336      in INTEGER, and vice-versa.
1337
1338           (lognot 5)
1339                => -6
1340           ;;  5  =  0000  0000 0000  0000 0000  0000 0101
1341           ;; becomes
1342           ;; -6  =  1111  1111 1111  1111 1111  1111 1010
1343
1344 \1f
1345 File: lispref.info,  Node: Math Functions,  Next: Random Numbers,  Prev: Bitwise Operations,  Up: Numbers
1346
1347 Standard Mathematical Functions
1348 ===============================
1349
1350    These mathematical functions are available if floating point is
1351 supported (which is the normal state of affairs).  They allow integers
1352 as well as floating point numbers as arguments.
1353
1354  - Function: sin arg
1355  - Function: cos arg
1356  - Function: tan arg
1357      These are the ordinary trigonometric functions, with argument
1358      measured in radians.
1359
1360  - Function: asin arg
1361      The value of `(asin ARG)' is a number between -pi/2 and pi/2
1362      (inclusive) whose sine is ARG; if, however, ARG is out of range
1363      (outside [-1, 1]), then the result is a NaN.
1364
1365  - Function: acos arg
1366      The value of `(acos ARG)' is a number between 0 and pi (inclusive)
1367      whose cosine is ARG; if, however, ARG is out of range (outside
1368      [-1, 1]), then the result is a NaN.
1369
1370  - Function: atan arg
1371      The value of `(atan ARG)' is a number between -pi/2 and pi/2
1372      (exclusive) whose tangent is ARG.
1373
1374  - Function: sinh arg
1375  - Function: cosh arg
1376  - Function: tanh arg
1377      These are the ordinary hyperbolic trigonometric functions.
1378
1379  - Function: asinh arg
1380  - Function: acosh arg
1381  - Function: atanh arg
1382      These are the inverse hyperbolic trigonometric functions.
1383
1384  - Function: exp arg
1385      This is the exponential function; it returns e to the power ARG.
1386      e is a fundamental mathematical constant also called the base of
1387      natural logarithms.
1388
1389  - Function: log arg &optional base
1390      This function returns the logarithm of ARG, with base BASE.  If
1391      you don't specify BASE, the base E is used.  If ARG is negative,
1392      the result is a NaN.
1393
1394  - Function: log10 arg
1395      This function returns the logarithm of ARG, with base 10.  If ARG
1396      is negative, the result is a NaN.  `(log10 X)' == `(log X 10)', at
1397      least approximately.
1398
1399  - Function: expt x y
1400      This function returns X raised to power Y.  If both arguments are
1401      integers and Y is positive, the result is an integer; in this
1402      case, it is truncated to fit the range of possible integer values.
1403
1404  - Function: sqrt arg
1405      This returns the square root of ARG.  If ARG is negative, the
1406      value is a NaN.
1407
1408  - Function: cube-root arg
1409      This returns the cube root of ARG.
1410
1411 \1f
1412 File: lispref.info,  Node: Random Numbers,  Prev: Math Functions,  Up: Numbers
1413
1414 Random Numbers
1415 ==============
1416
1417    A deterministic computer program cannot generate true random numbers.
1418 For most purposes, "pseudo-random numbers" suffice.  A series of
1419 pseudo-random numbers is generated in a deterministic fashion.  The
1420 numbers are not truly random, but they have certain properties that
1421 mimic a random series.  For example, all possible values occur equally
1422 often in a pseudo-random series.
1423
1424    In XEmacs, pseudo-random numbers are generated from a "seed" number.
1425 Starting from any given seed, the `random' function always generates
1426 the same sequence of numbers.  XEmacs always starts with the same seed
1427 value, so the sequence of values of `random' is actually the same in
1428 each XEmacs run!  For example, in one operating system, the first call
1429 to `(random)' after you start XEmacs always returns -1457731, and the
1430 second one always returns -7692030.  This repeatability is helpful for
1431 debugging.
1432
1433    If you want truly unpredictable random numbers, execute `(random
1434 t)'.  This chooses a new seed based on the current time of day and on
1435 XEmacs's process ID number.
1436
1437  - Function: random &optional limit
1438      This function returns a pseudo-random integer.  Repeated calls
1439      return a series of pseudo-random integers.
1440
1441      If LIMIT is a positive integer, the value is chosen to be
1442      nonnegative and less than LIMIT.
1443
1444      If LIMIT is `t', it means to choose a new seed based on the
1445      current time of day and on XEmacs's process ID number.
1446
1447      On some machines, any integer representable in Lisp may be the
1448      result of `random'.  On other machines, the result can never be
1449      larger than a certain maximum or less than a certain (negative)
1450      minimum.
1451
1452 \1f
1453 File: lispref.info,  Node: Strings and Characters,  Next: Lists,  Prev: Numbers,  Up: Top
1454
1455 Strings and Characters
1456 **********************
1457
1458    A string in XEmacs Lisp is an array that contains an ordered sequence
1459 of characters.  Strings are used as names of symbols, buffers, and
1460 files, to send messages to users, to hold text being copied between
1461 buffers, and for many other purposes.  Because strings are so important,
1462 XEmacs Lisp has many functions expressly for manipulating them.  XEmacs
1463 Lisp programs use strings more often than individual characters.
1464
1465 * Menu:
1466
1467 * String Basics::             Basic properties of strings and characters.
1468 * Predicates for Strings::    Testing whether an object is a string or char.
1469 * Creating Strings::          Functions to allocate new strings.
1470 * Predicates for Characters:: Testing whether an object is a character.
1471 * Character Codes::           Each character has an equivalent integer.
1472 * Text Comparison::           Comparing characters or strings.
1473 * String Conversion::         Converting characters or strings and vice versa.
1474 * Modifying Strings::         Changing characters in a string.
1475 * String Properties::         Additional information attached to strings.
1476 * Formatting Strings::        `format': XEmacs's analog of `printf'.
1477 * Character Case::            Case conversion functions.
1478 * Case Tables::               Customizing case conversion.
1479 * Char Tables::               Mapping from characters to Lisp objects.
1480