import xemacs-21.2.37
[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 object1 object2
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
947      This function returns NUMBER plus one.  NUMBER may be a number,
948      character or marker.  Markers and characters are converted to
949      integers.
950
951      For example,
952
953           (setq foo 4)
954                => 4
955           (1+ foo)
956                => 5
957
958      This function is not analogous to the C operator `++'--it does not
959      increment a variable.  It just computes a sum.  Thus, if we
960      continue,
961
962           foo
963                => 4
964
965      If you want to increment the variable, you must use `setq', like
966      this:
967
968           (setq foo (1+ foo))
969                => 5
970
971      Now that the `cl' package is always available from lisp code, a
972      more convenient and natural way to increment a variable is
973      `(incf foo)'.
974
975  - Function: 1- number
976      This function returns NUMBER minus one.  NUMBER may be a number,
977      character or marker.  Markers and characters are converted to
978      integers.
979
980  - Function: abs number
981      This returns the absolute value of NUMBER.
982
983  - Function: + &rest numbers
984      This function adds its arguments together.  When given no
985      arguments, `+' returns 0.
986
987      If any of the arguments are characters or markers, they are first
988      converted to integers.
989
990           (+)
991                => 0
992           (+ 1)
993                => 1
994           (+ 1 2 3 4)
995                => 10
996
997  - Function: - &optional number &rest other-numbers
998      The `-' function serves two purposes: negation and subtraction.
999      When `-' has a single argument, the value is the negative of the
1000      argument.  When there are multiple arguments, `-' subtracts each of
1001      the OTHER-NUMBERS from NUMBER, cumulatively.  If there are no
1002      arguments, an error is signaled.
1003
1004      If any of the arguments are characters or markers, they are first
1005      converted to integers.
1006
1007           (- 10 1 2 3 4)
1008                => 0
1009           (- 10)
1010                => -10
1011           (-)
1012                => 0
1013
1014  - Function: * &rest numbers
1015      This function multiplies its arguments together, and returns the
1016      product.  When given no arguments, `*' returns 1.
1017
1018      If any of the arguments are characters or markers, they are first
1019      converted to integers.
1020
1021           (*)
1022                => 1
1023           (* 1)
1024                => 1
1025           (* 1 2 3 4)
1026                => 24
1027
1028  - Function: / dividend &rest divisors
1029      The `/' function serves two purposes: inversion and division.  When
1030      `/' has a single argument, the value is the inverse of the
1031      argument.  When there are multiple arguments, `/' divides DIVIDEND
1032      by each of the DIVISORS, cumulatively, returning the quotient.  If
1033      there are no arguments, an error is signaled.
1034
1035      If none of the arguments are floats, then the result is an integer.
1036      This means the result has to be rounded.  On most machines, the
1037      result is rounded towards zero after each division, but some
1038      machines may round differently with negative arguments.  This is
1039      because the Lisp function `/' is implemented using the C division
1040      operator, which also permits machine-dependent rounding.  As a
1041      practical matter, all known machines round in the standard fashion.
1042
1043      If any of the arguments are characters or markers, they are first
1044      converted to integers.
1045
1046      If you divide by 0, an `arith-error' error is signaled.  (*Note
1047      Errors::.)
1048
1049           (/ 6 2)
1050                => 3
1051           (/ 5 2)
1052                => 2
1053           (/ 25 3 2)
1054                => 4
1055           (/ 3.0)
1056                => 0.3333333333333333
1057           (/ -17 6)
1058                => -2
1059
1060      The result of `(/ -17 6)' could in principle be -3 on some
1061      machines.
1062
1063  - Function: % dividend divisor
1064      This function returns the integer remainder after division of
1065      DIVIDEND by DIVISOR.  The arguments must be integers or markers.
1066
1067      For negative arguments, the remainder is in principle
1068      machine-dependent since the quotient is; but in practice, all
1069      known machines behave alike.
1070
1071      An `arith-error' results if DIVISOR is 0.
1072
1073           (% 9 4)
1074                => 1
1075           (% -9 4)
1076                => -1
1077           (% 9 -4)
1078                => 1
1079           (% -9 -4)
1080                => -1
1081
1082      For any two integers DIVIDEND and DIVISOR,
1083
1084           (+ (% DIVIDEND DIVISOR)
1085              (* (/ DIVIDEND DIVISOR) DIVISOR))
1086
1087      always equals DIVIDEND.
1088
1089  - Function: mod dividend divisor
1090      This function returns the value of DIVIDEND modulo DIVISOR; in
1091      other words, the remainder after division of DIVIDEND by DIVISOR,
1092      but with the same sign as DIVISOR.  The arguments must be numbers
1093      or markers.
1094
1095      Unlike `%', `mod' returns a well-defined result for negative
1096      arguments.  It also permits floating point arguments; it rounds the
1097      quotient downward (towards minus infinity) to an integer, and uses
1098      that quotient to compute the remainder.
1099
1100      An `arith-error' results if DIVISOR is 0.
1101
1102           (mod 9 4)
1103                => 1
1104           (mod -9 4)
1105                => 3
1106           (mod 9 -4)
1107                => -3
1108           (mod -9 -4)
1109                => -1
1110           (mod 5.5 2.5)
1111                => .5
1112
1113      For any two numbers DIVIDEND and DIVISOR,
1114
1115           (+ (mod DIVIDEND DIVISOR)
1116              (* (floor DIVIDEND DIVISOR) DIVISOR))
1117
1118      always equals DIVIDEND, subject to rounding error if either
1119      argument is floating point.  For `floor', see *Note Numeric
1120      Conversions::.
1121
1122 \1f
1123 File: lispref.info,  Node: Rounding Operations,  Next: Bitwise Operations,  Prev: Arithmetic Operations,  Up: Numbers
1124
1125 Rounding Operations
1126 ===================
1127
1128    The functions `ffloor', `fceiling', `fround' and `ftruncate' take a
1129 floating point argument and return a floating point result whose value
1130 is a nearby integer.  `ffloor' returns the nearest integer below;
1131 `fceiling', the nearest integer above; `ftruncate', the nearest integer
1132 in the direction towards zero; `fround', the nearest integer.
1133
1134  - Function: ffloor number
1135      This function rounds NUMBER to the next lower integral value, and
1136      returns that value as a floating point number.
1137
1138  - Function: fceiling number
1139      This function rounds NUMBER to the next higher integral value, and
1140      returns that value as a floating point number.
1141
1142  - Function: ftruncate number
1143      This function rounds NUMBER towards zero to an integral value, and
1144      returns that value as a floating point number.
1145
1146  - Function: fround number
1147      This function rounds NUMBER to the nearest integral value, and
1148      returns that value as a floating point number.
1149
1150 \1f
1151 File: lispref.info,  Node: Bitwise Operations,  Next: Math Functions,  Prev: Rounding Operations,  Up: Numbers
1152
1153 Bitwise Operations on Integers
1154 ==============================
1155
1156    In a computer, an integer is represented as a binary number, a
1157 sequence of "bits" (digits which are either zero or one).  A bitwise
1158 operation acts on the individual bits of such a sequence.  For example,
1159 "shifting" moves the whole sequence left or right one or more places,
1160 reproducing the same pattern "moved over".
1161
1162    The bitwise operations in XEmacs Lisp apply only to integers.
1163
1164  - Function: lsh integer1 count
1165      `lsh', which is an abbreviation for "logical shift", shifts the
1166      bits in INTEGER1 to the left COUNT places, or to the right if
1167      COUNT is negative, bringing zeros into the vacated bits.  If COUNT
1168      is negative, `lsh' shifts zeros into the leftmost
1169      (most-significant) bit, producing a positive result even if
1170      INTEGER1 is negative.  Contrast this with `ash', below.
1171
1172      Here are two examples of `lsh', shifting a pattern of bits one
1173      place to the left.  We show only the low-order eight bits of the
1174      binary pattern; the rest are all zero.
1175
1176           (lsh 5 1)
1177                => 10
1178           ;; Decimal 5 becomes decimal 10.
1179           00000101 => 00001010
1180           
1181           (lsh 7 1)
1182                => 14
1183           ;; Decimal 7 becomes decimal 14.
1184           00000111 => 00001110
1185
1186      As the examples illustrate, shifting the pattern of bits one place
1187      to the left produces a number that is twice the value of the
1188      previous number.
1189
1190      Shifting a pattern of bits two places to the left produces results
1191      like this (with 8-bit binary numbers):
1192
1193           (lsh 3 2)
1194                => 12
1195           ;; Decimal 3 becomes decimal 12.
1196           00000011 => 00001100
1197
1198      On the other hand, shifting one place to the right looks like this:
1199
1200           (lsh 6 -1)
1201                => 3
1202           ;; Decimal 6 becomes decimal 3.
1203           00000110 => 00000011
1204           
1205           (lsh 5 -1)
1206                => 2
1207           ;; Decimal 5 becomes decimal 2.
1208           00000101 => 00000010
1209
1210      As the example illustrates, shifting one place to the right
1211      divides the value of a positive integer by two, rounding downward.
1212
1213      The function `lsh', like all XEmacs Lisp arithmetic functions, does
1214      not check for overflow, so shifting left can discard significant
1215      bits and change the sign of the number.  For example, left shifting
1216      134,217,727 produces -2 on a 28-bit machine:
1217
1218           (lsh 134217727 1)          ; left shift
1219                => -2
1220
1221      In binary, in the 28-bit implementation, the argument looks like
1222      this:
1223
1224           ;; Decimal 134,217,727
1225           0111  1111 1111  1111 1111  1111 1111
1226
1227      which becomes the following when left shifted:
1228
1229           ;; Decimal -2
1230           1111  1111 1111  1111 1111  1111 1110
1231
1232  - Function: ash integer1 count
1233      `ash' ("arithmetic shift") shifts the bits in INTEGER1 to the left
1234      COUNT places, or to the right if COUNT is negative.
1235
1236      `ash' gives the same results as `lsh' except when INTEGER1 and
1237      COUNT are both negative.  In that case, `ash' puts ones in the
1238      empty bit positions on the left, while `lsh' puts zeros in those
1239      bit positions.
1240
1241      Thus, with `ash', shifting the pattern of bits one place to the
1242      right looks like this:
1243
1244           (ash -6 -1) => -3
1245           ;; Decimal -6 becomes decimal -3.
1246           1111  1111 1111  1111 1111  1111 1010
1247                =>
1248           1111  1111 1111  1111 1111  1111 1101
1249
1250      In contrast, shifting the pattern of bits one place to the right
1251      with `lsh' looks like this:
1252
1253           (lsh -6 -1) => 134217725
1254           ;; Decimal -6 becomes decimal 134,217,725.
1255           1111  1111 1111  1111 1111  1111 1010
1256                =>
1257           0111  1111 1111  1111 1111  1111 1101
1258
1259      Here are other examples:
1260
1261                              ;               28-bit binary values
1262           
1263           (lsh 5 2)          ;   5  =  0000  0000 0000  0000 0000  0000 0101
1264                => 20         ;      =  0000  0000 0000  0000 0000  0001 0100
1265           (ash 5 2)
1266                => 20
1267           (lsh -5 2)         ;  -5  =  1111  1111 1111  1111 1111  1111 1011
1268                => -20        ;      =  1111  1111 1111  1111 1111  1110 1100
1269           (ash -5 2)
1270                => -20
1271           (lsh 5 -2)         ;   5  =  0000  0000 0000  0000 0000  0000 0101
1272                => 1          ;      =  0000  0000 0000  0000 0000  0000 0001
1273           (ash 5 -2)
1274                => 1
1275           (lsh -5 -2)        ;  -5  =  1111  1111 1111  1111 1111  1111 1011
1276                => 4194302    ;      =  0011  1111 1111  1111 1111  1111 1110
1277           (ash -5 -2)        ;  -5  =  1111  1111 1111  1111 1111  1111 1011
1278                => -2         ;      =  1111  1111 1111  1111 1111  1111 1110
1279
1280  - Function: logand &rest ints-or-markers
1281      This function returns the "logical and" of the arguments: the Nth
1282      bit is set in the result if, and only if, the Nth bit is set in
1283      all the arguments.  ("Set" means that the value of the bit is 1
1284      rather than 0.)
1285
1286      For example, using 4-bit binary numbers, the "logical and" of 13
1287      and 12 is 12: 1101 combined with 1100 produces 1100.  In both the
1288      binary numbers, the leftmost two bits are set (i.e., they are
1289      1's), so the leftmost two bits of the returned value are set.
1290      However, for the rightmost two bits, each is zero in at least one
1291      of the arguments, so the rightmost two bits of the returned value
1292      are 0's.
1293
1294      Therefore,
1295
1296           (logand 13 12)
1297                => 12
1298
1299      If `logand' is not passed any argument, it returns a value of -1.
1300      This number is an identity element for `logand' because its binary
1301      representation consists entirely of ones.  If `logand' is passed
1302      just one argument, it returns that argument.
1303
1304                              ;                28-bit binary values
1305           
1306           (logand 14 13)     ; 14  =  0000  0000 0000  0000 0000  0000 1110
1307                              ; 13  =  0000  0000 0000  0000 0000  0000 1101
1308                => 12         ; 12  =  0000  0000 0000  0000 0000  0000 1100
1309           
1310           (logand 14 13 4)   ; 14  =  0000  0000 0000  0000 0000  0000 1110
1311                              ; 13  =  0000  0000 0000  0000 0000  0000 1101
1312                              ;  4  =  0000  0000 0000  0000 0000  0000 0100
1313                => 4          ;  4  =  0000  0000 0000  0000 0000  0000 0100
1314           
1315           (logand)
1316                => -1         ; -1  =  1111  1111 1111  1111 1111  1111 1111
1317
1318  - Function: logior &rest ints-or-markers
1319      This function returns the "inclusive or" of its arguments: the Nth
1320      bit is set in the result if, and only if, the Nth bit is set in at
1321      least one of the arguments.  If there are no arguments, the result
1322      is zero, which is an identity element for this operation.  If
1323      `logior' is passed just one argument, it returns that argument.
1324
1325                              ;               28-bit binary values
1326           
1327           (logior 12 5)      ; 12  =  0000  0000 0000  0000 0000  0000 1100
1328                              ;  5  =  0000  0000 0000  0000 0000  0000 0101
1329                => 13         ; 13  =  0000  0000 0000  0000 0000  0000 1101
1330           
1331           (logior 12 5 7)    ; 12  =  0000  0000 0000  0000 0000  0000 1100
1332                              ;  5  =  0000  0000 0000  0000 0000  0000 0101
1333                              ;  7  =  0000  0000 0000  0000 0000  0000 0111
1334                => 15         ; 15  =  0000  0000 0000  0000 0000  0000 1111
1335
1336  - Function: logxor &rest ints-or-markers
1337      This function returns the "exclusive or" of its arguments: the Nth
1338      bit is set in the result if, and only if, the Nth bit is set in an
1339      odd number of the arguments.  If there are no arguments, the
1340      result is 0, which is an identity element for this operation.  If
1341      `logxor' is passed just one argument, it returns that argument.
1342
1343                              ;               28-bit binary values
1344           
1345           (logxor 12 5)      ; 12  =  0000  0000 0000  0000 0000  0000 1100
1346                              ;  5  =  0000  0000 0000  0000 0000  0000 0101
1347                => 9          ;  9  =  0000  0000 0000  0000 0000  0000 1001
1348           
1349           (logxor 12 5 7)    ; 12  =  0000  0000 0000  0000 0000  0000 1100
1350                              ;  5  =  0000  0000 0000  0000 0000  0000 0101
1351                              ;  7  =  0000  0000 0000  0000 0000  0000 0111
1352                => 14         ; 14  =  0000  0000 0000  0000 0000  0000 1110
1353
1354  - Function: lognot integer
1355      This function returns the logical complement of its argument: the
1356      Nth bit is one in the result if, and only if, the Nth bit is zero
1357      in INTEGER, and vice-versa.
1358
1359           (lognot 5)
1360                => -6
1361           ;;  5  =  0000  0000 0000  0000 0000  0000 0101
1362           ;; becomes
1363           ;; -6  =  1111  1111 1111  1111 1111  1111 1010
1364
1365 \1f
1366 File: lispref.info,  Node: Math Functions,  Next: Random Numbers,  Prev: Bitwise Operations,  Up: Numbers
1367
1368 Standard Mathematical Functions
1369 ===============================
1370
1371    These mathematical functions are available if floating point is
1372 supported (which is the normal state of affairs).  They allow integers
1373 as well as floating point numbers as arguments.
1374
1375  - Function: sin number
1376  - Function: cos number
1377  - Function: tan number
1378      These are the ordinary trigonometric functions, with argument
1379      measured in radians.
1380
1381  - Function: asin number
1382      The value of `(asin NUMBER)' is a number between -pi/2 and pi/2
1383      (inclusive) whose sine is NUMBER; if, however, NUMBER is out of
1384      range (outside [-1, 1]), then the result is a NaN.
1385
1386  - Function: acos number
1387      The value of `(acos NUMBER)' is a number between 0 and pi
1388      (inclusive) whose cosine is NUMBER; if, however, NUMBER is out of
1389      range (outside [-1, 1]), then the result is a NaN.
1390
1391  - Function: atan number &optional number2
1392      The value of `(atan NUMBER)' is a number between -pi/2 and pi/2
1393      (exclusive) whose tangent is NUMBER.
1394
1395      If optional argument NUMBER2 is supplied, the function returns
1396      `atan2(NUMBER,NUMBER2)'.
1397
1398  - Function: sinh number
1399  - Function: cosh number
1400  - Function: tanh number
1401      These are the ordinary hyperbolic trigonometric functions.
1402
1403  - Function: asinh number
1404  - Function: acosh number
1405  - Function: atanh number
1406      These are the inverse hyperbolic trigonometric functions.
1407
1408  - Function: exp number
1409      This is the exponential function; it returns e to the power
1410      NUMBER.  e is a fundamental mathematical constant also called the
1411      base of natural logarithms.
1412
1413  - Function: log number &optional base
1414      This function returns the logarithm of NUMBER, with base BASE.  If
1415      you don't specify BASE, the base E is used.  If NUMBER is
1416      negative, the result is a NaN.
1417
1418  - Function: log10 number
1419      This function returns the logarithm of NUMBER, with base 10.  If
1420      NUMBER is negative, the result is a NaN.  `(log10 X)' == `(log X
1421      10)', at least approximately.
1422
1423  - Function: expt x y
1424      This function returns X raised to power Y.  If both arguments are
1425      integers and Y is positive, the result is an integer; in this
1426      case, it is truncated to fit the range of possible integer values.
1427
1428  - Function: sqrt number
1429      This returns the square root of NUMBER.  If NUMBER is negative,
1430      the value is a NaN.
1431
1432  - Function: cube-root number
1433      This returns the cube root of NUMBER.
1434
1435 \1f
1436 File: lispref.info,  Node: Random Numbers,  Prev: Math Functions,  Up: Numbers
1437
1438 Random Numbers
1439 ==============
1440
1441    A deterministic computer program cannot generate true random numbers.
1442 For most purposes, "pseudo-random numbers" suffice.  A series of
1443 pseudo-random numbers is generated in a deterministic fashion.  The
1444 numbers are not truly random, but they have certain properties that
1445 mimic a random series.  For example, all possible values occur equally
1446 often in a pseudo-random series.
1447
1448    In XEmacs, pseudo-random numbers are generated from a "seed" number.
1449 Starting from any given seed, the `random' function always generates
1450 the same sequence of numbers.  XEmacs always starts with the same seed
1451 value, so the sequence of values of `random' is actually the same in
1452 each XEmacs run!  For example, in one operating system, the first call
1453 to `(random)' after you start XEmacs always returns -1457731, and the
1454 second one always returns -7692030.  This repeatability is helpful for
1455 debugging.
1456
1457    If you want truly unpredictable random numbers, execute `(random
1458 t)'.  This chooses a new seed based on the current time of day and on
1459 XEmacs's process ID number.
1460
1461  - Function: random &optional limit
1462      This function returns a pseudo-random integer.  Repeated calls
1463      return a series of pseudo-random integers.
1464
1465      If LIMIT is a positive integer, the value is chosen to be
1466      nonnegative and less than LIMIT.
1467
1468      If LIMIT is `t', it means to choose a new seed based on the
1469      current time of day and on XEmacs's process ID number.
1470
1471      On some machines, any integer representable in Lisp may be the
1472      result of `random'.  On other machines, the result can never be
1473      larger than a certain maximum or less than a certain (negative)
1474      minimum.
1475
1476 \1f
1477 File: lispref.info,  Node: Strings and Characters,  Next: Lists,  Prev: Numbers,  Up: Top
1478
1479 Strings and Characters
1480 **********************
1481
1482    A string in XEmacs Lisp is an array that contains an ordered sequence
1483 of characters.  Strings are used as names of symbols, buffers, and
1484 files, to send messages to users, to hold text being copied between
1485 buffers, and for many other purposes.  Because strings are so important,
1486 XEmacs Lisp has many functions expressly for manipulating them.  XEmacs
1487 Lisp programs use strings more often than individual characters.
1488
1489 * Menu:
1490
1491 * String Basics::             Basic properties of strings and characters.
1492 * Predicates for Strings::    Testing whether an object is a string or char.
1493 * Creating Strings::          Functions to allocate new strings.
1494 * Predicates for Characters:: Testing whether an object is a character.
1495 * Character Codes::           Each character has an equivalent integer.
1496 * Text Comparison::           Comparing characters or strings.
1497 * String Conversion::         Converting characters or strings and vice versa.
1498 * Modifying Strings::         Changing characters in a string.
1499 * String Properties::         Additional information attached to strings.
1500 * Formatting Strings::        `format': XEmacs's analog of `printf'.
1501 * Character Case::            Case conversion functions.
1502 * Case Tables::               Customizing case conversion.
1503 * Char Tables::               Mapping from characters to Lisp objects.
1504