~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to info/chap-12.texi

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
@node Numbers (Numbers), Characters, Packages, Top
 
4
@chapter Numbers
 
5
 
 
6
@menu
 
7
* Number Concepts::             
 
8
* Numbers Dictionary::          
 
9
@end menu
 
10
 
 
11
@node Number Concepts, Numbers Dictionary, Numbers (Numbers), Numbers (Numbers)
 
12
@section Number Concepts
 
13
 
 
14
@c including concept-numbers
 
15
 
 
16
@menu
 
17
* Numeric Operations::          
 
18
* Implementation-Dependent Numeric Constants::  
 
19
* Rational Computations::       
 
20
* Floating-point Computations::  
 
21
* Complex Computations::        
 
22
* Interval Designators::        
 
23
* Random-State Operations::     
 
24
@end menu
 
25
 
 
26
@node Numeric Operations, Implementation-Dependent Numeric Constants, Number Concepts, Number Concepts
 
27
@subsection Numeric Operations
 
28
 
 
29
@r{Common Lisp} provides a large variety of operations related to @i{numbers}.
 
30
This section provides an overview of those operations by grouping them
 
31
into categories that emphasize some of the relationships among them.
 
32
 
 
33
Figure 12--1 shows @i{operators} relating to
 
34
arithmetic operations.
 
35
 
 
36
@format
 
37
@group
 
38
@noindent
 
39
@w{  *  1+         gcd   }
 
40
@w{  +  1-         incf  }
 
41
@w{  -  conjugate  lcm   }
 
42
@w{  /  decf             }
 
43
 
 
44
@noindent
 
45
@w{  Figure 12--1: Operators relating to Arithmetic.}
 
46
 
 
47
@end group
 
48
@end format
 
49
 
 
50
Figure 12--2 shows @i{defined names} relating to
 
51
exponential, logarithmic, and trigonometric operations.
 
52
 
 
53
@format
 
54
@group
 
55
@noindent
 
56
@w{  abs    cos    signum  }
 
57
@w{  acos   cosh   sin     }
 
58
@w{  acosh  exp    sinh    }
 
59
@w{  asin   expt   sqrt    }
 
60
@w{  asinh  isqrt  tan     }
 
61
@w{  atan   log    tanh    }
 
62
@w{  atanh  phase          }
 
63
@w{  cis    pi             }
 
64
 
 
65
@noindent
 
66
@w{  Figure 12--2: Defined names relating to Exponentials, Logarithms, and Trigonometry.}
 
67
 
 
68
@end group
 
69
@end format
 
70
 
 
71
Figure 12--3 shows @i{operators} relating to
 
72
numeric comparison and predication.
 
73
 
 
74
@format
 
75
@group
 
76
@noindent
 
77
@w{  /=  >=      oddp   }
 
78
@w{  <   evenp   plusp  }
 
79
@w{  <=  max     zerop  }
 
80
@w{  =   min            }
 
81
@w{  >   minusp         }
 
82
 
 
83
@noindent
 
84
@w{  Figure 12--3: Operators for numeric comparison and predication.}
 
85
 
 
86
@end group
 
87
@end format
 
88
 
 
89
Figure 12--4 shows @i{defined names} relating to
 
90
numeric type manipulation and coercion.
 
91
 
 
92
@format
 
93
@group
 
94
@noindent
 
95
@w{  ceiling          float-radix           rational     }
 
96
@w{  complex          float-sign            rationalize  }
 
97
@w{  decode-float     floor                 realpart     }
 
98
@w{  denominator      fround                rem          }
 
99
@w{  fceiling         ftruncate             round        }
 
100
@w{  ffloor           imagpart              scale-float  }
 
101
@w{  float            integer-decode-float  truncate     }
 
102
@w{  float-digits     mod                                }
 
103
@w{  float-precision  numerator                          }
 
104
 
 
105
@noindent
 
106
@w{  Figure 12--4: Defined names relating to numeric type manipulation and coercion.}
 
107
 
 
108
@end group
 
109
@end format
 
110
 
 
111
@menu
 
112
* Associativity and Commutativity in Numeric Operations::  
 
113
* Examples of Associativity and Commutativity in Numeric Operations::  
 
114
* Contagion in Numeric Operations::  
 
115
* Viewing Integers as Bits and Bytes::  
 
116
* Logical Operations on Integers::  
 
117
* Byte Operations on Integers::  
 
118
@end menu
 
119
 
 
120
@node Associativity and Commutativity in Numeric Operations, Examples of Associativity and Commutativity in Numeric Operations, Numeric Operations, Numeric Operations
 
121
@subsubsection Associativity and Commutativity in Numeric Operations
 
122
 
 
123
For functions that are mathematically associative (and possibly commutative),
 
124
a @i{conforming implementation} may process the @i{arguments} in any manner 
 
125
consistent with associative (and possibly commutative) rearrangement.  This does not
 
126
affect the order in which the @i{argument} @i{forms} are @i{evaluated};
 
127
for a discussion of evaluation order, see @ref{Function Forms}.
 
128
What is unspecified is only the order in which the @i{parameter} @i{values}
 
129
are processed.  This implies that @i{implementations} may differ in which 
 
130
automatic @i{coercions} are applied; see @ref{Contagion in Numeric Operations}.
 
131
 
 
132
A @i{conforming program} can control the order of processing explicitly by 
 
133
separating the operations into separate (possibly nested) @i{function forms},
 
134
or by writing explicit calls to @i{functions} that perform coercions.
 
135
 
 
136
@node Examples of Associativity and Commutativity in Numeric Operations, Contagion in Numeric Operations, Associativity and Commutativity in Numeric Operations, Numeric Operations
 
137
@subsubsection Examples of Associativity and Commutativity in Numeric Operations
 
138
 
 
139
Consider the following expression, in which we assume that @t{1.0} and
 
140
@t{1.0e-15} both denote @i{single floats}:
 
141
 
 
142
@example
 
143
 (+ 1/3 2/3 1.0d0 1.0 1.0e-15)
 
144
@end example
 
145
 
 
146
One @i{conforming implementation} might
 
147
process the @i{arguments} from left to right,
 
148
first adding @t{1/3} and @t{2/3} to get @t{1}, 
 
149
then converting that to a @i{double float} 
 
150
for combination with @t{1.0d0},
 
151
then successively converting and adding @t{1.0} and @t{1.0e-15}.
 
152
 
 
153
Another @i{conforming implementation} might process the @i{arguments} from
 
154
right to left, first performing a @i{single float} addition of @t{1.0} and
 
155
@t{1.0e-15} (perhaps losing accuracy in the process), then converting the sum to 
 
156
a @i{double float} and adding @t{1.0d0}, then converting @t{2/3} to a
 
157
@i{double float} and adding it, and then converting @t{1/3} and adding that.
 
158
 
 
159
A third @i{conforming implementation} might first scan all the @i{arguments},
 
160
process all the @i{rationals} first to keep that part of the computation exact,
 
161
then find an @i{argument} of the largest floating-point format among all the
 
162
@i{arguments} and add that, and then add in all other @i{arguments}, converting
 
163
each in turn (all in a perhaps misguided attempt to make the computation as accurate
 
164
as possible).
 
165
 
 
166
In any case, all three strategies are legitimate.
 
167
 
 
168
A @i{conforming program} could control the order by writing, for example,
 
169
 
 
170
@example
 
171
 (+ (+ 1/3 2/3) (+ 1.0d0 1.0e-15) 1.0)
 
172
@end example
 
173
 
 
174
@node Contagion in Numeric Operations, Viewing Integers as Bits and Bytes, Examples of Associativity and Commutativity in Numeric Operations, Numeric Operations
 
175
@subsubsection Contagion in Numeric Operations
 
176
 
 
177
For information about the contagion rules for implicit coercions of @i{arguments} 
 
178
in numeric operations, see
 
179
     @ref{Rule of Float Precision Contagion}, 
 
180
     @ref{Rule of Float and Rational Contagion},
 
181
 and @ref{Rule of Complex Contagion}.
 
182
 
 
183
@node Viewing Integers as Bits and Bytes, Logical Operations on Integers, Contagion in Numeric Operations, Numeric Operations
 
184
@subsubsection Viewing Integers as Bits and Bytes
 
185
 
 
186
@node Logical Operations on Integers, Byte Operations on Integers, Viewing Integers as Bits and Bytes, Numeric Operations
 
187
@subsubsection Logical Operations on Integers
 
188
 
 
189
Logical operations require @i{integers} as arguments;
 
190
an error of @i{type} @b{type-error} should be signaled 
 
191
if an argument is supplied that is not an @i{integer}.
 
192
@i{Integer} arguments to logical operations are treated as if
 
193
they were represented in two's-complement notation.
 
194
 
 
195
Figure 12--5 shows @i{defined names} relating to
 
196
logical operations on numbers.
 
197
 
 
198
@format
 
199
@group
 
200
@noindent
 
201
@w{  ash          boole-ior       logbitp   }
 
202
@w{  boole        boole-nand      logcount  }
 
203
@w{  boole-1      boole-nor       logeqv    }
 
204
@w{  boole-2      boole-orc1      logior    }
 
205
@w{  boole-and    boole-orc2      lognand   }
 
206
@w{  boole-andc1  boole-set       lognor    }
 
207
@w{  boole-andc2  boole-xor       lognot    }
 
208
@w{  boole-c1     integer-length  logorc1   }
 
209
@w{  boole-c2     logand          logorc2   }
 
210
@w{  boole-clr    logandc1        logtest   }
 
211
@w{  boole-eqv    logandc2        logxor    }
 
212
 
 
213
@noindent
 
214
@w{  Figure 12--5: Defined names relating to logical operations on numbers.}
 
215
 
 
216
@end group
 
217
@end format
 
218
 
 
219
@node Byte Operations on Integers,  , Logical Operations on Integers, Numeric Operations
 
220
@subsubsection Byte Operations on Integers
 
221
 
 
222
The byte-manipulation @i{functions} use @i{objects} 
 
223
called @i{byte specifiers} to designate the size and position
 
224
of a specific @i{byte} within an @i{integer}.
 
225
The representation of a @i{byte specifier} is @i{implementation-dependent};
 
226
it might or might not be a @i{number}.
 
227
The @i{function} @b{byte} will construct a @i{byte specifier},
 
228
which various other byte-manipulation @i{functions} will accept.
 
229
 
 
230
Figure 12--6 shows @i{defined names} relating to
 
231
manipulating @i{bytes} of @i{numbers}.
 
232
 
 
233
@format
 
234
@group
 
235
@noindent
 
236
@w{  byte           deposit-field  ldb-test    }
 
237
@w{  byte-position  dpb            mask-field  }
 
238
@w{  byte-size      ldb                        }
 
239
 
 
240
@noindent
 
241
@w{  Figure 12--6: Defined names relating to byte manipulation.}
 
242
 
 
243
@end group
 
244
@end format
 
245
 
 
246
@node Implementation-Dependent Numeric Constants, Rational Computations, Numeric Operations, Number Concepts
 
247
@subsection Implementation-Dependent Numeric Constants
 
248
 
 
249
Figure 12--7 shows @i{defined names} relating to
 
250
@i{implementation-dependent} details about @i{numbers}.
 
251
 
 
252
@format
 
253
@group
 
254
@noindent
 
255
@w{  double-float-epsilon           most-negative-fixnum           }
 
256
@w{  double-float-negative-epsilon  most-negative-long-float       }
 
257
@w{  least-negative-double-float    most-negative-short-float      }
 
258
@w{  least-negative-long-float      most-negative-single-float     }
 
259
@w{  least-negative-short-float     most-positive-double-float     }
 
260
@w{  least-negative-single-float    most-positive-fixnum           }
 
261
@w{  least-positive-double-float    most-positive-long-float       }
 
262
@w{  least-positive-long-float      most-positive-short-float      }
 
263
@w{  least-positive-short-float     most-positive-single-float     }
 
264
@w{  least-positive-single-float    short-float-epsilon            }
 
265
@w{  long-float-epsilon             short-float-negative-epsilon   }
 
266
@w{  long-float-negative-epsilon    single-float-epsilon           }
 
267
@w{  most-negative-double-float     single-float-negative-epsilon  }
 
268
 
 
269
@noindent
 
270
@w{  Figure 12--7: Defined names relating to implementation-dependent details about numbers.}
 
271
 
 
272
@end group
 
273
@end format
 
274
 
 
275
@node Rational Computations, Floating-point Computations, Implementation-Dependent Numeric Constants, Number Concepts
 
276
@subsection Rational Computations
 
277
 
 
278
The rules in this section apply to @i{rational} computations.
 
279
 
 
280
@menu
 
281
* Rule of Unbounded Rational Precision::  
 
282
* Rule of Canonical Representation for Rationals::  
 
283
* Rule of Float Substitutability::  
 
284
@end menu
 
285
 
 
286
@node Rule of Unbounded Rational Precision, Rule of Canonical Representation for Rationals, Rational Computations, Rational Computations
 
287
@subsubsection Rule of Unbounded Rational Precision
 
288
 
 
289
Rational computations cannot overflow in the usual sense 
 
290
(though there may not be enough storage to represent a result), 
 
291
since @i{integers} and @i{ratios} may in principle be of any magnitude.
 
292
 
 
293
@node Rule of Canonical Representation for Rationals, Rule of Float Substitutability, Rule of Unbounded Rational Precision, Rational Computations
 
294
@subsubsection Rule of Canonical Representation for Rationals
 
295
 
 
296
If any computation produces a result that is a mathematical ratio of two integers
 
297
such that the denominator evenly divides the numerator, then the result is converted
 
298
to the equivalent @i{integer}.  
 
299
 
 
300
If the denominator does not evenly divide the numerator,
 
301
the canonical representation of a @i{rational} number is as the @i{ratio}
 
302
that numerator and that denominator, where the greatest common divisor of
 
303
the numerator and denominator is one, and where the denominator is positive
 
304
and greater than one.
 
305
 
 
306
When used as input (in the default syntax),
 
307
the notation @t{-0} always denotes the @i{integer} @t{0}.
 
308
A @i{conforming implementation} must not have a
 
309
representation of ``minus zero'' for @i{integers}
 
310
that is distinct from its representation of zero for @i{integers}.
 
311
However, such a distinction is possible for @i{floats}; 
 
312
see the @i{type} @b{float}.
 
313
 
 
314
@node Rule of Float Substitutability,  , Rule of Canonical Representation for Rationals, Rational Computations
 
315
@subsubsection Rule of Float Substitutability
 
316
 
 
317
When the arguments to an irrational mathematical @i{function} 
 
318
 
 
319
[Reviewer Note by Barmar: There should be a table of these functions.]
 
320
are all @i{rational} and the true mathematical result
 
321
is also (mathematically) rational, then unless otherwise noted
 
322
an implementation is free to return either an accurate
 
323
@i{rational} result
 
324
or a @i{single float} approximation.
 
325
If the arguments are all @i{rational} 
 
326
but the result cannot be expressed
 
327
as a @i{rational} number, then a @i{single float} 
 
328
approximation is always returned.
 
329
 
 
330
If the arguments to a mathematical @i{function} are all of type
 
331
  @t{(or rational (complex rational))} 
 
332
and the true mathematical result is
 
333
  (mathematically) a complex number with rational real and imaginary
 
334
  parts, then unless otherwise noted an implementation is free to return
 
335
  either an accurate result of type @t{(or rational (complex rational))} 
 
336
or
 
337
  a @i{single float}
 
338
  (permissible only if the imaginary part of the true mathematical
 
339
  result is zero) or @t{(complex single-float)}. If the arguments are
 
340
  all of type @t{(or rational (complex rational))}
 
341
but the result cannot be
 
342
  expressed as a @i{rational} or @i{complex rational},
 
343
then the returned
 
344
  value will be of @i{type} @b{single-float} 
 
345
(permissible only if the imaginary
 
346
  part of the true mathematical result is zero) or @t{(complex single-float)}.
 
347
 
 
348
@format
 
349
@group
 
350
@noindent
 
351
@w{  Function  Sample Results                                   }
 
352
@w{  @b{abs}       @t{(abs #c(3 4)) @result{}  5 @i{or} 5.0}                       }
 
353
@w{  @b{acos}      @t{(acos 1) @result{}  0 @i{or} 0.0}                            }
 
354
@w{  @b{acosh}     @t{(acosh 1) @result{}  0 @i{or} 0.0}                           }
 
355
@w{  @b{asin}      @t{(asin 0) @result{}  0 @i{or} 0.0}                            }
 
356
@w{  @b{asinh}     @t{(asinh 0) @result{}  0 @i{or} 0.0}                           }
 
357
@w{  @b{atan}      @t{(atan 0) @result{}  0 @i{or} 0.0}                            }
 
358
@w{  @b{atanh}     @t{(atanh 0) @result{}  0 @i{or} 0.0}                           }
 
359
@w{  @b{cis}       @t{(cis 0) @result{}  #c(1 0) @i{or} #c(1.0 0.0)}               }
 
360
@w{  @b{cos}       @t{(cos 0) @result{}  1 @i{or} 1.0}                             }
 
361
@w{  @b{cosh}      @t{(cosh 0) @result{}  1 @i{or} 1.0}                            }
 
362
@w{  @b{exp}       @t{(exp 0) @result{}  1 @i{or} 1.0}                             }
 
363
@w{  @b{expt}      @t{(expt 8 1/3) @result{}  2 @i{or} 2.0}                        }
 
364
@w{  @b{log}       @t{(log 1) @result{}  0 @i{or} 0.0}                             }
 
365
@w{            @t{(log 8 2) @result{}  3 @i{or} 3.0}                           }
 
366
@w{  @b{phase}     @t{(phase 7) @result{}  0 @i{or} 0.0}                           }
 
367
@w{  @b{signum}    @t{(signum #c(3 4)) @result{}  #c(3/5 4/5) @i{or} #c(0.6 0.8)}  }
 
368
@w{  @b{sin}       @t{(sin 0) @result{}  0 @i{or} 0.0}                             }
 
369
@w{  @b{sinh}      @t{(sinh 0) @result{}  0 @i{or} 0.0}                            }
 
370
@w{  @b{sqrt}      @t{(sqrt 4) @result{}  2 @i{or} 2.0}                            }
 
371
@w{            @t{(sqrt 9/16) @result{}  3/4 @i{or} 0.75}                      }
 
372
@w{  @b{tan}       @t{(tan 0) @result{}  0 @i{or} 0.0}                             }
 
373
@w{  @b{tanh}      @t{(tanh 0) @result{}  0 @i{or} 0.0}                            }
 
374
 
 
375
@noindent
 
376
@w{  Figure 12--8: Functions Affected by Rule of Float Substitutability}
 
377
 
 
378
@end group
 
379
@end format
 
380
 
 
381
@node Floating-point Computations, Complex Computations, Rational Computations, Number Concepts
 
382
@subsection Floating-point Computations
 
383
 
 
384
The following rules apply to floating point computations.
 
385
 
 
386
@menu
 
387
* Rule of Float and Rational Contagion::  
 
388
* Examples of Rule of Float and Rational Contagion::  
 
389
* Rule of Float Approximation::  
 
390
* Rule of Float Underflow and Overflow::  
 
391
* Rule of Float Precision Contagion::  
 
392
@end menu
 
393
 
 
394
@node Rule of Float and Rational Contagion, Examples of Rule of Float and Rational Contagion, Floating-point Computations, Floating-point Computations
 
395
@subsubsection Rule of Float and Rational Contagion
 
396
 
 
397
When @i{rationals} and @i{floats} are combined by a numerical function, 
 
398
the @i{rational} is first converted to a @i{float} of the same format.
 
399
For @i{functions} such as @b{+} that take more than two arguments,
 
400
it is permitted that part of the operation be carried out exactly using
 
401
@i{rationals} and the rest be done using floating-point arithmetic.
 
402
 
 
403
When @i{rationals} and @i{floats} are compared by a numerical function, 
 
404
the @i{function} @b{rational} is effectively called to convert the @i{float} 
 
405
to a @i{rational} and then an exact
 
406
comparison is performed. In the case of @i{complex} numbers,
 
407
the real and imaginary parts are effectively handled individually.
 
408
 
 
409
@node Examples of Rule of Float and Rational Contagion, Rule of Float Approximation, Rule of Float and Rational Contagion, Floating-point Computations
 
410
@subsubsection Examples of Rule of Float and Rational Contagion
 
411
 
 
412
@example
 
413
 ;;;; Combining rationals with floats.
 
414
 ;;; This example assumes an implementation in which 
 
415
 ;;; (float-radix 0.5) is 2 (as in IEEE) or 16 (as in IBM/360),
 
416
 ;;; or else some other implementation in which 1/2 has an exact 
 
417
 ;;;  representation in floating point.
 
418
 (+ 1/2 0.5) @result{}  1.0
 
419
 (- 1/2 0.5d0) @result{}  0.0d0
 
420
 (+ 0.5 -0.5 1/2) @result{}  0.5
 
421
 
 
422
 ;;;; Comparing rationals with floats.
 
423
 ;;; This example assumes an implementation in which the default float 
 
424
 ;;; format is IEEE single-float, IEEE double-float, or some other format
 
425
 ;;; in which 5/7 is rounded upwards by FLOAT.
 
426
 (< 5/7 (float 5/7)) @result{}  @i{true}
 
427
 (< 5/7 (rational (float 5/7))) @result{}  @i{true}
 
428
 (< (float 5/7) (float 5/7)) @result{}  @i{false}
 
429
@end example
 
430
 
 
431
@node Rule of Float Approximation, Rule of Float Underflow and Overflow, Examples of Rule of Float and Rational Contagion, Floating-point Computations
 
432
@subsubsection Rule of Float Approximation
 
433
 
 
434
Computations with @i{floats} are only approximate,
 
435
although they are described as if the results
 
436
were mathematically accurate. 
 
437
Two mathematically identical
 
438
expressions may be computationally different because of errors
 
439
inherent in the floating-point approximation process.
 
440
The precision of a @i{float} is not necessarily
 
441
correlated with the accuracy of that number.
 
442
For instance, 3.142857142857142857 is a more precise approximation
 
443
to \pi than 3.14159, but the latter is more accurate.
 
444
The precision refers to the number of bits retained in the representation.
 
445
When an operation combines a @i{short float} with a 
 
446
@i{long float},
 
447
the result will be a @i{long float}. 
 
448
@r{Common Lisp} functions assume that the accuracy of
 
449
arguments to them does not exceed their precision.  Therefore
 
450
when two @i{small floats} 
 
451
are combined, the result is a @i{small float}. 
 
452
@r{Common Lisp} functions 
 
453
never convert automatically from a larger size to a smaller one.
 
454
 
 
455
@node Rule of Float Underflow and Overflow, Rule of Float Precision Contagion, Rule of Float Approximation, Floating-point Computations
 
456
@subsubsection Rule of Float Underflow and Overflow
 
457
 
 
458
An error of @i{type} @b{floating-point-overflow}
 
459
or @b{floating-point-underflow} should be signaled if a 
 
460
floating-point computation causes exponent overflow or underflow, respectively.
 
461
 
 
462
@node Rule of Float Precision Contagion,  , Rule of Float Underflow and Overflow, Floating-point Computations
 
463
@subsubsection Rule of Float Precision Contagion
 
464
 
 
465
The result of a numerical function is a @i{float} of the 
 
466
largest format among all the floating-point arguments to the @i{function}. 
 
467
 
 
468
@node Complex Computations, Interval Designators, Floating-point Computations, Number Concepts
 
469
@subsection Complex Computations
 
470
 
 
471
The following rules apply to @i{complex} computations:
 
472
 
 
473
@menu
 
474
* Rule of Complex Substitutability::  
 
475
* Rule of Complex Contagion::   
 
476
* Rule of Canonical Representation for Complex Rationals::  
 
477
* Examples of Rule of Canonical Representation for Complex Rationals::  
 
478
* Principal Values and Branch Cuts::  
 
479
@end menu
 
480
 
 
481
@node Rule of Complex Substitutability, Rule of Complex Contagion, Complex Computations, Complex Computations
 
482
@subsubsection Rule of Complex Substitutability
 
483
 
 
484
Except during the execution of irrational and transcendental @i{functions},
 
485
no numerical @i{function} ever @i{yields} a @i{complex} unless 
 
486
one or more of its @i{arguments} is a @i{complex}.
 
487
 
 
488
@node Rule of Complex Contagion, Rule of Canonical Representation for Complex Rationals, Rule of Complex Substitutability, Complex Computations
 
489
@subsubsection Rule of Complex Contagion
 
490
 
 
491
When a 
 
492
 
 
493
@i{real}
 
494
 
 
495
and 
 
496
a @i{complex} are both part of a computation, 
 
497
the 
 
498
 
 
499
@i{real}
 
500
 
 
501
is first converted to a @i{complex} by providing an imaginary part of @t{0}.
 
502
 
 
503
@node Rule of Canonical Representation for Complex Rationals, Examples of Rule of Canonical Representation for Complex Rationals, Rule of Complex Contagion, Complex Computations
 
504
@subsubsection Rule of Canonical Representation for Complex Rationals
 
505
 
 
506
If the result of any computation would be a @i{complex}
 
507
number whose real part is of @i{type} @b{rational} and whose imaginary
 
508
part is zero, the result is converted to the @i{rational} 
 
509
which is the real part.
 
510
This rule does not apply to @i{complex} numbers whose parts
 
511
are @i{floats}. 
 
512
For example, @t{#C(5 0)} and @t{5} are not @i{different} @i{objects} in @r{Common Lisp}
 
513
(they are always the @i{same} under @b{eql});
 
514
@t{#C(5.0 0.0)} and @t{5.0} are always @i{different} @i{objects} in @r{Common Lisp}
 
515
(they are never the @i{same} under @b{eql},
 
516
although they are the @i{same} under @b{equalp} and @b{=}).
 
517
 
 
518
@node Examples of Rule of Canonical Representation for Complex Rationals, Principal Values and Branch Cuts, Rule of Canonical Representation for Complex Rationals, Complex Computations
 
519
@subsubsection Examples of Rule of Canonical Representation for Complex Rationals
 
520
 
 
521
@example
 
522
 #c(1.0 1.0) @result{}  #C(1.0 1.0)
 
523
 #c(0.0 0.0) @result{}  #C(0.0 0.0)
 
524
 #c(1.0 1) @result{}  #C(1.0 1.0)
 
525
 #c(0.0 0) @result{}  #C(0.0 0.0)
 
526
 #c(1 1) @result{}  #C(1 1)
 
527
 #c(0 0) @result{}  0
 
528
 (typep #c(1 1) '(complex (eql 1))) @result{}  @i{true}
 
529
 (typep #c(0 0) '(complex (eql 0))) @result{}  @i{false}
 
530
@end example
 
531
 
 
532
@node Principal Values and Branch Cuts,  , Examples of Rule of Canonical Representation for Complex Rationals, Complex Computations
 
533
@subsubsection Principal Values and Branch Cuts
 
534
 
 
535
Many of the irrational and transcendental functions are multiply defined
 
536
in the complex domain; for example, there are in general an infinite
 
537
number of complex values for the logarithm function.  In each such
 
538
case, a @i{principal} @i{value} must be chosen for the function to return.
 
539
In general, such values cannot be chosen so as to make the range
 
540
continuous; lines in the domain
 
541
called branch cuts must be defined, which in turn
 
542
define the discontinuities in the range.
 
543
@r{Common Lisp} defines the branch cuts, @i{principal} @i{values}, and boundary
 
544
conditions for the complex functions following ``Principal Values and Branch Cuts in Complex APL.'' The branch
 
545
cut rules that apply to each function are located with the description of
 
546
that function.
 
547
 
 
548
Figure 12--9 lists
 
549
the identities that are obeyed
 
550
throughout the applicable portion of the complex domain, even on
 
551
the branch cuts:
 
552
 
 
553
@format
 
554
@group
 
555
@noindent
 
556
@w{  sin i z = i sinh z  sinh i z = i sin z        arctan i z = i arctanh z  }
 
557
@w{  cos i z = cosh z    cosh i z = cos z          arcsinh i z = i arcsin z  }
 
558
@w{  tan i z = i tanh z  arcsin i z = i arcsinh z  arctanh i z = i arctan z  }
 
559
 
 
560
@noindent
 
561
@w{         Figure 12--9: Trigonometric Identities for Complex Domain        }
 
562
 
 
563
@end group
 
564
@end format
 
565
 
 
566
The quadrant numbers referred to in the discussions of branch cuts are as illustrated
 
567
in Figure 12--10.
 
568
 
 
569
@example
 
570
                           Imaginary Axis
 
571
                                 |
 
572
                                 |
 
573
                        II       |        I
 
574
                                 |
 
575
                                 |
 
576
                                 |
 
577
               ______________________________________ Real Axis
 
578
                                 |
 
579
                                 |
 
580
                                 |
 
581
                       III       |         IV
 
582
                                 |
 
583
                                 |
 
584
                                 |
 
585
                                 |
 
586
 
 
587
@end example
 
588
 
 
589
@w{  Figure 12--9: Quadrant Numbering for Branch Cuts}
 
590
 
 
591
@node Interval Designators, Random-State Operations, Complex Computations, Number Concepts
 
592
@subsection Interval Designators
 
593
 
 
594
The @i{compound type specifier} form of the numeric @i{type specifiers}
 
595
in Figure 12--10 permit the user to specify an interval on the real number line
 
596
which describe a @i{subtype} of the @i{type} which would be described by the
 
597
corresponding @i{atomic type specifier}.  A @i{subtype} of some @i{type}
 
598
@i{T} is specified using an ordered pair of @i{objects} called
 
599
@i{interval designators} for @i{type} @i{T}.
 
600
 
 
601
The first of the two @i{interval designators} for @i{type} @i{T} can be
 
602
any of the following:
 
603
 
 
604
@table @asis
 
605
 
 
606
@item a number @i{N} of @i{type} @i{T}  
 
607
This denotes a lower inclusive bound of @i{N}.  That is, @i{elements}
 
608
of the @i{subtype} of @i{T} will be greater than or equal to @i{N}.
 
609
 
 
610
@item a @i{singleton} @i{list} whose @i{element} is
 
611
          a number @i{M} of @i{type} @i{T}  
 
612
This denotes a lower exclusive bound of @i{M}.  That is, @i{elements}
 
613
of the @i{subtype} of @i{T} will be greater than @i{M}.
 
614
 
 
615
@item the symbol @b{*}  
 
616
This denotes the absence of a lower bound on the interval.
 
617
 
 
618
@end table
 
619
 
 
620
The second of the two @i{interval designators} for @i{type} @i{T} can be
 
621
any of the following:
 
622
 
 
623
@table @asis
 
624
 
 
625
@item a number @i{N} of @i{type} @i{T}  
 
626
This denotes an upper inclusive bound of @i{N}.  That is, @i{elements}
 
627
of the @i{subtype} of @i{T} will be less than or equal to @i{N}.
 
628
 
 
629
@item a @i{singleton} @i{list} whose @i{element} is
 
630
          a number @i{M} of @i{type} @i{T}  
 
631
This denotes an upper exclusive bound of @i{M}.  That is, @i{elements}
 
632
of the @i{subtype} of @i{T} will be less than @i{M}.
 
633
 
 
634
@item the symbol @b{*}  
 
635
This denotes the absence of an upper bound on the interval.
 
636
 
 
637
@end table
 
638
 
 
639
@node Random-State Operations,  , Interval Designators, Number Concepts
 
640
@subsection Random-State Operations
 
641
 
 
642
Figure 12--10 lists some @i{defined names} that are applicable to @i{random states}.
 
643
 
 
644
@format
 
645
@group
 
646
@noindent
 
647
@w{  *random-state*     random            }
 
648
@w{  make-random-state  random-state-p    }
 
649
 
 
650
@noindent
 
651
@w{  Figure 12--10: Random-state defined names}
 
652
 
 
653
@end group
 
654
@end format
 
655
 
 
656
@c end of including concept-numbers
 
657
 
 
658
@node Numbers Dictionary,  , Number Concepts, Numbers (Numbers)
 
659
@section Numbers Dictionary
 
660
 
 
661
@c including dict-numbers
 
662
 
 
663
@menu
 
664
* number::                      
 
665
* complex (System Class)::      
 
666
* real::                        
 
667
* float (System Class)::        
 
668
* short-float::                 
 
669
* rational (System Class)::                     
 
670
* ratio::                       
 
671
* integer::                     
 
672
* signed-byte::                 
 
673
* unsigned-byte::               
 
674
* mod (System Class)::                          
 
675
* bit (System Class)::                          
 
676
* fixnum::                      
 
677
* bignum::                      
 
678
* =::                           
 
679
* max::                         
 
680
* minusp::                      
 
681
* zerop::                       
 
682
* floor::                       
 
683
* sin::                         
 
684
* asin::                        
 
685
* pi::                          
 
686
* sinh::                        
 
687
* *::                           
 
688
* +::                           
 
689
* -::                           
 
690
* /::                           
 
691
* 1+::                          
 
692
* abs::                         
 
693
* evenp::                       
 
694
* exp::                         
 
695
* gcd::                         
 
696
* incf::                        
 
697
* lcm::                         
 
698
* log::                         
 
699
* mod (Function)::                              
 
700
* signum::                      
 
701
* sqrt::                        
 
702
* random-state::                
 
703
* make-random-state::           
 
704
* random::                      
 
705
* random-state-p::              
 
706
* *random-state*::              
 
707
* numberp::                     
 
708
* cis::                         
 
709
* complex::                     
 
710
* complexp::                    
 
711
* conjugate::                   
 
712
* phase::                       
 
713
* realpart::                    
 
714
* upgraded-complex-part-type::  
 
715
* realp::                       
 
716
* numerator::                   
 
717
* rational (Function)::                 
 
718
* rationalp::                   
 
719
* ash::                         
 
720
* integer-length::              
 
721
* integerp::                    
 
722
* parse-integer::               
 
723
* boole::                       
 
724
* boole-1::                     
 
725
* logand::                      
 
726
* logbitp::                     
 
727
* logcount::                    
 
728
* logtest::                     
 
729
* byte::                        
 
730
* deposit-field::               
 
731
* dpb::                         
 
732
* ldb::                         
 
733
* ldb-test::                    
 
734
* mask-field::                  
 
735
* most-positive-fixnum::        
 
736
* decode-float::                
 
737
* float::                       
 
738
* floatp::                      
 
739
* most-positive-short-float::   
 
740
* short-float-epsilon::         
 
741
* arithmetic-error::            
 
742
* arithmetic-error-operands::   
 
743
* division-by-zero::            
 
744
* floating-point-invalid-operation::  
 
745
* floating-point-inexact::      
 
746
* floating-point-overflow::     
 
747
* floating-point-underflow::    
 
748
@end menu
 
749
 
 
750
@node number, complex (System Class), Numbers Dictionary, Numbers Dictionary
 
751
@subsection number                                                       [System Class]
 
752
 
 
753
@subsubheading  Class Precedence List::
 
754
@b{number},
 
755
@b{t}
 
756
 
 
757
@subsubheading  Description::
 
758
 
 
759
The @i{type} @b{number} contains @i{objects} which represent
 
760
mathematical numbers.
 
761
 
 
762
The @i{types} @b{real} and @b{complex} are @i{disjoint} 
 
763
@i{subtypes} of @b{number}.
 
764
 
 
765
The @i{function} @b{=} tests for numerical equality.
 
766
The @i{function} @b{eql}, when its arguments are both @i{numbers}, 
 
767
tests that they have both the same @i{type} and numerical value.
 
768
Two @i{numbers} that are the @i{same} under @b{eql} or @b{=}
 
769
are not necessarily the @i{same} under @b{eq}.
 
770
 
 
771
@subsubheading  Notes::
 
772
 
 
773
@r{Common Lisp} differs from mathematics on some naming issues.  In mathematics,
 
774
the set of real numbers is traditionally described as a subset of the
 
775
complex numbers, but in @r{Common Lisp}, the @i{type} @b{real} and the @i{type} @b{complex} are
 
776
disjoint.  The @r{Common Lisp} type which includes all mathematical complex
 
777
numbers is called @b{number}.  The reasons for these differences
 
778
include historical precedent, compatibility with most other popular
 
779
computer languages, and various issues of time and space efficiency.
 
780
 
 
781
@node complex (System Class), real, number, Numbers Dictionary
 
782
@subsection complex                                                      [System Class]
 
783
 
 
784
@subsubheading  Class Precedence List::
 
785
@b{complex},
 
786
@b{number},
 
787
@b{t}
 
788
 
 
789
@subsubheading  Description::
 
790
 
 
791
The @i{type} @b{complex} includes all mathematical complex numbers
 
792
other than those included in the @i{type} @b{rational}.
 
793
@i{Complexes} are 
 
794
expressed
 
795
in Cartesian form with a
 
796
real part and an imaginary part, each of which is a @i{real}.
 
797
The real part and imaginary part are either both
 
798
@i{rational} or both of the same @i{float} @i{type}.
 
799
The imaginary part can be a @i{float} zero, but can never
 
800
be a @i{rational} zero, for such a number is always represented
 
801
by @r{Common Lisp} as a @i{rational} rather than a @i{complex}.
 
802
 
 
803
@subsubheading  Compound Type Specifier Kind::
 
804
 
 
805
Specializing.
 
806
 
 
807
@subsubheading  Compound Type Specifier Syntax::
 
808
 
 
809
(@code{complex}@{@i{@t{[}typespec | @b{*}@t{]}}@})
 
810
 
 
811
@subsubheading  Compound Type Specifier Arguments::
 
812
 
 
813
@i{typespec}---a @i{type specifier} that denotes a @i{subtype} of @i{type} @b{real}.
 
814
 
 
815
@subsubheading  Compound Type Specifier Description::
 
816
 
 
817
[Editorial Note by KMP: If you ask me, this definition is a complete mess.  Looking at
 
818
issue ARRAY-TYPE-ELEMENT-TYPE-SEMANTICS:UNIFY-UPGRADING does not help me figure 
 
819
it out, either.  Anyone got any suggestions?]
 
820
 
 
821
Every element of this @i{type} is a @i{complex} whose
 
822
real part and imaginary part are each of type
 
823
 
 
824
@t{(upgraded-complex-part-type @i{typespec})}.
 
825
 
 
826
This @i{type} encompasses those @i{complexes}
 
827
that can result by giving numbers of @i{type} @i{typespec}
 
828
to @b{complex}.
 
829
 
 
830
@t{(complex @i{type-specifier})}
 
831
refers to all @i{complexes} that can result from giving
 
832
@i{numbers} of @i{type} @i{type-specifier} to the @i{function} @b{complex}, 
 
833
plus all other @i{complexes} of the same specialized representation.      
 
834
 
 
835
@subsubheading  See Also::
 
836
 
 
837
@ref{Rule of Canonical Representation for Complex Rationals},
 
838
@ref{Constructing Numbers from Tokens},
 
839
@ref{Printing Complexes}
 
840
 
 
841
@subsubheading  Notes::
 
842
 
 
843
The input syntax for a @i{complex} with real part r and 
 
844
imaginary part i is @t{#C(r i)}.  
 
845
For further details, see @ref{Standard Macro Characters}.
 
846
 
 
847
For every @i{float}, n, there is a @i{complex}
 
848
which represents the same mathematical number 
 
849
and which can be obtained by @t{(COERCE n 'COMPLEX)}.
 
850
 
 
851
@node real, float (System Class), complex (System Class), Numbers Dictionary
 
852
@subsection real                                                         [System Class]
 
853
 
 
854
@subsubheading  Class Precedence List::
 
855
@b{real},
 
856
@b{number},
 
857
@b{t}
 
858
 
 
859
@subsubheading  Description::
 
860
 
 
861
The @i{type} @b{real} includes all @i{numbers} that
 
862
represent mathematical real numbers, though there are mathematical real
 
863
numbers (@i{e.g.}, irrational numbers) that do not have an exact representation 
 
864
in @r{Common Lisp}.  Only @i{reals} can be ordered using the
 
865
@b{<}, @b{>}, @b{<=}, and @b{>=} functions.
 
866
 
 
867
The @i{types} @b{rational} and @b{float} are @i{disjoint}
 
868
@i{subtypes} of @i{type} @b{real}.
 
869
 
 
870
@subsubheading  Compound Type Specifier Kind::
 
871
 
 
872
Abbreviating.
 
873
 
 
874
@subsubheading  Compound Type Specifier Syntax::
 
875
 
 
876
(@code{real}@{@i{@t{[}lower-limit @r{[}upper-limit@r{]}@t{]}}@})
 
877
 
 
878
@subsubheading  Compound Type Specifier Arguments::
 
879
 
 
880
@i{lower-limit}, @i{upper-limit}---@i{interval designators} 
 
881
                                           for @i{type} @b{real}.
 
882
 The defaults for each of @i{lower-limit} and @i{upper-limit} is the @i{symbol} @b{*}.
 
883
 
 
884
@subsubheading  Compound Type Specifier Description::
 
885
 
 
886
This denotes the @i{reals} on the interval described by
 
887
@i{lower-limit} and @i{upper-limit}.
 
888
 
 
889
@node float (System Class), short-float, real, Numbers Dictionary
 
890
@subsection float                                                        [System Class]
 
891
 
 
892
@subsubheading  Class Precedence List::
 
893
@b{float},
 
894
 
 
895
@b{real},
 
896
 
 
897
@b{number},
 
898
@b{t}
 
899
 
 
900
@subsubheading  Description::
 
901
 
 
902
A @i{float}
 
903
is a mathematical rational (but @i{not} a @r{Common Lisp} @i{rational})
 
904
of the form
 
905
s\cdot f\cdot b^@r{e-p},
 
906
where s is +1 or -1, the @i{sign};
 
907
b is an @i{integer} 
 
908
greater than~1, the @i{base} or @i{radix} of the representation;
 
909
p is a positive @i{integer}, 
 
910
the @i{precision} (in base-b digits) of the @i{float};
 
911
f is a positive @i{integer} 
 
912
between b^@r{p-1} and
 
913
b^p-1 (inclusive), the significand;
 
914
and e is an @i{integer}, the exponent.
 
915
The value of p and the range of~e
 
916
depends on the implementation and on the type of @i{float} 
 
917
within that implementation. In addition, there is a floating-point zero;
 
918
depending on the implementation, there can also be a ``minus zero''. If there
 
919
is no minus zero, then 0.0 and~-0.0 are both interpreted as simply a
 
920
floating-point zero.
 
921
@t{(= 0.0 -0.0)} is always true.  
 
922
If there is a minus zero, @t{(eql -0.0 0.0)} is @i{false},
 
923
otherwise it is @i{true}.
 
924
 
 
925
[Reviewer Note by Barmar: What about IEEE NaNs and infinities?]
 
926
 
 
927
[Reviewer Note by RWK: In the following, what is the ``ordering''?  precision? range?
 
928
          Can there be additional subtypes of float or does ``others'' in the
 
929
          list of four?]
 
930
 
 
931
The @i{types} @b{short-float}, @b{single-float}, @b{double-float}, 
 
932
and @b{long-float} are @i{subtypes} of @i{type} @b{float}.  Any two of them must be
 
933
either @i{disjoint} @i{types} or the @i{same} @i{type};
 
934
if the @i{same} @i{type}, then any other @i{types} between them in the
 
935
above ordering must also be the @i{same} @i{type}.  For example, 
 
936
if the @i{type} @b{single-float} and the @i{type} @b{long-float} are the @i{same} @i{type},
 
937
then the @i{type} @b{double-float} must be the @i{same} @i{type} also.
 
938
 
 
939
@subsubheading  Compound Type Specifier Kind::
 
940
 
 
941
Abbreviating.
 
942
 
 
943
@subsubheading  Compound Type Specifier Syntax::
 
944
 
 
945
(@code{float}@{@i{@t{[}lower-limit @r{[}upper-limit@r{]}@t{]}}@})
 
946
 
 
947
@subsubheading  Compound Type Specifier Arguments::
 
948
 
 
949
@i{lower-limit}, @i{upper-limit}---@i{interval designators} 
 
950
                                           for @i{type} @b{float}.
 
951
 The defaults for each of @i{lower-limit} and @i{upper-limit} is the @i{symbol} @b{*}.
 
952
 
 
953
@subsubheading  Compound Type Specifier Description::
 
954
 
 
955
This denotes the @i{floats} on the interval described by
 
956
@i{lower-limit} and @i{upper-limit}.
 
957
 
 
958
@subsubheading  See Also::
 
959
 
 
960
@i{Figure~2--9},
 
961
@ref{Constructing Numbers from Tokens},
 
962
@ref{Printing Floats}
 
963
 
 
964
@subsubheading  Notes::
 
965
 
 
966
Note that all mathematical integers are representable not only as
 
967
@r{Common Lisp} @i{reals}, but also as @i{complex floats}.  For example,
 
968
possible representations of the mathematical number 1 
 
969
include the @i{integer} @t{1},
 
970
        the @i{float} @t{1.0},
 
971
     or the @i{complex} @t{#C(1.0 0.0)}.  
 
972
 
 
973
@node short-float, rational (System Class), float (System Class), Numbers Dictionary
 
974
@subsection short-float, single-float, double-float, long-float                  [Type]
 
975
 
 
976
@subsubheading  Supertypes:: 
 
977
 
 
978
@b{short-float}: 
 
979
 @b{short-float},
 
980
 @b{float}, 
 
981
 
 
982
 @b{real},
 
983
 
 
984
 @b{number},
 
985
 @b{t}
 
986
 
 
987
@b{single-float}: 
 
988
 @b{single-float},
 
989
 @b{float}, 
 
990
 
 
991
 @b{real},
 
992
 
 
993
 @b{number},
 
994
 @b{t}
 
995
 
 
996
@b{double-float}: 
 
997
 @b{double-float},
 
998
 @b{float}, 
 
999
 
 
1000
 @b{real},
 
1001
 
 
1002
 @b{number},
 
1003
 @b{t}
 
1004
 
 
1005
@b{long-float}: 
 
1006
 @b{long-float},
 
1007
 @b{float}, 
 
1008
 
 
1009
 @b{real},
 
1010
 
 
1011
 @b{number},
 
1012
 @b{t}
 
1013
 
 
1014
@subsubheading  Description::
 
1015
 
 
1016
For the four defined @i{subtypes} of @i{type} @b{float}, it is true that
 
1017
intermediate between the @i{type} @b{short-float} and the @i{type} @b{long-float} are
 
1018
the @i{type} @b{single-float} and the @i{type} @b{double-float}.
 
1019
The precise definition of these categories is 
 
1020
@i{implementation-defined}.
 
1021
The precision (measured in ``bits'', computed as p\log_2b)
 
1022
and the exponent size (also measured in ``bits,'' computed as
 
1023
\log_2(n+1), where n is the maximum exponent value) is recommended
 
1024
to be at least as great
 
1025
as the values in Figure 12--11. 
 
1026
Each of the defined @i{subtypes} of @i{type} @b{float} might or might not have a minus zero.
 
1027
 
 
1028
@format
 
1029
@group
 
1030
@noindent
 
1031
@w{  @b{Format}  @b{Minimum Precision}  @b{Minimum Exponent Size}  }
 
1032
@w{  __________________________________________________}
 
1033
@w{  Short   13 bits            5 bits                 }
 
1034
@w{  Single  24 bits            8 bits                 }
 
1035
@w{  Double  50 bits            8 bits                 }
 
1036
@w{  Long    50 bits            8 bits                 }
 
1037
 
 
1038
@noindent
 
1039
@w{  Figure 12--11: Recommended Minimum Floating-Point Precision and Exponent Size}
 
1040
 
 
1041
@end group
 
1042
@end format
 
1043
 
 
1044
There can be fewer than four internal 
 
1045
representations for @i{floats}. 
 
1046
If there are fewer distinct representations, the following rules apply:
 
1047
@table @asis
 
1048
 
 
1049
@item --  
 
1050
If there is only one, it is 
 
1051
the @i{type} @b{single-float}.
 
1052
In this representation, an @i{object} is simultaneously of @i{types} 
 
1053
@b{single-float}, @b{double-float}, @b{short-float}, 
 
1054
and @b{long-float}.
 
1055
@item --  
 
1056
Two internal representations can be arranged in either of the
 
1057
following ways:
 
1058
@table @asis
 
1059
 
 
1060
@item @t{*}  
 
1061
Two @i{types} are provided: @b{single-float} and
 
1062
@b{short-float}.  An @i{object} is simultaneously 
 
1063
of @i{types} @b{single-float}, @b{double-float}, and @b{long-float}.
 
1064
@item @t{*}  
 
1065
Two @i{types} are provided: @b{single-float} and
 
1066
@b{double-float}. An @i{object} is simultaneously of @i{types}
 
1067
@b{single-float} and @b{short-float}, or
 
1068
@b{double-float} and @b{long-float}.
 
1069
@end table
 
1070
 
 
1071
@item --  
 
1072
Three internal representations can be arranged in either
 
1073
of the following ways:
 
1074
@table @asis
 
1075
 
 
1076
@item @t{*}  
 
1077
Three @i{types} are provided: @b{short-float}, 
 
1078
@b{single-float}, and @b{double-float}.
 
1079
An @i{object} can simultaneously be of @i{type} @b{double-float}
 
1080
and @b{long-float}.
 
1081
@item @t{*}  
 
1082
Three @i{types} are provided: 
 
1083
@b{single-float}, @b{double-float},
 
1084
and @b{long-float}. An @i{object} can simultaneously
 
1085
be of @i{types} @b{single-float} and @b{short-float}.
 
1086
@end table
 
1087
 
 
1088
@end table
 
1089
 
 
1090
@subsubheading  Compound Type Specifier Kind::
 
1091
 
 
1092
Abbreviating.
 
1093
 
 
1094
@subsubheading  Compound Type Specifier Syntax::
 
1095
 
 
1096
(@code{short-float}@{@i{@t{[}short-lower-limit   @r{[}short-upper-limit@r{]}@t{]}}@})
 
1097
(@code{single-float}@{@i{@t{[}single-lower-limit @r{[}single-upper-limit@r{]}@t{]}}@})
 
1098
(@code{double-float}@{@i{@t{[}double-lower-limit @r{[}double-upper-limit@r{]}@t{]}}@})
 
1099
(@code{long-float}@{@i{@t{[}long-lower-limit     @r{[}long-upper-limit@r{]}@t{]}}@})
 
1100
 
 
1101
@subsubheading  Compound Type Specifier Arguments::
 
1102
 
 
1103
@i{short-lower-limit}, @i{short-upper-limit}---@i{interval designators} 
 
1104
                                           for @i{type} @b{short-float}.
 
1105
 The defaults for each of @i{lower-limit} and @i{upper-limit} is the @i{symbol} @b{*}.
 
1106
 
 
1107
@i{single-lower-limit}, @i{single-upper-limit}---@i{interval designators} 
 
1108
                                           for @i{type} @b{single-float}.
 
1109
 The defaults for each of @i{lower-limit} and @i{upper-limit} is the @i{symbol} @b{*}.
 
1110
 
 
1111
@i{double-lower-limit}, @i{double-upper-limit}---@i{interval designators} 
 
1112
                                           for @i{type} @b{double-float}.
 
1113
 The defaults for each of @i{lower-limit} and @i{upper-limit} is the @i{symbol} @b{*}.
 
1114
 
 
1115
@i{long-lower-limit}, @i{long-upper-limit}---@i{interval designators} 
 
1116
                                           for @i{type} @b{long-float}.
 
1117
 The defaults for each of @i{lower-limit} and @i{upper-limit} is the @i{symbol} @b{*}.
 
1118
 
 
1119
@subsubheading  Compound Type Specifier Description::
 
1120
 
 
1121
Each of these denotes the set of @i{floats} of the indicated @i{type} 
 
1122
that are on the interval specified by the @i{interval designators}.
 
1123
 
 
1124
@node rational (System Class), ratio, short-float, Numbers Dictionary
 
1125
@subsection rational                                                     [System Class]
 
1126
 
 
1127
@subsubheading  Class Precedence List::
 
1128
@b{rational},
 
1129
 
 
1130
@b{real},
 
1131
 
 
1132
@b{number},
 
1133
@b{t}
 
1134
 
 
1135
@subsubheading  Description::
 
1136
 
 
1137
The canonical representation of a @i{rational} 
 
1138
is as an @i{integer} if its value is integral,
 
1139
and otherwise as a @i{ratio}.
 
1140
 
 
1141
The @i{types} @b{integer} and @b{ratio} 
 
1142
are @i{disjoint} @i{subtypes} of @i{type} @b{rational}.
 
1143
 
 
1144
@subsubheading  Compound Type Specifier Kind::
 
1145
 
 
1146
Abbreviating.
 
1147
 
 
1148
@subsubheading  Compound Type Specifier Syntax::
 
1149
 
 
1150
(@code{rational}@{@i{@t{[}lower-limit @r{[}upper-limit@r{]}@t{]}}@})
 
1151
 
 
1152
@subsubheading  Compound Type Specifier Arguments::
 
1153
 
 
1154
@i{lower-limit}, @i{upper-limit}---@i{interval designators} 
 
1155
                                           for @i{type} @b{rational}.
 
1156
 The defaults for each of @i{lower-limit} and @i{upper-limit} is the @i{symbol} @b{*}.
 
1157
 
 
1158
@subsubheading  Compound Type Specifier Description::
 
1159
 
 
1160
This denotes the @i{rationals} on the interval described by
 
1161
@i{lower-limit} and @i{upper-limit}.
 
1162
 
 
1163
@node ratio, integer, rational (System Class), Numbers Dictionary
 
1164
@subsection ratio                                                        [System Class]
 
1165
 
 
1166
@subsubheading  Class Precedence List::
 
1167
@b{ratio},
 
1168
@b{rational},
 
1169
 
 
1170
@b{real},
 
1171
 
 
1172
@b{number},
 
1173
@b{t}
 
1174
 
 
1175
@subsubheading  Description::
 
1176
 
 
1177
A @i{ratio} is a @i{number} 
 
1178
representing the mathematical ratio of two non-zero integers,
 
1179
the numerator and denominator,
 
1180
whose greatest common divisor is one,
 
1181
and of which the denominator is positive and greater than one.
 
1182
 
 
1183
@subsubheading  See Also::
 
1184
 
 
1185
@i{Figure~2--9},
 
1186
@ref{Constructing Numbers from Tokens},
 
1187
@ref{Printing Ratios}
 
1188
 
 
1189
@node integer, signed-byte, ratio, Numbers Dictionary
 
1190
@subsection integer                                                      [System Class]
 
1191
 
 
1192
@subsubheading  Class Precedence List::
 
1193
@b{integer},
 
1194
@b{rational},
 
1195
 
 
1196
@b{real},
 
1197
 
 
1198
@b{number},
 
1199
@b{t}
 
1200
 
 
1201
@subsubheading  Description::
 
1202
 
 
1203
An @i{integer} is a mathematical integer. There is no limit on the 
 
1204
magnitude of an @i{integer}.
 
1205
 
 
1206
The @i{types} @b{fixnum} and @b{bignum} 
 
1207
form an @i{exhaustive partition} of @i{type} @b{integer}.
 
1208
 
 
1209
@subsubheading  Compound Type Specifier Kind::
 
1210
 
 
1211
Abbreviating.
 
1212
 
 
1213
@subsubheading  Compound Type Specifier Syntax::
 
1214
 
 
1215
(@code{integer}@{@i{@t{[}lower-limit @r{[}upper-limit@r{]}@t{]}}@})
 
1216
 
 
1217
@subsubheading  Compound Type Specifier Arguments::
 
1218
 
 
1219
@i{lower-limit}, @i{upper-limit}---@i{interval designators} 
 
1220
                                           for @i{type} @b{integer}.
 
1221
 The defaults for each of @i{lower-limit} and @i{upper-limit} is the @i{symbol} @b{*}.
 
1222
 
 
1223
@subsubheading  Compound Type Specifier Description::
 
1224
 
 
1225
This denotes the @i{integers} on the interval described by
 
1226
@i{lower-limit} and @i{upper-limit}.
 
1227
 
 
1228
@subsubheading  See Also::
 
1229
 
 
1230
@i{Figure~2--9},
 
1231
@ref{Constructing Numbers from Tokens},
 
1232
@ref{Printing Integers}
 
1233
 
 
1234
@subsubheading  Notes::
 
1235
 
 
1236
The @i{type} @t{(integer @i{lower} @i{upper})},
 
1237
where @i{lower} and @i{upper} 
 
1238
are @b{most-negative-fixnum} and @b{most-positive-fixnum}, respectively,
 
1239
is also called @b{fixnum}.
 
1240
 
 
1241
The @i{type} @t{(integer 0 1)} is also called @b{bit}.
 
1242
The @i{type} @t{(integer 0 *)} is also called @b{unsigned-byte}.
 
1243
 
 
1244
@node signed-byte, unsigned-byte, integer, Numbers Dictionary
 
1245
@subsection signed-byte                                                          [Type]
 
1246
 
 
1247
@subsubheading  Supertypes:: 
 
1248
 
 
1249
@b{signed-byte},
 
1250
@b{integer},
 
1251
@b{rational},
 
1252
 
 
1253
@b{real},
 
1254
 
 
1255
@b{number},
 
1256
@b{t}
 
1257
 
 
1258
@subsubheading  Description::
 
1259
 
 
1260
The atomic @i{type specifier} @b{signed-byte} denotes the same 
 
1261
type as is denoted by the @i{type specifier} @b{integer};
 
1262
however, the list forms of these two @i{type specifiers} have different semantics.
 
1263
 
 
1264
@subsubheading  Compound Type Specifier Kind::
 
1265
 
 
1266
Abbreviating.
 
1267
 
 
1268
@subsubheading  Compound Type Specifier Syntax::
 
1269
 
 
1270
(@code{signed-byte}@{@i{@t{[}s | @b{*}@t{]}}@})
 
1271
 
 
1272
@subsubheading  Compound Type Specifier Arguments::
 
1273
 
 
1274
@i{s}---a positive @i{integer}.
 
1275
 
 
1276
@subsubheading  Compound Type Specifier Description::
 
1277
 
 
1278
This denotes the set of @i{integers} that can be represented
 
1279
in two's-complement form in a @i{byte} of @i{s} bits.  This is
 
1280
equivalent to @t{(integer -2^@r{s-1} 2^@r{s-1}-1)}.  The type
 
1281
@b{signed-byte} or the type @t{(signed-byte *)} is the same
 
1282
as the @i{type} @b{integer}.
 
1283
 
 
1284
@node unsigned-byte, mod (System Class), signed-byte, Numbers Dictionary
 
1285
@subsection unsigned-byte                                                        [Type]
 
1286
 
 
1287
@subsubheading  Supertypes:: 
 
1288
 
 
1289
@b{unsigned-byte},
 
1290
@b{signed-byte},
 
1291
@b{integer},
 
1292
@b{rational},
 
1293
 
 
1294
@b{real},
 
1295
 
 
1296
@b{number},
 
1297
@b{t}
 
1298
 
 
1299
@subsubheading  Description::
 
1300
 
 
1301
The atomic @i{type specifier} @b{unsigned-byte} denotes the same 
 
1302
type as is denoted by the @i{type specifier} @t{(integer 0 *)}.  
 
1303
 
 
1304
@subsubheading  Compound Type Specifier Kind::
 
1305
 
 
1306
Abbreviating.
 
1307
 
 
1308
@subsubheading  Compound Type Specifier Syntax::
 
1309
 
 
1310
(@code{unsigned-byte}@{@i{@t{[}@i{s} | @b{*}@t{]}}@})
 
1311
 
 
1312
@subsubheading  Compound Type Specifier Arguments::
 
1313
 
 
1314
@i{s}---a positive @i{integer}.
 
1315
 
 
1316
@subsubheading  Compound Type Specifier Description::
 
1317
 
 
1318
This denotes the set of non-negative @i{integers} that can be
 
1319
represented in a byte of size @i{s} (bits).  
 
1320
This is equivalent 
 
1321
to @t{(mod @i{m})} for @i{m}=2^s, or
 
1322
to @t{(integer 0 @i{n})} for @i{n}=2^s-1.
 
1323
The @i{type} @b{unsigned-byte} or 
 
1324
the type @t{(unsigned-byte *)} is the same as
 
1325
the type @t{(integer 0 *)}, the set of non-negative @i{integers}.
 
1326
 
 
1327
@subsubheading  Notes::
 
1328
 
 
1329
The @i{type} @t{(unsigned-byte 1)} is also called @b{bit}.
 
1330
 
 
1331
@node mod (System Class), bit (System Class), unsigned-byte, Numbers Dictionary
 
1332
@subsection mod                                                        [Type Specifier]
 
1333
 
 
1334
@subsubheading  Compound Type Specifier Kind::
 
1335
 
 
1336
Abbreviating.
 
1337
 
 
1338
@subsubheading  Compound Type Specifier Syntax::
 
1339
 
 
1340
(@code{mod}@{@i{n}@})
 
1341
 
 
1342
@subsubheading  Compound Type Specifier Arguments::
 
1343
 
 
1344
@i{n}---a positive @i{integer}.
 
1345
 
 
1346
@subsubheading  Compound Type Specifier Description::
 
1347
 
 
1348
This denotes the set of non-negative @i{integers} less than @i{n}.
 
1349
This is equivalent to 
 
1350
  @t{(integer 0 (@i{n}))}
 
1351
or to
 
1352
  @t{(integer 0 @i{m})},
 
1353
where @i{m}=@i{n}-1.
 
1354
 
 
1355
The argument is required, and cannot be @b{*}.
 
1356
 
 
1357
The symbol @b{mod} is not valid as a @i{type specifier}.
 
1358
 
 
1359
@node bit (System Class), fixnum, mod (System Class), Numbers Dictionary
 
1360
@subsection bit                                                                  [Type]
 
1361
 
 
1362
@subsubheading  Supertypes:: 
 
1363
 
 
1364
@b{bit},
 
1365
@b{unsigned-byte},
 
1366
@b{signed-byte},
 
1367
@b{integer},
 
1368
@b{rational},
 
1369
 
 
1370
@b{real},
 
1371
 
 
1372
@b{number},
 
1373
@b{t}
 
1374
 
 
1375
@subsubheading  Description::
 
1376
 
 
1377
The @i{type} @b{bit} is equivalent to the @i{type} @t{(integer 0 1)}
 
1378
and @t{(unsigned-byte 1)}.
 
1379
 
 
1380
@node fixnum, bignum, bit (System Class), Numbers Dictionary
 
1381
@subsection fixnum                                                               [Type]
 
1382
 
 
1383
@subsubheading  Supertypes:: 
 
1384
 
 
1385
@b{fixnum},
 
1386
@b{integer},
 
1387
@b{rational},
 
1388
 
 
1389
@b{real},
 
1390
 
 
1391
@b{number},
 
1392
@b{t}
 
1393
 
 
1394
@subsubheading  Description::
 
1395
 
 
1396
A @i{fixnum} is an @i{integer} whose value is between 
 
1397
@b{most-negative-fixnum} and @b{most-positive-fixnum} inclusive.
 
1398
Exactly which @i{integers} are @i{fixnums} is 
 
1399
@i{implementation-defined}.
 
1400
 
 
1401
The @i{type} @b{fixnum} is required to be a supertype of
 
1402
@t{(signed-byte 16)}.
 
1403
 
 
1404
@node bignum, =, fixnum, Numbers Dictionary
 
1405
@subsection bignum                                                               [Type]
 
1406
 
 
1407
@subsubheading  Supertypes:: 
 
1408
 
 
1409
@b{bignum},
 
1410
@b{integer},
 
1411
@b{rational},
 
1412
 
 
1413
@b{real},
 
1414
 
 
1415
@b{number},
 
1416
@b{t}
 
1417
 
 
1418
@subsubheading  Description::
 
1419
 
 
1420
The @i{type} @b{bignum} is defined to be exactly @t{(and integer (not fixnum))}.
 
1421
 
 
1422
@node =, max, bignum, Numbers Dictionary
 
1423
@subsection =, /=, <, >, <=, >=                                              [Function]
 
1424
 
 
1425
@code{=}  @i{@r{&rest} numbers^+} @result{}  @i{generalized-boolean}
 
1426
 
 
1427
@code{/=}  @i{@r{&rest} numbers^+} @result{}  @i{generalized-boolean}
 
1428
 
 
1429
@code{<}  @i{@r{&rest} numbers^+} @result{}  @i{generalized-boolean}
 
1430
 
 
1431
@code{>}  @i{@r{&rest} numbers^+} @result{}  @i{generalized-boolean}
 
1432
 
 
1433
@code{<=}  @i{@r{&rest} numbers^+} @result{}  @i{generalized-boolean}
 
1434
 
 
1435
@code{>=}  @i{@r{&rest} numbers^+} @result{}  @i{generalized-boolean}
 
1436
 
 
1437
@subsubheading  Arguments and Values::
 
1438
 
 
1439
@i{number}---for @b{<}, @b{>}, @b{<=}, @b{>=}: a @i{real};
 
1440
                 for @b{=}, @b{/=}: a @i{number}.
 
1441
 
 
1442
@i{generalized-boolean}---a @i{generalized boolean}.
 
1443
 
 
1444
@subsubheading  Description::
 
1445
 
 
1446
@b{=}, @b{/=}, @b{<}, @b{>}, @b{<=}, and @b{>=} 
 
1447
perform arithmetic comparisons on their arguments as follows:
 
1448
 
 
1449
@table @asis
 
1450
 
 
1451
@item @b{=}  
 
1452
The value of @b{=} is @i{true} if all @i{numbers} are the same in value;
 
1453
otherwise it is @i{false}.
 
1454
Two @i{complexes} are considered equal by @b{=}
 
1455
if their real and imaginary parts are equal according to @b{=}.
 
1456
 
 
1457
@item @b{/=}  
 
1458
The value of @b{/=} is @i{true} if no two @i{numbers} are the same in value;
 
1459
otherwise it is @i{false}.
 
1460
 
 
1461
@item @b{<}  
 
1462
The value of @b{<} is @i{true} if the @i{numbers} are in monotonically increasing order;
 
1463
otherwise it is @i{false}.
 
1464
 
 
1465
@item @b{>}  
 
1466
The value of @b{>} is @i{true} if the @i{numbers} are in monotonically decreasing order;
 
1467
otherwise it is @i{false}.
 
1468
 
 
1469
@item @b{<=}  
 
1470
The value of @b{<=} is @i{true} if the @i{numbers} are in monotonically 
 
1471
 nondecreasing order;
 
1472
otherwise it is @i{false}.
 
1473
 
 
1474
@item @b{>=}  
 
1475
The value of @b{>=} is @i{true} if the @i{numbers} are in monotonically
 
1476
 nonincreasing order;
 
1477
otherwise it is @i{false}.
 
1478
@end table
 
1479
 
 
1480
@b{=}, @b{/=}, @b{<}, @b{>}, @b{<=}, and @b{>=} 
 
1481
perform necessary type conversions. 
 
1482
 
 
1483
@subsubheading  Examples::
 
1484
 
 
1485
The uses of these functions are illustrated in Figure 12--12.
 
1486
 
 
1487
@format
 
1488
@group
 
1489
@noindent
 
1490
@w{  @t{(= 3 3)} is @i{true}.              @t{(/= 3 3)} is @i{false}.             }
 
1491
@w{  @t{(= 3 5)} is @i{false}.             @t{(/= 3 5)} is @i{true}.              }
 
1492
@w{  @t{(= 3 3 3 3)} is @i{true}.          @t{(/= 3 3 3 3)} is @i{false}.         }
 
1493
@w{  @t{(= 3 3 5 3)} is @i{false}.         @t{(/= 3 3 5 3)} is @i{false}.         }
 
1494
@w{  @t{(= 3 6 5 2)} is @i{false}.         @t{(/= 3 6 5 2)} is @i{true}.          }
 
1495
@w{  @t{(= 3 2 3)} is @i{false}.           @t{(/= 3 2 3)} is @i{false}.           }
 
1496
@w{  @t{(< 3 5)} is @i{true}.              @t{(<= 3 5)} is @i{true}.              }
 
1497
@w{  @t{(< 3 -5)} is @i{false}.            @t{(<= 3 -5)} is @i{false}.            }
 
1498
@w{  @t{(< 3 3)} is @i{false}.             @t{(<= 3 3)} is @i{true}.              }
 
1499
@w{  @t{(< 0 3 4 6 7)} is @i{true}.        @t{(<= 0 3 4 6 7)} is @i{true}.        }
 
1500
@w{  @t{(< 0 3 4 4 6)} is @i{false}.       @t{(<= 0 3 4 4 6)} is @i{true}.        }
 
1501
@w{  @t{(> 4 3)} is @i{true}.              @t{(>= 4 3)} is @i{true}.              }
 
1502
@w{  @t{(> 4 3 2 1 0)} is @i{true}.        @t{(>= 4 3 2 1 0)} is @i{true}.        }
 
1503
@w{  @t{(> 4 3 3 2 0)} is @i{false}.       @t{(>= 4 3 3 2 0)} is @i{true}.        }
 
1504
@w{  @t{(> 4 3 1 2 0)} is @i{false}.       @t{(>= 4 3 1 2 0)} is @i{false}.       }
 
1505
@w{  @t{(= 3)} is @i{true}.                @t{(/= 3)} is @i{true}.                }
 
1506
@w{  @t{(< 3)} is @i{true}.                @t{(<= 3)} is @i{true}.                }
 
1507
@w{  @t{(= 3.0 #c(3.0 0.0))} is @i{true}.  @t{(/= 3.0 #c(3.0 1.0))} is @i{true}.  }
 
1508
@w{  @t{(= 3 3.0)} is @i{true}.            @t{(= 3.0s0 3.0d0)} is @i{true}.       }
 
1509
@w{  @t{(= 0.0 -0.0)} is @i{true}.         @t{(= 5/2 2.5)} is @i{true}.           }
 
1510
@w{  @t{(> 0.0 -0.0)} is @i{false}.        @t{(= 0 -0.0)} is @i{true}.            }
 
1511
@w{  @t{(<= 0 x 9)} is @i{true} if @t{x} is between @t{0} and @t{9}, inclusive}
 
1512
@w{  @t{(< 0.0 x 1.0)} is @i{true} if @t{x} is between @t{0.0} and @t{1.0}, exclusive}
 
1513
@w{  @t{(< -1 j (length v))} is @i{true} if @t{j} is a @i{valid array index} for a @i{vector} @t{v}}
 
1514
 
 
1515
@noindent
 
1516
@w{         Figure 12--12: Uses of /=, =, <, >, <=, and >=        }
 
1517
 
 
1518
@end group
 
1519
@end format
 
1520
 
 
1521
@subsubheading  Exceptional Situations::
 
1522
 
 
1523
Might signal @b{type-error} if some @i{argument} is not a @i{real}.
 
1524
Might signal @b{arithmetic-error} if otherwise unable to fulfill its contract.
 
1525
 
 
1526
@subsubheading  Notes::
 
1527
 
 
1528
@b{=} differs from @b{eql} in that
 
1529
@t{(= 0.0 -0.0)} is always true,
 
1530
because @b{=} compares the mathematical values of its operands,
 
1531
whereas @b{eql} compares the representational values, so to speak.
 
1532
 
 
1533
@node max, minusp, =, Numbers Dictionary
 
1534
@subsection max, min                                                         [Function]
 
1535
 
 
1536
@code{max}  @i{@r{&rest} reals^+} @result{}  @i{max-real}
 
1537
 
 
1538
@code{min}  @i{@r{&rest} reals^+} @result{}  @i{min-real}
 
1539
 
 
1540
@subsubheading  Arguments and Values::
 
1541
 
 
1542
@i{real}---a @i{real}.
 
1543
 
 
1544
@i{max-real}, @i{min-real}---a @i{real}.
 
1545
 
 
1546
@subsubheading  Description::
 
1547
 
 
1548
@b{max} returns the @i{real} that is greatest (closest to positive infinity).
 
1549
@b{min} returns the @i{real} that is least (closest to negative infinity).
 
1550
 
 
1551
For @b{max},
 
1552
the implementation has the choice of returning the largest
 
1553
argument as is or applying the rules of floating-point @i{contagion},
 
1554
taking all the arguments into consideration for @i{contagion} purposes.
 
1555
Also, if one or more of the arguments are @b{=}, then any one
 
1556
of them may be chosen as the value to return.
 
1557
For example, if the @i{reals} are a mixture of @i{rationals} and @i{floats},
 
1558
and the largest argument is a @i{rational},
 
1559
then the implementation is free to
 
1560
produce either that @i{rational} 
 
1561
or its @i{float} approximation;
 
1562
if the largest argument is a 
 
1563
@i{float} of a smaller format
 
1564
than the largest format of any @i{float} argument,
 
1565
then the implementation is free to
 
1566
return the argument in its given format or expanded to the larger format.
 
1567
Similar remarks apply to @b{min} 
 
1568
(replacing ``largest argument'' by ``smallest argument'').
 
1569
 
 
1570
@subsubheading  Examples::
 
1571
 
 
1572
@example
 
1573
 (max 3) @result{}  3 
 
1574
 (min 3) @result{}  3
 
1575
 (max 6 12) @result{}  12 
 
1576
 (min 6 12) @result{}  6
 
1577
 (max -6 -12) @result{}  -6 
 
1578
 (min -6 -12) @result{}  -12
 
1579
 (max 1 3 2 -7) @result{}  3 
 
1580
 (min 1 3 2 -7) @result{}  -7
 
1581
 (max -2 3 0 7) @result{}  7 
 
1582
 (min -2 3 0 7) @result{}  -2
 
1583
 (max 5.0 2) @result{}  5.0 
 
1584
 (min 5.0 2)
 
1585
@result{}  2
 
1586
@i{OR}@result{} 2.0
 
1587
 (max 3.0 7 1)
 
1588
@result{}  7
 
1589
@i{OR}@result{} 7.0 
 
1590
 (min 3.0 7 1)
 
1591
@result{}  1
 
1592
@i{OR}@result{} 1.0
 
1593
 (max 1.0s0 7.0d0) @result{}  7.0d0
 
1594
 (min 1.0s0 7.0d0)
 
1595
@result{}  1.0s0
 
1596
@i{OR}@result{} 1.0d0
 
1597
 (max 3 1 1.0s0 1.0d0)
 
1598
@result{}  3
 
1599
@i{OR}@result{} 3.0d0
 
1600
 (min 3 1 1.0s0 1.0d0)
 
1601
@result{}  1
 
1602
@i{OR}@result{} 1.0s0 
 
1603
@i{OR}@result{} 1.0d0
 
1604
@end example
 
1605
 
 
1606
@subsubheading  Exceptional Situations::
 
1607
 
 
1608
Should signal an error of @i{type} @b{type-error}
 
1609
                              if any @i{number} is not a @i{real}.
 
1610
 
 
1611
@node minusp, zerop, max, Numbers Dictionary
 
1612
@subsection minusp, plusp                                                    [Function]
 
1613
 
 
1614
@code{minusp}  @i{real} @result{}  @i{generalized-boolean}
 
1615
 
 
1616
@code{plusp}  @i{real} @result{}  @i{generalized-boolean}
 
1617
 
 
1618
@subsubheading  Arguments and Values::
 
1619
 
 
1620
@i{real}---a @i{real}.
 
1621
 
 
1622
@i{generalized-boolean}---a @i{generalized boolean}.
 
1623
 
 
1624
@subsubheading  Description::
 
1625
 
 
1626
@b{minusp} returns @i{true} if @i{real} is less than zero;
 
1627
otherwise, returns @i{false}.
 
1628
 
 
1629
@b{plusp} returns @i{true} if @i{real} is greater than zero;
 
1630
otherwise, returns @i{false}.
 
1631
 
 
1632
Regardless of whether an @i{implementation} provides distinct
 
1633
representations for positive and negative @i{float} zeros,
 
1634
@t{(minusp -0.0)} always returns @i{false}.
 
1635
 
 
1636
@subsubheading  Examples::
 
1637
@example
 
1638
 (minusp -1) @result{}  @i{true}
 
1639
 (plusp 0) @result{}  @i{false}
 
1640
 (plusp least-positive-single-float) @result{}  @i{true}
 
1641
@end example
 
1642
 
 
1643
@subsubheading  Exceptional Situations::
 
1644
 
 
1645
Should signal an error of @i{type} @b{type-error}
 
1646
                              if @i{real} is not a @i{real}.
 
1647
 
 
1648
@node zerop, floor, minusp, Numbers Dictionary
 
1649
@subsection zerop                                                            [Function]
 
1650
 
 
1651
@code{zerop}  @i{number} @result{}  @i{generalized-boolean}
 
1652
 
 
1653
@subsubheading  Pronunciation::
 
1654
 
 
1655
pronounced 'z\=e (, )r\=o@r{}(, )p\=e
 
1656
 
 
1657
@subsubheading  Arguments and Values::
 
1658
 
 
1659
@i{number}---a @i{number}.
 
1660
 
 
1661
@i{generalized-boolean}---a @i{generalized boolean}.
 
1662
 
 
1663
@subsubheading  Description::
 
1664
 
 
1665
Returns @i{true} if @i{number} is zero (@i{integer}, @i{float}, or @i{complex});
 
1666
otherwise, returns @i{false}.
 
1667
 
 
1668
Regardless of whether an @i{implementation} provides distinct representations
 
1669
for positive and negative floating-point zeros, @t{(zerop -0.0)} 
 
1670
always returns @i{true}.
 
1671
 
 
1672
@subsubheading  Examples::
 
1673
 
 
1674
@example
 
1675
 (zerop 0) @result{}  @i{true}
 
1676
 (zerop 1) @result{}  @i{false}
 
1677
 (zerop -0.0) @result{}  @i{true}
 
1678
 (zerop 0/100) @result{}  @i{true}
 
1679
 (zerop #c(0 0.0)) @result{}  @i{true}
 
1680
@end example
 
1681
 
 
1682
@subsubheading  Exceptional Situations::
 
1683
 
 
1684
Should signal an error of @i{type} @b{type-error}
 
1685
                              if @i{number} is not a @i{number}.
 
1686
 
 
1687
@subsubheading  Notes::
 
1688
 
 
1689
@example
 
1690
 (zerop @i{number}) @equiv{} (= @i{number} 0)
 
1691
@end example
 
1692
 
 
1693
@node floor, sin, zerop, Numbers Dictionary
 
1694
@subsection floor, ffloor, ceiling, fceiling,
 
1695
@subheading truncate, ftruncate, round, fround
 
1696
@flushright
 
1697
@i{[Function]}
 
1698
@end flushright
 
1699
 
 
1700
@code{floor}  @i{number @r{&optional} divisor} @result{}  @i{quotient, remainder}
 
1701
 
 
1702
@code{ffloor}  @i{number @r{&optional} divisor} @result{}  @i{quotient, remainder}
 
1703
 
 
1704
@code{ceiling}  @i{number @r{&optional} divisor} @result{}  @i{quotient, remainder}
 
1705
 
 
1706
@code{fceiling}  @i{number @r{&optional} divisor} @result{}  @i{quotient, remainder}
 
1707
 
 
1708
@code{truncate}  @i{number @r{&optional} divisor} @result{}  @i{quotient, remainder}
 
1709
 
 
1710
@code{ftruncate}  @i{number @r{&optional} divisor} @result{}  @i{quotient, remainder}
 
1711
 
 
1712
@code{round}  @i{number @r{&optional} divisor} @result{}  @i{quotient, remainder}
 
1713
 
 
1714
@code{fround}  @i{number @r{&optional} divisor} @result{}  @i{quotient, remainder}
 
1715
 
 
1716
@subsubheading  Arguments and Values::
 
1717
 
 
1718
@i{number}---a @i{real}.
 
1719
 
 
1720
@i{divisor}---a non-zero @i{real}.
 
1721
 The default is the @i{integer} @t{1}.
 
1722
 
 
1723
@i{quotient}---for @b{floor}, @b{ceiling}, 
 
1724
                       @b{truncate}, and @b{round}: an @i{integer};
 
1725
                   for @b{ffloor}, @b{fceiling}, 
 
1726
                       @b{ftruncate}, and @b{fround}: a @i{float}.
 
1727
 
 
1728
@i{remainder}---a @i{real}.
 
1729
 
 
1730
@subsubheading  Description::
 
1731
 
 
1732
These functions divide @i{number} by @i{divisor}, 
 
1733
returning a @i{quotient} and @i{remainder}, such that 
 
1734
 
 
1735
 @i{quotient}@r{\cdot} @i{divisor}+@i{remainder}=@i{number}
 
1736
 
 
1737
The @i{quotient} always represents a mathematical integer.
 
1738
When more than one mathematical integer might be possible
 
1739
 (@i{i.e.}, when the remainder is not zero),
 
1740
the kind of rounding or truncation depends on the @i{operator}:
 
1741
 
 
1742
@table @asis
 
1743
 
 
1744
@item @b{floor}, @b{ffloor}  
 
1745
@b{floor} and @b{ffloor} produce a @i{quotient} 
 
1746
that has been truncated toward negative infinity;
 
1747
that is, the @i{quotient} represents the largest mathematical integer
 
1748
that is not larger than the mathematical quotient.
 
1749
 
 
1750
@item @b{ceiling}, @b{fceiling}  
 
1751
@b{ceiling} and @b{fceiling} produce a @i{quotient}
 
1752
that has been truncated toward positive infinity;
 
1753
that is, the @i{quotient} represents the smallest mathematical integer
 
1754
that is not smaller than the mathematical result.
 
1755
 
 
1756
@item @b{truncate}, @b{ftruncate}  
 
1757
@b{truncate} and @b{ftruncate} produce a @i{quotient}
 
1758
that has been truncated towards zero;
 
1759
that is, the @i{quotient} represents the mathematical integer
 
1760
of the same sign as the mathematical quotient, and
 
1761
that has the greatest integral magnitude not greater than that of the mathematical quotient.
 
1762
 
 
1763
@item @b{round}, @b{fround}  
 
1764
@b{round} and @b{fround} produce a @i{quotient}
 
1765
that has been rounded to the nearest mathematical integer;
 
1766
if the mathematical quotient is exactly halfway between two integers,
 
1767
(that is, it has the form @i{integer}+1\over2),
 
1768
then the @i{quotient} has been rounded to the even (divisible by two) integer.
 
1769
 
 
1770
@end table
 
1771
 
 
1772
All of these functions perform type conversion operations on @i{numbers}.
 
1773
 
 
1774
The @i{remainder}
 
1775
is an @i{integer}  if both   @t{x} and @t{y} are @i{integers},
 
1776
is a  @i{rational} if both   @t{x} and @t{y} are @i{rationals}, and
 
1777
is a  @i{float}    if either @t{x} or  @t{y} is  a @i{float}.
 
1778
 
 
1779
@b{ffloor}, @b{fceiling}, @b{ftruncate}, and @b{fround} 
 
1780
handle arguments of different @i{types} in the following way:
 
1781
If  @i{number}  is     a @i{float},
 
1782
and @i{divisor} is not a @i{float} of longer format,
 
1783
then the first result is a @i{float} of the same @i{type} as @i{number}.
 
1784
Otherwise, the first result is of the @i{type} determined by @i{contagion} rules;
 
1785
see @ref{Contagion in Numeric Operations}.
 
1786
 
 
1787
@subsubheading  Examples::
 
1788
 
 
1789
@example
 
1790
 (floor 3/2) @result{}  1, 1/2
 
1791
 (ceiling 3 2) @result{}  2, -1
 
1792
 (ffloor 3 2) @result{}  1.0, 1
 
1793
 (ffloor -4.7) @result{}  -5.0, 0.3
 
1794
 (ffloor 3.5d0) @result{}  3.0d0, 0.5d0
 
1795
 (fceiling 3/2) @result{}  2.0, -1/2
 
1796
 (truncate 1) @result{}  1, 0
 
1797
 (truncate .5) @result{}  0, 0.5
 
1798
 (round .5) @result{}  0, 0.5
 
1799
 (ftruncate -7 2) @result{}  -3.0, -1
 
1800
 (fround -7 2) @result{}  -4.0, 1
 
1801
 (dolist (n '(2.6 2.5 2.4 0.7 0.3 -0.3 -0.7 -2.4 -2.5 -2.6))
 
1802
   (format t "~&~4,1@@F ~2,' D ~2,' D ~2,' D ~2,' D"
 
1803
           n (floor n) (ceiling n) (truncate n) (round n)))
 
1804
@t{ |> } +2.6  2  3  2  3
 
1805
@t{ |> } +2.5  2  3  2  2
 
1806
@t{ |> } +2.4  2  3  2  2
 
1807
@t{ |> } +0.7  0  1  0  1
 
1808
@t{ |> } +0.3  0  1  0  0
 
1809
@t{ |> } -0.3 -1  0  0  0
 
1810
@t{ |> } -0.7 -1  0  0 -1
 
1811
@t{ |> } -2.4 -3 -2 -2 -2
 
1812
@t{ |> } -2.5 -3 -2 -2 -2
 
1813
@t{ |> } -2.6 -3 -2 -2 -3
 
1814
@result{}  NIL
 
1815
@end example
 
1816
 
 
1817
@subsubheading  Notes::
 
1818
 
 
1819
When only @i{number} is given, the two results are exact;
 
1820
the mathematical sum of the two results is always equal to the
 
1821
mathematical value of @i{number}.
 
1822
 
 
1823
@t{(@i{function} @i{number} @i{divisor})}
 
1824
and @t{(@i{function} (/ @i{number} @i{divisor}))}
 
1825
(where @i{function} is any of one
 
1826
of @b{floor}, @b{ceiling}, @b{ffloor}, 
 
1827
@b{fceiling}, @b{truncate}, 
 
1828
@b{round}, @b{ftruncate}, and @b{fround})
 
1829
return the same first value, but
 
1830
they return different remainders as the second value. For example:
 
1831
 
 
1832
@example
 
1833
 (floor 5 2) @result{}  2, 1
 
1834
 (floor (/ 5 2)) @result{}  2, 1/2
 
1835
@end example
 
1836
 
 
1837
If an effect is desired that is similar to @b{round},
 
1838
but that always rounds up or down (rather than toward the nearest even integer) 
 
1839
if the mathematical quotient is exactly halfway between two integers, 
 
1840
the programmer should consider a construction such as
 
1841
    @t{(floor (+ x 1/2))}
 
1842
 or @t{(ceiling (- x 1/2))}.
 
1843
 
 
1844
@node sin, asin, floor, Numbers Dictionary
 
1845
@subsection sin, cos, tan                                                    [Function]
 
1846
 
 
1847
@code{sin}  @i{radians} @result{}  @i{number}
 
1848
 
 
1849
@code{cos}  @i{radians} @result{}  @i{number}
 
1850
 
 
1851
@code{tan}  @i{radians} @result{}  @i{number}
 
1852
 
 
1853
@subsubheading  Arguments and Values::
 
1854
 
 
1855
@i{radians}---a @i{number} given in radians.
 
1856
 
 
1857
@i{number}---a @i{number}.
 
1858
 
 
1859
@subsubheading  Description::
 
1860
 
 
1861
@b{sin}, @b{cos}, and @b{tan} 
 
1862
return the sine, cosine, and tangent, respectively, of @i{radians}.
 
1863
 
 
1864
@subsubheading  Examples::
 
1865
 
 
1866
@example
 
1867
 (sin 0) @result{}  0.0
 
1868
 (cos 0.7853982) @result{}  0.707107
 
1869
 (tan #c(0 1)) @result{}  #C(0.0 0.761594)
 
1870
@end example
 
1871
 
 
1872
@subsubheading  Exceptional Situations::
 
1873
 
 
1874
Should signal an error of @i{type} @b{type-error}
 
1875
                              if @i{radians} is not a @i{number}.
 
1876
Might signal @b{arithmetic-error}.
 
1877
 
 
1878
@subsubheading  See Also::
 
1879
 
 
1880
@ref{asin}
 
1881
,
 
1882
@b{acos},
 
1883
@b{atan},
 
1884
@ref{Rule of Float Substitutability}
 
1885
 
 
1886
@node asin, pi, sin, Numbers Dictionary
 
1887
@subsection asin, acos, atan                                                 [Function]
 
1888
 
 
1889
@code{asin}  @i{number} @result{}  @i{radians}
 
1890
 
 
1891
@code{acos}  @i{number} @result{}  @i{radians}
 
1892
 
 
1893
@code{atan}  @i{number1 @r{&optional} number2} @result{}  @i{radians}
 
1894
 
 
1895
@subsubheading  Arguments and Values::
 
1896
 
 
1897
@i{number}---a @i{number}.
 
1898
 
 
1899
@i{number1}---a @i{number} if @i{number2} is not supplied,
 
1900
               or a @i{real}   if @i{number2} is     supplied.
 
1901
 
 
1902
@i{number2}---a @i{real}.
 
1903
 
 
1904
@i{radians}---a @i{number} (of radians).
 
1905
 
 
1906
@subsubheading  Description::
 
1907
 
 
1908
@b{asin}, @b{acos}, and @b{atan}
 
1909
compute the arc sine, arc cosine, and arc tangent respectively.
 
1910
 
 
1911
The arc sine, arc cosine, and arc tangent (with only @i{number1} supplied)
 
1912
functions can be defined mathematically for
 
1913
@i{number} or @i{number1} specified as @i{x} as in Figure 12--13.
 
1914
 
 
1915
@format
 
1916
@group
 
1917
@noindent
 
1918
@w{  Function     Definition                            }
 
1919
@w{  Arc sine      -i @t{log}  (ix+ \sqrt@r{1-x^2} )          }
 
1920
@w{  Arc cosine    (\pi/2) - @t{arcsin}  x                  }
 
1921
@w{  Arc tangent   -i @t{log}  ((1+ix) \sqrt@r{1/(1+x^2)} )   }
 
1922
 
 
1923
@noindent
 
1924
@w{  Figure 12--13: Mathematical definition of arc sine, arc cosine, and arc tangent}
 
1925
 
 
1926
@end group
 
1927
@end format
 
1928
 
 
1929
These formulae are mathematically correct, assuming
 
1930
completely accurate computation. They are not necessarily
 
1931
the simplest ones for real-valued computations. 
 
1932
 
 
1933
If both @i{number1} and @i{number2} are supplied
 
1934
for @b{atan}, the result is the arc tangent 
 
1935
of @i{number1}/@i{number2}.
 
1936
The value of @b{atan} is always between
 
1937
-\pi (exclusive) and~\pi (inclusive)
 
1938
 
 
1939
 when minus zero is not supported.
 
1940
The range of the two-argument arc tangent when minus zero is supported
 
1941
includes -\pi.
 
1942
 
 
1943
For a 
 
1944
 
 
1945
@i{real}
 
1946
 
 
1947
@i{number1}, 
 
1948
the result is 
 
1949
 
 
1950
a @i{real}
 
1951
 
 
1952
and lies between
 
1953
-\pi/2 and~\pi/2 (both exclusive).
 
1954
@i{number1} can be a @i{complex} if @i{number2}
 
1955
is not supplied. If both are supplied, @i{number2} can be zero provided
 
1956
@i{number1} is not zero.  
 
1957
 
 
1958
[Reviewer Note by Barmar: Should add ``However, if the implementation distinguishes 
 
1959
                  positive and negative zero, both may be signed zeros, 
 
1960
                  and limits are used to define the result.'']
 
1961
 
 
1962
The following definition for arc sine determines the range and
 
1963
branch cuts:
 
1964
 
 
1965
@center  @t{arcsin}  z = -i @t{log}  (iz+\sqrt@r{1-z^2}\Bigr) 
 
1966
 
 
1967
The branch cut for the arc sine function is in two pieces:
 
1968
one along the negative real axis to the left of~-1
 
1969
(inclusive), continuous with quadrant II, and one along the positive real
 
1970
axis to the right of~1 (inclusive), continuous with quadrant IV.  The
 
1971
range is that strip of the complex plane containing numbers whose real
 
1972
part is between -\pi/2 and~\pi/2.  A number with real
 
1973
part equal to -\pi/2 is in the range if and only if its imaginary
 
1974
part is non-negative; a number with real part equal to \pi/2 is in
 
1975
the range if and only if its imaginary part is non-positive.
 
1976
 
 
1977
The following definition for arc cosine determines the range and
 
1978
branch cuts:
 
1979
 
 
1980
@center  @t{arccos}  z = \pi\over2 - @t{arcsin}  z
 
1981
 
 
1982
or, which are equivalent,
 
1983
 
 
1984
@center  @t{arccos}  z = -i @t{log}  (z+i \sqrt@r{1-z^2}\Bigr) 
 
1985
 
 
1986
@center  @t{arccos}  z = @t{2 @t{log}  (\sqrt@r{(1+z)/2} + i \sqrt@r{(1-z)/2})}\over@r{i}
 
1987
 
 
1988
The branch cut for the arc cosine function is in two pieces:
 
1989
one along the negative real axis to the left of~-1
 
1990
(inclusive), continuous with quadrant II, and one along the positive real
 
1991
axis to the right of~1 (inclusive), continuous with quadrant IV.  
 
1992
This is the same branch cut as for arc sine.
 
1993
The range is that strip of the complex plane containing numbers whose real
 
1994
part is between 0 and~\pi.  A number with real
 
1995
part equal to 0 is in the range if and only if its imaginary
 
1996
part is non-negative; a number with real part equal to \pi is in
 
1997
the range if and only if its imaginary part is non-positive.
 
1998
 
 
1999
The following definition for (one-argument) arc tangent determines the
 
2000
range and branch cuts:
 
2001
 
 
2002
@center  @t{arctan}  z = @i{@i{@t{log}  (1+iz) - @t{log}  (1-iz)}\over@i{2i}} 
 
2003
 
 
2004
Beware of simplifying this formula; ``obvious'' simplifications are likely
 
2005
to alter the branch cuts or the values on the branch cuts incorrectly.
 
2006
The branch cut for the arc tangent function is in two pieces:
 
2007
one along the positive imaginary axis above i
 
2008
(exclusive), continuous with quadrant II, and one along the negative imaginary
 
2009
axis below -i (exclusive), continuous with quadrant IV.  
 
2010
The points i and~-i are excluded from the domain.
 
2011
The range is that strip of the complex plane containing numbers whose real
 
2012
part is between -\pi/2 and~\pi/2.  A number with real
 
2013
part equal to -\pi/2 is in the range if and only if its imaginary
 
2014
part is strictly positive; a number with real part equal to \pi/2 is in
 
2015
the range if and only if its imaginary part is strictly negative.  Thus the range of
 
2016
arc tangent is identical to that of arc sine with the points
 
2017
-\pi/2 and~\pi/2 excluded.
 
2018
 
 
2019
For @b{atan},
 
2020
the signs of @i{number1} (indicated as @i{x})
 
2021
and @i{number2} (indicated as @i{y}) are used to derive quadrant
 
2022
information. Figure 12--14 details various special cases.
 
2023
 
 
2024
The asterisk (*) indicates that the entry in the figure applies to
 
2025
implementations that support minus zero.
 
2026
 
 
2027
@format
 
2028
@group
 
2029
@noindent
 
2030
@w{   to 1pc@r{}@i{y} Condition  @i{x} Condition  Cartesian locus  Range of result          }
 
2031
@w{   to 1pc@r{} y = 0        x > 0       Positive x-axis   0                       }
 
2032
@w{   to 1pc* y = +0      x > 0       Positive x-axis  +0                       }
 
2033
@w{   to 1pc* y = -0      x > 0       Positive x-axis  -0                       }
 
2034
@w{   to 1pc@r{} y > 0        x > 0       Quadrant I       0 < result < \pi/2      }
 
2035
@w{   to 1pc@r{} y > 0        x = 0       Positive y-axis  \pi/2                    }
 
2036
@w{   to 1pc@r{} y > 0        x < 0       Quadrant II      \pi/2 < result < \pi    }
 
2037
@w{   to 1pc@r{} y = 0        x < 0       Negative x-axis   \pi                     }
 
2038
@w{   to 1pc* y = +0      x < 0       Negative x-axis  +\pi                     }
 
2039
@w{   to 1pc* y = -0      x < 0       Negative x-axis  -\pi                     }
 
2040
@w{   to 1pc@r{} y < 0        x < 0       Quadrant III     -\pi < result < -\pi/2  }
 
2041
@w{   to 1pc@r{} y < 0        x = 0       Negative y-axis  -\pi/2                   }
 
2042
@w{   to 1pc@r{} y < 0        x > 0       Quadrant IV      -\pi/2 < result < 0     }
 
2043
@w{   to 1pc@r{} y = 0        x = 0       Origin           undefined consequences   }
 
2044
@w{   to 1pc* y = +0      x = +0      Origin           +0                       }
 
2045
@w{   to 1pc* y = -0      x = +0      Origin           -0                       }
 
2046
@w{   to 1pc* y = +0      x = -0      Origin           +\pi                     }
 
2047
@w{   to 1pc* y = -0      x = -0      Origin           -\pi                     }
 
2048
 
 
2049
@noindent
 
2050
@w{               Figure 12--14: Quadrant information for arc tangent             }
 
2051
 
 
2052
@end group
 
2053
@end format
 
2054
 
 
2055
@subsubheading  Examples::
 
2056
 
 
2057
@example
 
2058
 (asin 0) @result{}  0.0 
 
2059
 (acos #c(0 1))  @result{}  #C(1.5707963267948966 -0.8813735870195432)
 
2060
 (/ (atan 1 (sqrt 3)) 6)  @result{}  0.087266 
 
2061
 (atan #c(0 2)) @result{}  #C(-1.5707964 0.54930615)
 
2062
@end example
 
2063
 
 
2064
@subsubheading  Exceptional Situations::
 
2065
 
 
2066
@b{acos} and @b{asin} should signal an error of @i{type} @b{type-error}
 
2067
                           if @i{number} is not a @i{number}.
 
2068
@b{atan} should signal @b{type-error} if
 
2069
  one argument is supplied and that argument is not a @i{number},
 
2070
  or if two arguments are supplied and both of those arguments are not @i{reals}.
 
2071
 
 
2072
@b{acos}, @b{asin}, and @b{atan} might signal @b{arithmetic-error}.
 
2073
 
 
2074
@subsubheading  See Also::
 
2075
 
 
2076
@ref{log}
 
2077
,
 
2078
@ref{sqrt}
 
2079
,
 
2080
@ref{Rule of Float Substitutability}
 
2081
 
 
2082
@subsubheading  Notes::
 
2083
 
 
2084
The result of either @b{asin} or @b{acos} can be a @i{complex}
 
2085
even if @i{number} is not a @i{complex}; this occurs when the 
 
2086
absolute value of @i{number} is greater than one.
 
2087
 
 
2088
@node pi, sinh, asin, Numbers Dictionary
 
2089
@subsection pi                                                      [Constant Variable]
 
2090
 
 
2091
@subsubheading  Value:: 
 
2092
 
 
2093
an @i{implementation-dependent} @i{long float}.
 
2094
 
 
2095
@subsubheading  Description::
 
2096
 
 
2097
The best @i{long float} approximation to the mathematical constant \pi.
 
2098
 
 
2099
@subsubheading  Examples::
 
2100
 
 
2101
@example
 
2102
 ;; In each of the following computations, the precision depends 
 
2103
 ;; on the implementation.  Also, if `long float' is treated by 
 
2104
 ;; the implementation as equivalent to some other float format 
 
2105
 ;; (e.g., `double float') the exponent marker might be the marker
 
2106
 ;; for that equivalent (e.g., `D' instead of `L').
 
2107
 pi @result{}  3.141592653589793L0
 
2108
 (cos pi) @result{}  -1.0L0
 
2109
 
 
2110
 (defun sin-of-degrees (degrees)
 
2111
   (let ((x (if (floatp degrees) degrees (float degrees pi))))
 
2112
     (sin (* x (/ (float pi x) 180)))))
 
2113
@end example
 
2114
 
 
2115
@subsubheading  Notes::
 
2116
 
 
2117
An approximation to \pi in some other precision can be obtained
 
2118
by writing @t{(float pi x)}, where @t{x} is a @i{float} of the
 
2119
desired precision, or by writing @t{(coerce pi @i{type})}, 
 
2120
where @i{type} is the desired type, such as @b{short-float}.
 
2121
 
 
2122
@node sinh, *, pi, Numbers Dictionary
 
2123
@subsection sinh, cosh, tanh, asinh, acosh, atanh                            [Function]
 
2124
 
 
2125
@code{sinh}  @i{number} @result{}  @i{result}
 
2126
 
 
2127
@code{cosh}  @i{number} @result{}  @i{result}
 
2128
 
 
2129
@code{tanh}  @i{number} @result{}  @i{result}
 
2130
 
 
2131
@code{asinh}  @i{number} @result{}  @i{result}
 
2132
 
 
2133
@code{acosh}  @i{number} @result{}  @i{result}
 
2134
 
 
2135
@code{atanh}  @i{number} @result{}  @i{result}
 
2136
 
 
2137
@subsubheading  Arguments and Values:: 
 
2138
 
 
2139
@i{number}---a @i{number}.
 
2140
 
 
2141
@i{result}---a @i{number}.
 
2142
 
 
2143
@subsubheading  Description::
 
2144
 
 
2145
These functions compute the hyperbolic sine, cosine, tangent,
 
2146
arc sine, arc cosine, and arc tangent functions, 
 
2147
which are mathematically defined for an argument @i{x}
 
2148
as given in Figure 12--15.
 
2149
 
 
2150
@format
 
2151
@group
 
2152
@noindent
 
2153
@w{  Function                Definition                                  }
 
2154
@w{  Hyperbolic sine          (e^x-e^@i{-x})/2                             }
 
2155
@w{  Hyperbolic cosine        (e^x+e^@i{-x})/2                             }
 
2156
@w{  Hyperbolic tangent       (e^x-e^@i{-x})/(e^x+e^@i{-x})                  }
 
2157
@w{  Hyperbolic arc sine      @t{log}  (x+\sqrt@i{1+x^2})                      }
 
2158
@w{  Hyperbolic arc cosine    2 @t{log}  (\sqrt@i{(x+1)/2} + \sqrt@i{(x-1)/2})   }
 
2159
@w{  Hyperbolic arc tangent   (@t{log}  (1+x) - @t{log} (1-x))/2                 }
 
2160
 
 
2161
@noindent
 
2162
@w{    Figure 12--15: Mathematical definitions for hyperbolic functions  }
 
2163
 
 
2164
@end group
 
2165
@end format
 
2166
 
 
2167
The following definition for the inverse hyperbolic cosine
 
2168
determines the range and branch cuts:
 
2169
 
 
2170
@center  @t{arccosh}  z = 2 @t{log}  (\sqrt@i{(z+1)/2} + \sqrt@i{(z-1)/2}\Bigr). 
 
2171
 
 
2172
The branch cut for the inverse hyperbolic cosine function
 
2173
lies along the real axis to the left of~1 (inclusive), extending
 
2174
indefinitely along the negative real axis, continuous with quadrant II
 
2175
and (between 0 and~1) with quadrant I.
 
2176
The range is that half-strip of the complex plane containing numbers whose
 
2177
real part is non-negative and whose imaginary
 
2178
part is between -\pi (exclusive) and~\pi (inclusive).
 
2179
A number with real part zero is in the range 
 
2180
if its imaginary part is between zero (inclusive) and~\pi (inclusive).
 
2181
 
 
2182
The following definition for the inverse hyperbolic sine determines
 
2183
the range and branch cuts:
 
2184
 
 
2185
@center  @t{arcsinh}  z = @t{log}  (z+\sqrt@i{1+z^2}\Bigr). 
 
2186
 
 
2187
The branch cut for the inverse hyperbolic sine function is in two pieces:
 
2188
one along the positive imaginary axis above i
 
2189
(inclusive), continuous with quadrant I, and one along the negative imaginary
 
2190
axis below -i (inclusive), continuous with quadrant III.
 
2191
The range is that strip of the complex plane containing numbers whose imaginary
 
2192
part is between -\pi/2 and~\pi/2.  A number with imaginary
 
2193
part equal to -\pi/2 is in the range if and only if its real
 
2194
part is non-positive; a number with imaginary part equal to \pi/2 is in
 
2195
the range if and only if its imaginary part is non-negative.
 
2196
 
 
2197
The following definition for the inverse hyperbolic tangent
 
2198
determines the range and branch cuts:
 
2199
 
 
2200
@center  @t{arctanh}  z = @i{@i{@t{log}  (1+z) - @t{log}  (1-z)}\over@r{2}}. 
 
2201
 
 
2202
Note that:
 
2203
 
 
2204
@center  i @t{arctan}  z = @t{arctanh}  iz. 
 
2205
 
 
2206
The branch cut for the inverse hyperbolic tangent function
 
2207
is in two pieces: one along the negative real axis to the left of
 
2208
-1 (inclusive), continuous with quadrant III, and one along
 
2209
the positive real axis to the right of~1 (inclusive), continuous with
 
2210
quadrant I.  The points -1 and~1 are excluded from the
 
2211
domain.
 
2212
The range is that strip of the complex plane containing
 
2213
numbers whose imaginary part is between -\pi/2 and
 
2214
\pi/2.  A number with imaginary part equal to -\pi/2
 
2215
is in the range if and only if its real part is strictly negative; a number with
 
2216
imaginary part equal to \pi/2 is in the range if and only if its imaginary
 
2217
part is strictly positive.  
 
2218
Thus the range of the inverse hyperbolic tangent function is identical to
 
2219
that of the inverse hyperbolic sine function with the points
 
2220
-\pi i/2 and~\pi i/2 excluded.
 
2221
 
 
2222
@subsubheading  Examples::
 
2223
 
 
2224
@example
 
2225
 (sinh 0) @result{}  0.0 
 
2226
 (cosh (complex 0 -1)) @result{}  #C(0.540302 -0.0)
 
2227
@end example
 
2228
 
 
2229
@subsubheading  Exceptional Situations::
 
2230
 
 
2231
Should signal an error of @i{type} @b{type-error}
 
2232
                              if @i{number} is not a @i{number}.
 
2233
Might signal @b{arithmetic-error}.
 
2234
 
 
2235
@subsubheading  See Also::
 
2236
 
 
2237
@ref{log}
 
2238
,
 
2239
@ref{sqrt}
 
2240
,
 
2241
@ref{Rule of Float Substitutability}
 
2242
 
 
2243
@subsubheading  Notes::
 
2244
 
 
2245
The result of @b{acosh} may be a @i{complex} even if @i{number} 
 
2246
is not a @i{complex}; this occurs when @i{number} is less than one.
 
2247
Also, the result of @b{atanh} may be a @i{complex} even if @i{number} 
 
2248
is not a @i{complex}; this occurs when the absolute value of @i{number} 
 
2249
is greater than one.
 
2250
 
 
2251
The branch cut formulae are mathematically correct, assuming
 
2252
completely accurate computation.  
 
2253
Implementors should consult a good text on
 
2254
numerical analysis.  The formulae given above are not necessarily
 
2255
the simplest ones for real-valued computations; they are chosen
 
2256
to define the branch cuts in desirable ways for the complex case.
 
2257
 
 
2258
@node *, +, sinh, Numbers Dictionary
 
2259
@subsection *                                                                [Function]
 
2260
 
 
2261
@code{*}  @i{@r{&rest} numbers} @result{}  @i{product}
 
2262
 
 
2263
@subsubheading  Arguments and Values::
 
2264
 
 
2265
@i{number}---a @i{number}.
 
2266
 
 
2267
@i{product}---a @i{number}.
 
2268
 
 
2269
@subsubheading  Description::
 
2270
 
 
2271
Returns the product of @i{numbers},
 
2272
performing any necessary type conversions in the process.
 
2273
If no @i{numbers} are supplied, @t{1} is returned.
 
2274
 
 
2275
@subsubheading  Examples::
 
2276
 
 
2277
@example
 
2278
 (*) @result{}  1
 
2279
 (* 3 5) @result{}  15
 
2280
 (* 1.0 #c(22 33) 55/98) @result{}  #C(12.346938775510203 18.520408163265305)
 
2281
@end example
 
2282
 
 
2283
@subsubheading  Exceptional Situations::
 
2284
 
 
2285
Might signal @b{type-error} if some @i{argument} is not a @i{number}.
 
2286
Might signal @b{arithmetic-error}.
 
2287
 
 
2288
@subsubheading  See Also::
 
2289
 
 
2290
@ref{Numeric Operations},
 
2291
@ref{Rational Computations},
 
2292
@ref{Floating-point Computations},
 
2293
@ref{Complex Computations}
 
2294
 
 
2295
@node +, -, *, Numbers Dictionary
 
2296
@subsection +                                                                [Function]
 
2297
 
 
2298
@code{+}  @i{@r{&rest} numbers} @result{}  @i{sum}
 
2299
 
 
2300
@subsubheading  Arguments and Values::
 
2301
 
 
2302
@i{number}---a @i{number}.
 
2303
 
 
2304
@i{sum}---a @i{number}.
 
2305
 
 
2306
@subsubheading  Description::
 
2307
 
 
2308
Returns the sum of @i{numbers},
 
2309
performing any necessary type conversions in the process.
 
2310
If no @i{numbers} are supplied, @t{0} is returned.
 
2311
 
 
2312
@subsubheading  Examples::
 
2313
@example
 
2314
 (+) @result{}  0
 
2315
 (+ 1) @result{}  1
 
2316
 (+ 31/100 69/100) @result{}  1
 
2317
 (+ 1/5 0.8) @result{}  1.0
 
2318
@end example
 
2319
 
 
2320
@subsubheading  Exceptional Situations::
 
2321
 
 
2322
Might signal @b{type-error} if some @i{argument} is not a @i{number}.
 
2323
Might signal @b{arithmetic-error}.
 
2324
 
 
2325
@subsubheading  See Also::
 
2326
 
 
2327
@ref{Numeric Operations},
 
2328
@ref{Rational Computations},
 
2329
@ref{Floating-point Computations},
 
2330
@ref{Complex Computations}
 
2331
 
 
2332
@node -, /, +, Numbers Dictionary
 
2333
@subsection -                                                              [Function]
 
2334
 
 
2335
@code{-}  @i{number} @result{}  @i{negation}
 
2336
 
 
2337
@code{-}  @i{minuend @r{&rest} subtrahends^+} @result{}  @i{difference}
 
2338
 
 
2339
@subsubheading  Arguments and Values::
 
2340
 
 
2341
@i{number}, @i{minuend}, @i{subtrahend}---a @i{number}.
 
2342
 
 
2343
@i{negation}, @i{difference}---a @i{number}.
 
2344
 
 
2345
@subsubheading  Description::
 
2346
 
 
2347
The @i{function} @b{-} performs arithmetic subtraction and negation.
 
2348
 
 
2349
If only one @i{number} is supplied,
 
2350
the negation of that @i{number} is returned.
 
2351
 
 
2352
If more than one @i{argument} is given, 
 
2353
it subtracts all of the @i{subtrahends} from the @i{minuend}
 
2354
and returns the result.
 
2355
 
 
2356
The @i{function} @b{-} performs necessary type conversions. 
 
2357
 
 
2358
@subsubheading  Examples::
 
2359
 
 
2360
@example
 
2361
 (- 55.55) @result{}  -55.55
 
2362
 (- #c(3 -5)) @result{}  #C(-3 5)
 
2363
 (- 0) @result{}  0
 
2364
 (eql (- 0.0) -0.0) @result{}  @i{true}
 
2365
 (- #c(100 45) #c(0 45)) @result{}  100
 
2366
 (- 10 1 2 3 4) @result{}  0
 
2367
@end example
 
2368
 
 
2369
@subsubheading  Exceptional Situations::
 
2370
 
 
2371
Might signal @b{type-error} if some @i{argument} is not a @i{number}.
 
2372
Might signal @b{arithmetic-error}.
 
2373
 
 
2374
@subsubheading  See Also::
 
2375
 
 
2376
@ref{Numeric Operations},
 
2377
@ref{Rational Computations},
 
2378
@ref{Floating-point Computations},
 
2379
@ref{Complex Computations}
 
2380
 
 
2381
@node /, 1+, -, Numbers Dictionary
 
2382
@subsection /                                                                [Function]
 
2383
 
 
2384
@code{/}  @i{number} @result{}  @i{reciprocal}
 
2385
 
 
2386
@code{/}  @i{numerator @r{&rest} denominators^+} @result{}  @i{quotient}
 
2387
 
 
2388
@subsubheading  Arguments and Values::
 
2389
 
 
2390
@i{number}, @i{denominator}---a non-zero @i{number}.
 
2391
 
 
2392
@i{numerator}, @i{quotient}, @i{reciprocal}---a @i{number}.
 
2393
 
 
2394
@subsubheading  Description::
 
2395
 
 
2396
The @i{function} @b{/} performs division or reciprocation.
 
2397
 
 
2398
If no @i{denominators} are supplied,
 
2399
the @i{function} @b{/} returns the reciprocal of @i{number}.
 
2400
 
 
2401
If at least one @i{denominator} is supplied,
 
2402
the @i{function} @b{/} divides the @i{numerator} by all of the @i{denominators} 
 
2403
and returns the resulting @i{quotient}.
 
2404
 
 
2405
If each @i{argument} is either an @i{integer} or a @i{ratio},
 
2406
and the result is not an @i{integer}, then it is a @i{ratio}.
 
2407
 
 
2408
The @i{function} @b{/} performs necessary type conversions.
 
2409
 
 
2410
If any @i{argument} is a @i{float} then 
 
2411
the rules of floating-point contagion apply;
 
2412
see @ref{Floating-point Computations}.
 
2413
 
 
2414
@subsubheading  Examples::
 
2415
 
 
2416
@example
 
2417
 (/ 12 4) @result{}  3
 
2418
 (/ 13 4) @result{}  13/4
 
2419
 (/ -8) @result{}  -1/8
 
2420
 (/ 3 4 5) @result{}  3/20
 
2421
 (/ 0.5) @result{}  2.0
 
2422
 (/ 20 5) @result{}  4
 
2423
 (/ 5 20) @result{}  1/4
 
2424
 (/ 60 -2 3 5.0) @result{}  -2.0
 
2425
 (/ 2 #c(2 2)) @result{}  #C(1/2 -1/2)
 
2426
@end example
 
2427
 
 
2428
@subsubheading  Exceptional Situations::
 
2429
 
 
2430
The consequences are unspecified if any @i{argument} other than the first is zero.
 
2431
If there is only one @i{argument}, the consequences are unspecified if it is zero.
 
2432
 
 
2433
Might signal @b{type-error} if some @i{argument} is not a @i{number}.
 
2434
Might signal @b{division-by-zero} if division by zero is attempted.
 
2435
Might signal @b{arithmetic-error}.
 
2436
 
 
2437
@subsubheading  See Also::
 
2438
 
 
2439
@ref{floor}
 
2440
, @b{ceiling}, @b{truncate}, @b{round}
 
2441
 
 
2442
@node 1+, abs, /, Numbers Dictionary
 
2443
@subsection 1+, 1-                                                         [Function]
 
2444
 
 
2445
@code{1}  @i{+} @result{}  @i{number}
 
2446
 @r{successor}
 
2447
@code{1}  @i{-} @result{}  @i{number}
 
2448
 @r{predecessor}
 
2449
 
 
2450
@subsubheading  Arguments and Values:: 
 
2451
 
 
2452
@i{number}---a @i{number}.
 
2453
 
 
2454
@i{successor}, @i{predecessor}---a @i{number}.
 
2455
 
 
2456
@subsubheading  Description::
 
2457
 
 
2458
@b{1+} returns a @i{number} that is one more than its argument @i{number}.
 
2459
@b{1-} returns a @i{number} that is one less than its argument @i{number}.
 
2460
 
 
2461
@subsubheading  Examples::
 
2462
 
 
2463
@example
 
2464
 (1+ 99) @result{}  100 
 
2465
 (1- 100) @result{}  99 
 
2466
 (1+ (complex 0.0)) @result{}  #C(1.0 0.0) 
 
2467
 (1- 5/3) @result{}  2/3 
 
2468
@end example
 
2469
 
 
2470
@subsubheading  Exceptional Situations::
 
2471
 
 
2472
Might signal @b{type-error} if its @i{argument} is not a @i{number}.
 
2473
Might signal @b{arithmetic-error}.
 
2474
 
 
2475
@subsubheading  See Also::
 
2476
 
 
2477
@ref{incf}
 
2478
, @b{decf}
 
2479
 
 
2480
@subsubheading  Notes::
 
2481
 
 
2482
@example
 
2483
 (1+ @i{number}) @equiv{} (+ @i{number} 1)
 
2484
 (1- @i{number}) @equiv{} (- @i{number} 1)
 
2485
@end example
 
2486
 
 
2487
Implementors are encouraged to make the performance of both the previous
 
2488
expressions be the same.
 
2489
 
 
2490
@node abs, evenp, 1+, Numbers Dictionary
 
2491
@subsection abs                                                              [Function]
 
2492
 
 
2493
@code{abs}  @i{number} @result{}  @i{absolute-value}
 
2494
 
 
2495
@subsubheading  Arguments and Values::
 
2496
 
 
2497
@i{number}---a @i{number}.
 
2498
 
 
2499
@i{absolute-value}---a non-negative @i{real}.
 
2500
 
 
2501
@subsubheading  Description::
 
2502
 
 
2503
@b{abs} returns the absolute value of @i{number}.
 
2504
 
 
2505
If @i{number} is 
 
2506
 
 
2507
a @i{real},
 
2508
 
 
2509
the result is  of the same @i{type} as @i{number}.
 
2510
 
 
2511
If @i{number} is a @i{complex}, 
 
2512
the result is a positive 
 
2513
 
 
2514
@i{real}
 
2515
 
 
2516
with
 
2517
the same magnitude as @i{number}.  
 
2518
The result can be a @i{float} 
 
2519
 
 
2520
[Reviewer Note by Barmar: Single-float.]
 
2521
even if @i{number}'s components are @i{rationals} 
 
2522
and an exact rational result
 
2523
would have been possible.
 
2524
Thus the result of @t{(abs #c(3 4))} can be either @t{5} or @t{5.0},
 
2525
depending on the implementation.
 
2526
 
 
2527
@subsubheading  Examples::
 
2528
 
 
2529
@example
 
2530
 (abs 0) @result{}  0
 
2531
 (abs 12/13) @result{}  12/13
 
2532
 (abs -1.09) @result{}  1.09
 
2533
 (abs #c(5.0 -5.0)) @result{}  7.071068
 
2534
 (abs #c(5 5)) @result{}  7.071068
 
2535
 (abs #c(3/5 4/5)) @result{}  1 or approximately 1.0
 
2536
 (eql (abs -0.0) -0.0) @result{}  @i{true}
 
2537
@end example
 
2538
 
 
2539
@subsubheading  See Also::
 
2540
 
 
2541
@ref{Rule of Float Substitutability}
 
2542
 
 
2543
@subsubheading  Notes::
 
2544
 
 
2545
If @i{number} is a @i{complex}, 
 
2546
the result is equivalent to the following: 
 
2547
 
 
2548
@t{(sqrt (+ (expt (realpart @i{number}) 2)  (expt (imagpart @i{number}) 2)))}
 
2549
 
 
2550
An implementation should not use this formula directly
 
2551
for all @i{complexes}
 
2552
but should handle very large or very small components specially
 
2553
to avoid intermediate overflow or underflow.
 
2554
 
 
2555
@node evenp, exp, abs, Numbers Dictionary
 
2556
@subsection evenp, oddp                                                      [Function]
 
2557
 
 
2558
@code{evenp}  @i{integer} @result{}  @i{generalized-boolean}
 
2559
 
 
2560
@code{oddp}  @i{integer} @result{}  @i{generalized-boolean}
 
2561
 
 
2562
@subsubheading  Arguments and Values::
 
2563
 
 
2564
@i{integer}---an @i{integer}.
 
2565
 
 
2566
@i{generalized-boolean}---a @i{generalized boolean}.
 
2567
 
 
2568
@subsubheading  Description::
 
2569
 
 
2570
@b{evenp} returns @i{true} if @i{integer} is even (divisible by two);
 
2571
otherwise, returns @i{false}.
 
2572
 
 
2573
@b{oddp} returns @i{true} if @i{integer} is odd (not divisible by two);
 
2574
otherwise, returns @i{false}.
 
2575
 
 
2576
@subsubheading  Examples::
 
2577
 
 
2578
@example
 
2579
 (evenp 0) @result{}  @i{true}
 
2580
 (oddp 10000000000000000000000) @result{}  @i{false}
 
2581
 (oddp -1) @result{}  @i{true}
 
2582
@end example
 
2583
 
 
2584
@subsubheading  Exceptional Situations::
 
2585
 
 
2586
Should signal an error of @i{type} @b{type-error}
 
2587
                              if @i{integer} is not an @i{integer}.
 
2588
 
 
2589
@subsubheading  Notes::
 
2590
 
 
2591
@example
 
2592
 (evenp @i{integer}) @equiv{} (not (oddp @i{integer}))
 
2593
 (oddp @i{integer})  @equiv{} (not (evenp @i{integer}))
 
2594
@end example
 
2595
 
 
2596
@node exp, gcd, evenp, Numbers Dictionary
 
2597
@subsection exp, expt                                                        [Function]
 
2598
 
 
2599
@code{exp}  @i{number} @result{}  @i{result}
 
2600
 
 
2601
@code{expt}  @i{base-number power-number} @result{}  @i{result}
 
2602
 
 
2603
@subsubheading  Arguments and Values::
 
2604
 
 
2605
@i{number}---a @i{number}.
 
2606
 
 
2607
@i{base-number}---a @i{number}.
 
2608
 
 
2609
@i{power-number}---a @i{number}.
 
2610
 
 
2611
@i{result}---a @i{number}.
 
2612
 
 
2613
@subsubheading  Description::
 
2614
 
 
2615
@b{exp} and @b{expt} perform exponentiation.
 
2616
 
 
2617
@b{exp} returns @i{e} raised to the power @i{number},
 
2618
where @i{e} is the base of the natural logarithms.
 
2619
@b{exp} has no branch cut.
 
2620
 
 
2621
@b{expt} returns @i{base-number} 
 
2622
raised to the power @i{power-number}.
 
2623
If the @i{base-number} is a @i{rational} 
 
2624
and @i{power-number} is
 
2625
an @i{integer},
 
2626
the calculation is exact and the result will be of @i{type} @b{rational};
 
2627
otherwise a floating-point approximation might result.
 
2628
 
 
2629
For @b{expt} of a @i{complex rational} to an @i{integer} power,
 
2630
the calculation must be exact and the result is
 
2631
of type @t{(or rational (complex rational))}.
 
2632
 
 
2633
The result of @b{expt} can be a @i{complex},
 
2634
even when neither argument is a @i{complex},
 
2635
if @i{base-number} is negative and @i{power-number}
 
2636
is not an @i{integer}. 
 
2637
The result is always the @i{principal} @i{complex} @i{value}.
 
2638
For example, @t{(expt -8 1/3)} is not permitted to return @t{-2},
 
2639
even though @t{-2} is one of the cube roots of @t{-8}. 
 
2640
The @i{principal} cube root is a @i{complex}
 
2641
approximately equal to @t{#C(1.0 1.73205)}, not @t{-2}.
 
2642
 
 
2643
@b{expt} is defined
 
2644
as @i{b^x = e^@i{x log b\/}}.
 
2645
This defines the @i{principal} @i{values} precisely.  The range of
 
2646
@b{expt} is the entire complex plane.  Regarded
 
2647
as a function of @i{x}, with @i{b} fixed, there is no branch cut.
 
2648
Regarded as a function of @i{b}, with @i{x} fixed, there is in general
 
2649
a branch cut along the negative real axis, continuous with quadrant II.
 
2650
The domain excludes the origin.
 
2651
By definition, 0^0=1.  If @i{b}=0 and the real part of @i{x} is strictly
 
2652
positive, then 
 
2653
@i{b^x}=0. For all other values of @i{x}, 0^@i{x} 
 
2654
is an error.
 
2655
 
 
2656
When @i{power-number} is an @i{integer} @t{0},
 
2657
then the result is always the value one in the @i{type} 
 
2658
of @i{base-number},
 
2659
even if the @i{base-number} is zero (of any @i{type}).  That is:
 
2660
 
 
2661
@example
 
2662
 (expt x 0) @equiv{} (coerce 1 (type-of x))
 
2663
@end example
 
2664
 
 
2665
If @i{power-number} is a zero of any other @i{type},
 
2666
then the result is also the value one, in the @i{type} of the arguments
 
2667
after the application of the contagion rules in @ref{Contagion in Numeric Operations},
 
2668
with one exception:
 
2669
the consequences are undefined if @i{base-number} is zero when @i{power-number}
 
2670
is zero and not of @i{type} @b{integer}.
 
2671
 
 
2672
@subsubheading  Examples::
 
2673
 
 
2674
@example
 
2675
 (exp 0) @result{}  1.0
 
2676
 (exp 1) @result{}  2.718282
 
2677
 (exp (log 5)) @result{}  5.0 
 
2678
 (expt 2 8) @result{}  256
 
2679
 (expt 4 .5) @result{}  2.0
 
2680
 (expt #c(0 1) 2) @result{}  -1
 
2681
 (expt #c(2 2) 3) @result{}  #C(-16 16)
 
2682
 (expt #c(2 2) 4) @result{}  -64 
 
2683
@end example
 
2684
 
 
2685
@subsubheading  See Also::
 
2686
 
 
2687
@ref{log}
 
2688
,
 
2689
@ref{Rule of Float Substitutability}
 
2690
 
 
2691
@subsubheading  Notes::
 
2692
 
 
2693
Implementations of @b{expt} are permitted to use different algorithms
 
2694
for the cases of a @i{power-number} of @i{type} @b{rational} 
 
2695
             and a @i{power-number} of @i{type} @b{float}.
 
2696
 
 
2697
  Note that by the following logic, 
 
2698
@t{(sqrt (expt @i{x} 3))} is not equivalent to 
 
2699
@t{(expt @i{x} 3/2)}.
 
2700
 
 
2701
@example
 
2702
 (setq x (exp (/ (* 2 pi #c(0 1)) 3)))         ;exp(2.pi.i/3)
 
2703
 (expt x 3) @result{}  1 ;except for round-off error
 
2704
 (sqrt (expt x 3)) @result{}  1 ;except for round-off error
 
2705
 (expt x 3/2) @result{}  -1 ;except for round-off error
 
2706
@end example
 
2707
 
 
2708
@node gcd, incf, exp, Numbers Dictionary
 
2709
@subsection gcd                                                              [Function]
 
2710
 
 
2711
@code{gcd}  @i{@r{&rest} integers} @result{}  @i{greatest-common-denominator}
 
2712
 
 
2713
@subsubheading  Arguments and Values::
 
2714
 
 
2715
@i{integer}---an @i{integer}.
 
2716
 
 
2717
@i{greatest-common-denominator}---a non-negative @i{integer}.
 
2718
 
 
2719
@subsubheading  Description::
 
2720
 
 
2721
Returns the greatest common divisor of @i{integers}.
 
2722
If only one @i{integer} is supplied, its absolute value is returned.
 
2723
If no @i{integers} are given, @b{gcd} returns @t{0},
 
2724
which is an identity for this operation.
 
2725
 
 
2726
@subsubheading  Examples::
 
2727
 
 
2728
@example
 
2729
 (gcd) @result{}  0
 
2730
 (gcd 60 42) @result{}  6
 
2731
 (gcd 3333 -33 101) @result{}  1
 
2732
 (gcd 3333 -33 1002001) @result{}  11
 
2733
 (gcd 91 -49) @result{}  7
 
2734
 (gcd 63 -42 35) @result{}  7
 
2735
 (gcd 5) @result{}  5
 
2736
 (gcd -4) @result{}  4
 
2737
@end example
 
2738
 
 
2739
@subsubheading  Exceptional Situations::
 
2740
 
 
2741
Should signal an error of @i{type} @b{type-error}
 
2742
                              if any @i{integer} is not an @i{integer}.
 
2743
 
 
2744
@subsubheading  See Also::
 
2745
 
 
2746
@ref{lcm}
 
2747
 
 
2748
@subsubheading  Notes::
 
2749
For three or more arguments,
 
2750
 
 
2751
@example
 
2752
 (gcd b c ... z) @equiv{} (gcd (gcd a b) c ... z)
 
2753
@end example
 
2754
 
 
2755
@node incf, lcm, gcd, Numbers Dictionary
 
2756
@subsection incf, decf                                                          [Macro]
 
2757
 
 
2758
@code{incf}  @i{place @r{[}delta-form@r{]}} @result{}  @i{new-value}
 
2759
 
 
2760
@code{decf}  @i{place @r{[}delta-form@r{]}} @result{}  @i{new-value}
 
2761
 
 
2762
@subsubheading  Arguments and Values:: 
 
2763
 
 
2764
@i{place}---a @i{place}.
 
2765
 
 
2766
@i{delta-form}---a @i{form}; evaluated to produce a @i{delta}.
 
2767
 The default is @t{1}.
 
2768
 
 
2769
@i{delta}---a @i{number}.
 
2770
 
 
2771
@i{new-value}---a @i{number}.
 
2772
 
 
2773
@subsubheading  Description::
 
2774
 
 
2775
@b{incf} and @b{decf} are used for incrementing and
 
2776
decrementing the @i{value} of @i{place}, respectively.
 
2777
 
 
2778
The @i{delta} is 
 
2779
    added to        (in the case of @b{incf})
 
2780
 or subtracted from (in the case of @b{decf})
 
2781
the number in @i{place} and the result is stored in @i{place}.
 
2782
 
 
2783
Any necessary type conversions are performed automatically.
 
2784
 
 
2785
For information about the @i{evaluation} of @i{subforms} of @i{places},
 
2786
see @ref{Evaluation of Subforms to Places}.  
 
2787
 
 
2788
@subsubheading  Examples::
 
2789
@example
 
2790
 (setq n 0)
 
2791
 (incf n) @result{}  1      
 
2792
 n @result{}  1
 
2793
 (decf n 3) @result{}  -2   
 
2794
 n @result{}  -2
 
2795
 (decf n -5) @result{}  3      
 
2796
 (decf n) @result{}  2      
 
2797
 (incf n 0.5) @result{}  2.5
 
2798
 (decf n) @result{}  1.5
 
2799
 n @result{}  1.5
 
2800
@end example
 
2801
 
 
2802
@subsubheading  Side Effects::
 
2803
 
 
2804
@i{Place} is modified.
 
2805
 
 
2806
@subsubheading  See Also::
 
2807
 
 
2808
@b{+}, 
 
2809
@ref{-}
 
2810
, @b{1+}, @b{1-}, 
 
2811
@ref{setf}
 
2812
 
 
2813
@node lcm, log, incf, Numbers Dictionary
 
2814
@subsection lcm                                                              [Function]
 
2815
 
 
2816
@code{lcm}  @i{@r{&rest} integers} @result{}  @i{least-common-multiple}
 
2817
 
 
2818
@subsubheading  Arguments and Values::
 
2819
 
 
2820
@i{integer}---an @i{integer}.
 
2821
 
 
2822
@i{least-common-multiple}---a non-negative @i{integer}.
 
2823
 
 
2824
@subsubheading  Description::
 
2825
 
 
2826
@b{lcm} returns the least common multiple of the @i{integers}.
 
2827
 
 
2828
If no @i{integer} is supplied, the @i{integer} @t{1} is returned.
 
2829
 
 
2830
If only one @i{integer} is supplied, 
 
2831
the absolute value of that @i{integer} is returned.
 
2832
 
 
2833
For two arguments that are not both zero,
 
2834
 
 
2835
@example
 
2836
 (lcm a b) @equiv{} (/ (abs (* a b)) (gcd a b))
 
2837
@end example
 
2838
 
 
2839
If one or both arguments are zero,
 
2840
 
 
2841
@example
 
2842
 (lcm a 0) @equiv{} (lcm 0 a) @equiv{} 0
 
2843
@end example
 
2844
 
 
2845
For three or more arguments,
 
2846
 
 
2847
@example
 
2848
 (lcm a b c ... z) @equiv{} (lcm (lcm a b) c ... z)
 
2849
@end example
 
2850
 
 
2851
@subsubheading  Examples::
 
2852
@example
 
2853
 (lcm 10) @result{}  10
 
2854
 (lcm 25 30) @result{}  150
 
2855
 (lcm -24 18 10) @result{}  360
 
2856
 (lcm 14 35) @result{}  70
 
2857
 (lcm 0 5) @result{}  0
 
2858
 (lcm 1 2 3 4 5 6) @result{}  60
 
2859
@end example
 
2860
 
 
2861
@subsubheading  Exceptional Situations::
 
2862
 
 
2863
Should signal @b{type-error} if any argument is not an @i{integer}.
 
2864
 
 
2865
@subsubheading  See Also::
 
2866
 
 
2867
@ref{gcd}
 
2868
 
 
2869
@node log, mod (Function), lcm, Numbers Dictionary
 
2870
@subsection log                                                              [Function]
 
2871
 
 
2872
@code{log}  @i{number @r{&optional} base} @result{}  @i{logarithm}
 
2873
 
 
2874
@subsubheading  Arguments and Values::
 
2875
 
 
2876
@i{number}---a non-zero @i{number}.
 
2877
 
 
2878
@i{base}---a @i{number}.
 
2879
 
 
2880
@i{logarithm}---a @i{number}.
 
2881
 
 
2882
@subsubheading  Description::
 
2883
 
 
2884
@b{log} returns the logarithm of @i{number} in base @i{base}.
 
2885
If @i{base} is not supplied its value is @i{e}, 
 
2886
the base of the natural logarithms.
 
2887
 
 
2888
@b{log} may return a @i{complex} when given a 
 
2889
 
 
2890
@i{real}
 
2891
 
 
2892
negative @i{number}.
 
2893
 
 
2894
@example
 
2895
 (log -1.0) @equiv{} (complex 0.0 (float pi 0.0))
 
2896
@end example
 
2897
 
 
2898
If @i{base} is zero,
 
2899
@b{log} returns zero.
 
2900
 
 
2901
The result of @t{(log 8 2)} may be either @t{3} or @t{3.0}, depending on the
 
2902
implementation. An implementation can use floating-point calculations
 
2903
even if an exact integer result is possible.
 
2904
 
 
2905
The branch cut for the logarithm function of one argument (natural
 
2906
logarithm) lies along the negative real axis, continuous with quadrant II.
 
2907
The domain excludes the origin.
 
2908
 
 
2909
The mathematical definition of a complex logarithm 
 
2910
is as follows, whether or not minus zero is supported by the
 
2911
implementation:
 
2912
 
 
2913
@example
 
2914
(log @i{x}) @equiv{} (complex (log (abs @i{x})) (phase @i{x}))
 
2915
@end example
 
2916
 
 
2917
Therefore the range of the one-argument logarithm function is that strip
 
2918
of the complex plane containing numbers with imaginary parts between
 
2919
 
 
2920
-\pi (exclusive) and~\pi (inclusive) if minus zero is not supported,
 
2921
or -\pi (inclusive) and~\pi (inclusive) if minus zero is supported.
 
2922
 
 
2923
The two-argument logarithm function is defined as 
 
2924
 
 
2925
@example
 
2926
 (log @i{base} @i{number})
 
2927
 @equiv{} (/ (log @i{number}) (log @i{base}))
 
2928
@end example
 
2929
 
 
2930
This defines the @i{principal} @i{values} precisely.  
 
2931
The range of the two-argument logarithm function is the entire complex plane.
 
2932
 
 
2933
@subsubheading  Examples::
 
2934
 
 
2935
@example
 
2936
 (log 100 10)
 
2937
@result{}  2.0
 
2938
@result{}  2
 
2939
 (log 100.0 10) @result{}  2.0
 
2940
 (log #c(0 1) #c(0 -1))
 
2941
@result{}  #C(-1.0 0.0)
 
2942
@i{OR}@result{} #C(-1 0)
 
2943
 (log 8.0 2) @result{}  3.0
 
2944
@end example
 
2945
 
 
2946
@example
 
2947
 (log #c(-16 16) #c(2 2)) @result{}  3 or approximately #c(3.0 0.0)
 
2948
                               or approximately 3.0 (unlikely)
 
2949
@end example
 
2950
 
 
2951
@subsubheading  Affected By::
 
2952
 
 
2953
The implementation.
 
2954
 
 
2955
@subsubheading  See Also::
 
2956
 
 
2957
@ref{exp}
 
2958
,
 
2959
@b{expt},
 
2960
@ref{Rule of Float Substitutability}
 
2961
 
 
2962
@node mod (Function), signum, log, Numbers Dictionary
 
2963
@subsection mod, rem                                                         [Function]
 
2964
 
 
2965
@code{mod}  @i{number divisor} @result{}  @i{modulus}
 
2966
 
 
2967
@code{rem}  @i{number divisor} @result{}  @i{remainder}
 
2968
 
 
2969
@subsubheading  Arguments and Values::
 
2970
 
 
2971
@i{number}---a @i{real}.
 
2972
 
 
2973
@i{divisor}---a @i{real}.
 
2974
 
 
2975
@i{modulus}, @i{remainder}---a @i{real}.
 
2976
 
 
2977
@subsubheading  Description::
 
2978
 
 
2979
@b{mod} and @b{rem} are generalizations of the modulus
 
2980
and remainder functions respectively.
 
2981
 
 
2982
@b{mod} performs the operation @b{floor} 
 
2983
on @i{number} and @i{divisor} 
 
2984
and returns the remainder of the @b{floor} operation.
 
2985
 
 
2986
@b{rem} performs the operation @b{truncate} 
 
2987
on @i{number} and @i{divisor}
 
2988
and returns the remainder of the @b{truncate} operation.
 
2989
 
 
2990
@b{mod} and @b{rem} are 
 
2991
the modulus and remainder functions 
 
2992
when @i{number} and @i{divisor} are @i{integers}.
 
2993
 
 
2994
@subsubheading  Examples::
 
2995
@example
 
2996
 (rem -1 5) @result{}  -1
 
2997
 (mod -1 5) @result{}  4
 
2998
 (mod 13 4) @result{}  1
 
2999
 (rem 13 4) @result{}  1
 
3000
 (mod -13 4) @result{}  3
 
3001
 (rem -13 4) @result{}  -1
 
3002
 (mod 13 -4) @result{}  -3
 
3003
 (rem 13 -4) @result{}  1
 
3004
 (mod -13 -4) @result{}  -1
 
3005
 (rem -13 -4) @result{}  -1
 
3006
 (mod 13.4 1) @result{}  0.4
 
3007
 (rem 13.4 1) @result{}  0.4
 
3008
 (mod -13.4 1) @result{}  0.6
 
3009
 (rem -13.4 1) @result{}  -0.4
 
3010
@end example
 
3011
 
 
3012
@subsubheading  See Also::
 
3013
 
 
3014
@ref{floor}
 
3015
, @b{truncate}
 
3016
 
 
3017
@subsubheading  Notes::
 
3018
 
 
3019
The result of @b{mod} is either zero or a 
 
3020
 
 
3021
@i{real}
 
3022
 
 
3023
with the same sign as @i{divisor}.
 
3024
 
 
3025
@node signum, sqrt, mod (Function), Numbers Dictionary
 
3026
@subsection signum                                                           [Function]
 
3027
 
 
3028
@code{signum}  @i{number} @result{}  @i{signed-prototype}
 
3029
 
 
3030
@subsubheading  Arguments and Values::
 
3031
 
 
3032
@i{number}---a @i{number}.
 
3033
 
 
3034
@i{signed-prototype}---a @i{number}.
 
3035
 
 
3036
@subsubheading  Description::
 
3037
 
 
3038
@b{signum} determines a numerical value that indicates whether
 
3039
@i{number} is negative, zero, or positive.
 
3040
 
 
3041
For a @i{rational},
 
3042
@b{signum} returns one of @t{-1}, @t{0}, or @t{1}
 
3043
according to whether @i{number} is negative, zero, or positive.
 
3044
For a @i{float}, 
 
3045
the result is a @i{float} of the same format
 
3046
whose value is minus one, zero, or one.
 
3047
For a @i{complex} number @t{z},
 
3048
@t{(signum @i{z})} is a complex number of the same phase but with unit magnitude,
 
3049
unless @t{z} is a complex zero, in which case the result is @t{z}.
 
3050
 
 
3051
For @i{rational} @i{arguments}, @b{signum} is a rational function,
 
3052
but it may be irrational for @i{complex} @i{arguments}.
 
3053
 
 
3054
If @i{number} is a @i{float}, the result is a @i{float}.
 
3055
If @i{number} is a @i{rational}, the result is a @i{rational}.
 
3056
If @i{number} is a @i{complex float}, the result is a @i{complex float}.
 
3057
If @i{number} is a @i{complex rational}, the result is a @i{complex}, 
 
3058
but it is @i{implementation-dependent} whether that result is a
 
3059
@i{complex rational} or a @i{complex float}.
 
3060
 
 
3061
@subsubheading  Examples::
 
3062
 
 
3063
@example
 
3064
 (signum 0) @result{}  0
 
3065
 (signum 99) @result{}  1
 
3066
 (signum 4/5) @result{}  1
 
3067
 (signum -99/100) @result{}  -1
 
3068
 (signum 0.0) @result{}  0.0
 
3069
 (signum #c(0 33)) @result{}  #C(0.0 1.0)
 
3070
 (signum #c(7.5 10.0)) @result{}  #C(0.6 0.8)
 
3071
 (signum #c(0.0 -14.7)) @result{}  #C(0.0 -1.0)
 
3072
 (eql (signum -0.0) -0.0) @result{}  @i{true}
 
3073
@end example
 
3074
 
 
3075
@subsubheading  See Also::
 
3076
 
 
3077
@ref{Rule of Float Substitutability}
 
3078
 
 
3079
@subsubheading  Notes::
 
3080
@example
 
3081
 (signum x) @equiv{} (if (zerop x) x (/ x (abs x)))
 
3082
@end example
 
3083
 
 
3084
@node sqrt, random-state, signum, Numbers Dictionary
 
3085
@subsection sqrt, isqrt                                                      [Function]
 
3086
 
 
3087
@code{sqrt}  @i{number} @result{}  @i{root}
 
3088
 
 
3089
@code{isqrt}  @i{natural} @result{}  @i{natural-root}
 
3090
 
 
3091
@subsubheading  Arguments and Values:: 
 
3092
 
 
3093
@i{number}, @i{root}---a @i{number}.
 
3094
 
 
3095
@i{natural}, @i{natural-root}---a non-negative @i{integer}.
 
3096
 
 
3097
@subsubheading  Description::
 
3098
 
 
3099
@b{sqrt} and @b{isqrt} compute square roots.
 
3100
 
 
3101
@b{sqrt} returns the @i{principal} square root of @i{number}.
 
3102
If the @i{number} is not a @i{complex} but is negative,
 
3103
then the result is a @i{complex}.
 
3104
 
 
3105
@b{isqrt} returns the greatest @i{integer} 
 
3106
less than or equal to the exact positive square root of @i{natural}.
 
3107
 
 
3108
If @i{number} is a positive @i{rational},
 
3109
it is @i{implementation-dependent} 
 
3110
whether @i{root} is a @i{rational} or a @i{float}.
 
3111
If @i{number} is a negative @i{rational},
 
3112
it is @i{implementation-dependent} 
 
3113
whether @i{root} is a @i{complex rational} or a @i{complex float}.
 
3114
 
 
3115
The mathematical definition of complex square root (whether or not
 
3116
minus zero is supported) follows:
 
3117
 
 
3118
@t{(sqrt @i{x}) = (exp (/ (log @i{x}) 2))}
 
3119
 
 
3120
The branch cut for square root lies along the negative real axis,
 
3121
continuous with quadrant II.
 
3122
The range consists of the right half-plane, including the non-negative
 
3123
imaginary axis and excluding the negative imaginary axis.
 
3124
 
 
3125
@subsubheading  Examples::
 
3126
 
 
3127
@example
 
3128
 (sqrt 9.0) @result{}  3.0
 
3129
 (sqrt -9.0) @result{}  #C(0.0 3.0)
 
3130
 (isqrt 9) @result{}  3
 
3131
 (sqrt 12) @result{}  3.4641016
 
3132
 (isqrt 12) @result{}  3
 
3133
 (isqrt 300) @result{}  17
 
3134
 (isqrt 325) @result{}  18
 
3135
 (sqrt 25)
 
3136
@result{}  5
 
3137
@i{OR}@result{} 5.0
 
3138
 (isqrt 25) @result{}  5
 
3139
 (sqrt -1) @result{}  #C(0.0 1.0)
 
3140
 (sqrt #c(0 2)) @result{}  #C(1.0 1.0)
 
3141
@end example
 
3142
 
 
3143
@subsubheading  Exceptional Situations::
 
3144
 
 
3145
The @i{function} @b{sqrt} should signal @b{type-error} if its argument 
 
3146
is not a @i{number}.
 
3147
 
 
3148
The @i{function} @b{isqrt} should signal @b{type-error} if its argument 
 
3149
is not a non-negative @i{integer}.
 
3150
 
 
3151
The functions @b{sqrt} and @b{isqrt} might signal @b{arithmetic-error}.
 
3152
 
 
3153
@subsubheading  See Also::
 
3154
 
 
3155
@ref{exp}
 
3156
,
 
3157
@ref{log}
 
3158
,
 
3159
@ref{Rule of Float Substitutability}
 
3160
 
 
3161
@subsubheading  Notes::
 
3162
 
 
3163
@example
 
3164
 (isqrt x) @equiv{} (values (floor (sqrt x))) 
 
3165
@end example
 
3166
 
 
3167
but it is potentially more efficient.
 
3168
 
 
3169
@node random-state, make-random-state, sqrt, Numbers Dictionary
 
3170
@subsection random-state                                                 [System Class]
 
3171
 
 
3172
@subsubheading  Class Precedence List::
 
3173
@b{random-state},
 
3174
@b{t}
 
3175
 
 
3176
@subsubheading  Description::
 
3177
 
 
3178
A @i{random state} @i{object} contains state
 
3179
information used by the pseudo-random number generator.
 
3180
The nature of a @i{random state} @i{object} is @i{implementation-dependent}.
 
3181
It can be printed out and successfully read back in by the same @i{implementation},
 
3182
but might not function correctly as a @i{random state} in another @i{implementation}.
 
3183
 
 
3184
@i{Implementations} are required to provide a read syntax for
 
3185
@i{objects} of @i{type} @b{random-state}, but the specific nature of that syntax 
 
3186
is @i{implementation-dependent}.
 
3187
 
 
3188
@subsubheading  See Also::
 
3189
 
 
3190
@ref{random-state}
 
3191
,
 
3192
@ref{random}
 
3193
,
 
3194
@ref{Printing Random States}
 
3195
 
 
3196
@node make-random-state, random, random-state, Numbers Dictionary
 
3197
@subsection make-random-state                                                [Function]
 
3198
 
 
3199
@code{make-random-state}  @i{@r{&optional} state} @result{}  @i{new-state}
 
3200
 
 
3201
@subsubheading  Arguments and Values::
 
3202
 
 
3203
@i{state}---a @i{random state}, or @b{nil}, or @b{t}.
 
3204
 The default is @b{nil}.
 
3205
 
 
3206
@i{new-state}---a @i{random state} @i{object}.
 
3207
 
 
3208
@subsubheading  Description::
 
3209
 
 
3210
Creates a @i{fresh} @i{object} of @i{type} @b{random-state} suitable
 
3211
for use as the @i{value} of @b{*random-state*}.
 
3212
 
 
3213
If @i{state} is a @i{random state} @i{object},
 
3214
the @i{new-state} is a @i{copy}_5 of that @i{object}.
 
3215
If @i{state} is @b{nil},
 
3216
the @i{new-state} is a @i{copy}_5 of the @i{current random state}.
 
3217
If @i{state} is @b{t},
 
3218
the @i{new-state} is a @i{fresh} @i{random state} @i{object}
 
3219
that has been randomly initialized by some means.
 
3220
 
 
3221
@subsubheading  Examples::
 
3222
 
 
3223
@example
 
3224
 (let* ((rs1 (make-random-state nil))
 
3225
        (rs2 (make-random-state t))
 
3226
        (rs3 (make-random-state rs2))
 
3227
        (rs4 nil))
 
3228
   (list (loop for i from 1 to 10 
 
3229
               collect (random 100)
 
3230
               when (= i 5)
 
3231
                do (setq rs4 (make-random-state)))
 
3232
         (loop for i from 1 to 10 collect (random 100 rs1))
 
3233
         (loop for i from 1 to 10 collect (random 100 rs2))
 
3234
         (loop for i from 1 to 10 collect (random 100 rs3))
 
3235
         (loop for i from 1 to 10 collect (random 100 rs4))))
 
3236
@result{}  ((29 25 72 57 55 68 24 35 54 65)
 
3237
    (29 25 72 57 55 68 24 35 54 65)
 
3238
    (93 85 53 99 58 62 2 23 23 59)
 
3239
    (93 85 53 99 58 62 2 23 23 59)
 
3240
    (68 24 35 54 65 54 55 50 59 49))
 
3241
@end example
 
3242
 
 
3243
@subsubheading  Exceptional Situations::
 
3244
 
 
3245
Should signal an error of @i{type} @b{type-error}
 
3246
                              if @i{state} is not a @i{random state}, or @b{nil}, or @b{t}.
 
3247
 
 
3248
@subsubheading  See Also::
 
3249
 
 
3250
@ref{random}
 
3251
 
3252
@ref{random-state}
 
3253
 
 
3254
@subsubheading  Notes::
 
3255
 
 
3256
One important use of @b{make-random-state} is to allow the same
 
3257
series of pseudo-random @i{numbers} to be generated many times within a 
 
3258
single program.
 
3259
 
 
3260
@node random, random-state-p, make-random-state, Numbers Dictionary
 
3261
@subsection random                                                           [Function]
 
3262
 
 
3263
@code{random}  @i{limit @r{&optional} random-state} @result{}  @i{random-number}
 
3264
 
 
3265
@subsubheading  Arguments and Values::
 
3266
 
 
3267
@i{limit}---a positive @i{integer},
 
3268
             or a positive @i{float}.
 
3269
 
 
3270
@i{random-state}---a @i{random state}.
 
3271
 The default is the @i{current random state}.
 
3272
 
 
3273
@i{random-number}---a non-negative @i{number}
 
3274
                        less than @i{limit} 
 
3275
                    and of the same @i{type} as @i{limit}.
 
3276
 
 
3277
@subsubheading  Description::
 
3278
 
 
3279
Returns a pseudo-random number that is a non-negative @i{number}
 
3280
less than @i{limit} and of the same @i{type} as @i{limit}.
 
3281
 
 
3282
The @i{random-state}, which is modified by this function,
 
3283
encodes the internal state maintained by the random number generator.
 
3284
 
 
3285
An approximately uniform choice distribution is used.  If @i{limit}
 
3286
is an @i{integer}, each of the possible results occurs with
 
3287
(approximate) probability 1/@i{limit}.
 
3288
 
 
3289
@subsubheading  Examples::
 
3290
 
 
3291
@example
 
3292
 (<= 0 (random 1000) 1000) @result{}  @i{true}
 
3293
 (let ((state1 (make-random-state))
 
3294
       (state2 (make-random-state)))
 
3295
   (= (random 1000 state1) (random 1000 state2))) @result{}  @i{true}
 
3296
@end example
 
3297
 
 
3298
@subsubheading  Side Effects::
 
3299
 
 
3300
The @i{random-state} is modified.
 
3301
 
 
3302
@subsubheading  Exceptional Situations::
 
3303
 
 
3304
Should signal an error of @i{type} @b{type-error}
 
3305
                              if @i{limit} is not a positive @i{integer} or a positive @i{real}.
 
3306
 
 
3307
@subsubheading  See Also::
 
3308
 
 
3309
@ref{make-random-state}
 
3310
 
3311
@ref{random-state}
 
3312
 
 
3313
@subsubheading  Notes::
 
3314
 
 
3315
See @i{Common Lisp: The Language} for information about generating random numbers.
 
3316
 
 
3317
@node random-state-p, *random-state*, random, Numbers Dictionary
 
3318
@subsection random-state-p                                                   [Function]
 
3319
 
 
3320
@code{random-state-p}  @i{object} @result{}  @i{generalized-boolean}
 
3321
 
 
3322
@subsubheading  Arguments and Values::
 
3323
 
 
3324
@i{object}---an @i{object}.
 
3325
 
 
3326
@i{generalized-boolean}---a @i{generalized boolean}.
 
3327
 
 
3328
@subsubheading  Description::
 
3329
 
 
3330
Returns @i{true} if @i{object} is of @i{type} @b{random-state};
 
3331
otherwise, returns @i{false}.
 
3332
 
 
3333
@subsubheading  Examples::
 
3334
 
 
3335
@example
 
3336
 (random-state-p *random-state*) @result{}  @i{true}
 
3337
 (random-state-p (make-random-state)) @result{}  @i{true}
 
3338
 (random-state-p 'test-function) @result{}  @i{false}
 
3339
@end example
 
3340
 
 
3341
@subsubheading  See Also::
 
3342
 
 
3343
@ref{make-random-state}
 
3344
 
3345
@ref{random-state}
 
3346
 
 
3347
@subsubheading  Notes::
 
3348
 
 
3349
@example
 
3350
 (random-state-p @i{object}) @equiv{} (typep @i{object} 'random-state)
 
3351
@end example
 
3352
 
 
3353
@node *random-state*, numberp, random-state-p, Numbers Dictionary
 
3354
@subsection *random-state*                                                   [Variable]
 
3355
 
 
3356
@subsubheading  Value Type::
 
3357
 
 
3358
a @i{random state}.
 
3359
 
 
3360
@subsubheading  Initial Value::
 
3361
 
 
3362
@i{implementation-dependent}.
 
3363
 
 
3364
@subsubheading  Description::
 
3365
 
 
3366
The @i{current random state}, which is used, for example,
 
3367
by the @i{function} @b{random} when a @i{random state} is not explicitly supplied.
 
3368
 
 
3369
@subsubheading  Examples::      
 
3370
 
 
3371
@example
 
3372
 (random-state-p *random-state*) @result{}  @i{true}
 
3373
 (setq snap-shot (make-random-state))
 
3374
 ;; The series from any given point is random,
 
3375
 ;; but if you backtrack to that point, you get the same series.
 
3376
 (list (loop for i from 1 to 10 collect (random))
 
3377
       (let ((*random-state* snap-shot))
 
3378
         (loop for i from 1 to 10 collect (random)))
 
3379
       (loop for i from 1 to 10 collect (random))
 
3380
       (let ((*random-state* snap-shot))
 
3381
         (loop for i from 1 to 10 collect (random))))
 
3382
@result{}  ((19 16 44 19 96 15 76 96 13 61)
 
3383
    (19 16 44 19 96 15 76 96 13 61)
 
3384
    (16 67 0 43 70 79 58 5 63 50)
 
3385
    (16 67 0 43 70 79 58 5 63 50))
 
3386
@end example
 
3387
 
 
3388
@subsubheading  Affected By::
 
3389
 
 
3390
The @i{implementation}.
 
3391
 
 
3392
@b{random}.
 
3393
 
 
3394
@subsubheading  See Also::
 
3395
 
 
3396
@ref{make-random-state}
 
3397
,
 
3398
@ref{random}
 
3399
,
 
3400
@b{random-state}
 
3401
 
 
3402
@subsubheading  Notes::
 
3403
 
 
3404
@i{Binding} @b{*random-state*} to a different 
 
3405
@i{random state} @i{object} correctly saves and 
 
3406
restores the old @i{random state} @i{object}.
 
3407
 
 
3408
@node numberp, cis, *random-state*, Numbers Dictionary
 
3409
@subsection numberp                                                          [Function]
 
3410
 
 
3411
@code{numberp}  @i{object} @result{}  @i{generalized-boolean}
 
3412
 
 
3413
@subsubheading  Arguments and Values::
 
3414
 
 
3415
@i{object}---an @i{object}.
 
3416
 
 
3417
@i{generalized-boolean}---a @i{generalized boolean}.
 
3418
 
 
3419
@subsubheading  Description::
 
3420
 
 
3421
Returns @i{true} if @i{object} is of @i{type} @b{number};
 
3422
otherwise, returns @i{false}.
 
3423
 
 
3424
@subsubheading  Examples::
 
3425
 
 
3426
@example
 
3427
 (numberp 12) @result{}  @i{true}
 
3428
 (numberp (expt 2 130)) @result{}  @i{true}
 
3429
 (numberp #c(5/3 7.2)) @result{}  @i{true}
 
3430
 (numberp nil) @result{}  @i{false}
 
3431
 (numberp (cons 1 2)) @result{}  @i{false}
 
3432
@end example
 
3433
 
 
3434
@subsubheading  Notes::
 
3435
 
 
3436
@example
 
3437
 (numberp @i{object}) @equiv{} (typep @i{object} 'number)
 
3438
@end example
 
3439
 
 
3440
@node cis, complex, numberp, Numbers Dictionary
 
3441
@subsection cis                                                              [Function]
 
3442
 
 
3443
@code{cis}  @i{radians} @result{}  @i{number}
 
3444
 
 
3445
@subsubheading  Arguments and Values::
 
3446
 
 
3447
@i{radians}---a @i{real}.
 
3448
 
 
3449
@i{number}---a @i{complex}.
 
3450
 
 
3451
@subsubheading  Description::
 
3452
 
 
3453
@b{cis} returns the value of~@i{e}^@i{i\cdot @i{radians}},
 
3454
which is a @i{complex} in which the
 
3455
real part is equal to the cosine of @i{radians}, and the 
 
3456
imaginary part is equal to the sine of @i{radians}.
 
3457
 
 
3458
@subsubheading  Examples::
 
3459
@example
 
3460
 (cis 0) @result{}  #C(1.0 0.0)
 
3461
@end example
 
3462
 
 
3463
@subsubheading  See Also::
 
3464
 
 
3465
@ref{Rule of Float Substitutability}
 
3466
 
 
3467
@node complex, complexp, cis, Numbers Dictionary
 
3468
@subsection complex                                                          [Function]
 
3469
 
 
3470
@code{complex}  @i{realpart @r{&optional} imagpart} @result{}  @i{complex}
 
3471
 
 
3472
@subsubheading  Arguments and Values::
 
3473
 
 
3474
@i{realpart}---a @i{real}.
 
3475
 
 
3476
@i{imagpart}---a @i{real}.
 
3477
 
 
3478
@i{complex}---a @i{rational} or a @i{complex}.
 
3479
 
 
3480
@subsubheading  Description::
 
3481
 
 
3482
@b{complex} returns a @i{number} 
 
3483
    whose real      part is @i{realpart} 
 
3484
and whose imaginary part is @i{imagpart}.
 
3485
 
 
3486
If @i{realpart} is a @i{rational}
 
3487
and @i{imagpart} is the @i{rational} number zero, 
 
3488
the result of @b{complex} is @i{realpart}, a @i{rational}.
 
3489
Otherwise, the result is a @i{complex}.
 
3490
 
 
3491
If either @i{realpart} or @i{imagpart} is a @i{float},
 
3492
the non-@i{float} is converted to a @i{float} 
 
3493
before the @i{complex} is created.
 
3494
If @i{imagpart} is not supplied, the imaginary part is a 
 
3495
zero of the same @i{type} as @i{realpart}; @i{i.e.}, @t{(coerce 0 (type-of @i{realpart}))} is
 
3496
effectively used.  
 
3497
 
 
3498
Type upgrading implies a movement upwards in the type 
 
3499
hierarchy lattice.  
 
3500
In the case of @i{complexes}, the @i{type-specifier} 
 
3501
 
 
3502
[Reviewer Note by Barmar: What type specifier?]
 
3503
must be a subtype of 
 
3504
@t{(upgraded-complex-part-type @i{type-specifier})}.
 
3505
If @i{type-specifier1} is a subtype of @i{type-specifier2}, then
 
3506
@t{(upgraded-complex-element-type '@i{type-specifier1})}
 
3507
must also be a subtype of
 
3508
@t{(upgraded-complex-element-type '@i{type-specifier2})}.  
 
3509
Two disjoint types can be upgraded into 
 
3510
the same thing.
 
3511
 
 
3512
@subsubheading  Examples::
 
3513
@example
 
3514
 (complex 0) @result{}  0
 
3515
 (complex 0.0) @result{}  #C(0.0 0.0)
 
3516
 (complex 1 1/2) @result{}  #C(1 1/2)
 
3517
 (complex 1 .99) @result{}  #C(1.0 0.99)
 
3518
 (complex 3/2 0.0) @result{}  #C(1.5 0.0)
 
3519
@end example
 
3520
 
 
3521
@subsubheading  See Also::
 
3522
 
 
3523
@ref{realpart}
 
3524
, @b{imagpart}
 
3525
 
 
3526
@subsubheading  Notes::
 
3527
 
 
3528
@example
 
3529
 #c(a b) @equiv{} #.(complex a b)
 
3530
@end example
 
3531
 
 
3532
@node complexp, conjugate, complex, Numbers Dictionary
 
3533
@subsection complexp                                                         [Function]
 
3534
 
 
3535
@code{complexp}  @i{object} @result{}  @i{generalized-boolean}
 
3536
 
 
3537
@subsubheading  Arguments and Values::
 
3538
 
 
3539
@i{object}---an @i{object}.
 
3540
 
 
3541
@i{generalized-boolean}---a @i{generalized boolean}.
 
3542
 
 
3543
@subsubheading  Description::
 
3544
 
 
3545
Returns @i{true} if @i{object} is of @i{type} @b{complex};
 
3546
otherwise, returns @i{false}.
 
3547
 
 
3548
@subsubheading  Examples::
 
3549
@example
 
3550
 (complexp 1.2d2) @result{}  @i{false}
 
3551
 (complexp #c(5/3 7.2)) @result{}  @i{true}
 
3552
 
 
3553
@end example
 
3554
 
 
3555
@subsubheading  See Also::
 
3556
 
 
3557
@ref{complex}
 
3558
 (@i{function} and @i{type}), 
 
3559
@ref{typep}
 
3560
 
 
3561
@subsubheading  Notes::
 
3562
 
 
3563
@example
 
3564
 (complexp @i{object}) @equiv{} (typep @i{object} 'complex)
 
3565
@end example
 
3566
 
 
3567
@node conjugate, phase, complexp, Numbers Dictionary
 
3568
@subsection conjugate                                                        [Function]
 
3569
 
 
3570
@code{conjugate}  @i{number} @result{}  @i{conjugate}
 
3571
 
 
3572
@subsubheading  Arguments and Values::
 
3573
 
 
3574
@i{number}---a @i{number}.
 
3575
 
 
3576
@i{conjugate}---a @i{number}.
 
3577
 
 
3578
@subsubheading  Description::
 
3579
 
 
3580
Returns the complex conjugate of @i{number}.
 
3581
The conjugate of a 
 
3582
 
 
3583
@i{real}
 
3584
 
 
3585
number is itself.  
 
3586
 
 
3587
@subsubheading  Examples::
 
3588
 
 
3589
@example
 
3590
 (conjugate #c(0 -1)) @result{}  #C(0 1)
 
3591
 (conjugate #c(1 1)) @result{}  #C(1 -1)
 
3592
 (conjugate 1.5) @result{}  1.5
 
3593
 (conjugate #C(3/5 4/5)) @result{}  #C(3/5 -4/5)
 
3594
 (conjugate #C(0.0D0 -1.0D0)) @result{}  #C(0.0D0 1.0D0)
 
3595
 (conjugate 3.7) @result{}  3.7
 
3596
@end example
 
3597
 
 
3598
@subsubheading  Notes::
 
3599
 
 
3600
For a @i{complex} number @t{z},
 
3601
 
 
3602
@example
 
3603
 (conjugate z) @equiv{} (complex (realpart z) (- (imagpart z)))
 
3604
@end example
 
3605
 
 
3606
@node phase, realpart, conjugate, Numbers Dictionary
 
3607
@subsection phase                                                            [Function]
 
3608
 
 
3609
@code{phase}  @i{number} @result{}  @i{phase}
 
3610
 
 
3611
@subsubheading  Arguments and Values::
 
3612
 
 
3613
@i{number}---a @i{number}.
 
3614
 
 
3615
@i{phase}---a @i{number}.
 
3616
 
 
3617
@subsubheading  Description::
 
3618
 
 
3619
@b{phase} 
 
3620
returns the phase 
 
3621
of @i{number} (the angle part of its polar representation)
 
3622
in radians, in the range 
 
3623
 
 
3624
-\pi (exclusive) if minus zero is not supported, or 
 
3625
-\pi (inclusive) if minus zero is supported, 
 
3626
 
 
3627
to \pi (inclusive).  The phase of a positive 
 
3628
 
 
3629
@i{real}
 
3630
 
 
3631
number
 
3632
is zero; that of a negative 
 
3633
 
 
3634
@i{real}
 
3635
 
 
3636
number is \pi.
 
3637
The phase of zero is defined to be zero.
 
3638
 
 
3639
If @i{number} is a @i{complex float},  
 
3640
the result is a @i{float} of the same @i{type} 
 
3641
as the components of @i{number}.
 
3642
If @i{number} is a @i{float}, the result is a
 
3643
@i{float} of the same @i{type}.
 
3644
If @i{number} is a @i{rational} or a @i{complex rational},
 
3645
the result is a @i{single float}.  
 
3646
 
 
3647
The branch cut for @b{phase} lies along the negative real
 
3648
axis, continuous with quadrant II.  The range consists of that portion of
 
3649
the real axis between -\pi (exclusive) and~\pi (inclusive).
 
3650
 
 
3651
The mathematical definition of @b{phase} is as follows:
 
3652
 
 
3653
@t{(phase @i{x}) = (atan (imagpart @i{x}) (realpart @i{x}))}
 
3654
 
 
3655
@subsubheading  Examples::
 
3656
 
 
3657
@example
 
3658
 (phase 1) @result{}  0.0s0
 
3659
 (phase 0) @result{}  0.0s0
 
3660
 (phase (cis 30)) @result{}  -1.4159266
 
3661
 (phase #c(0 1)) @result{}  1.5707964
 
3662
@end example
 
3663
 
 
3664
@subsubheading  Exceptional Situations::
 
3665
 
 
3666
Should signal @b{type-error} if its argument is not a @i{number}.
 
3667
Might signal @b{arithmetic-error}.
 
3668
 
 
3669
@subsubheading  See Also::
 
3670
 
 
3671
@ref{Rule of Float Substitutability}
 
3672
 
 
3673
@node realpart, upgraded-complex-part-type, phase, Numbers Dictionary
 
3674
@subsection realpart, imagpart                                               [Function]
 
3675
 
 
3676
@code{realpart}  @i{number} @result{}  @i{real}
 
3677
 
 
3678
@code{imagpart}  @i{number} @result{}  @i{real}
 
3679
 
 
3680
@subsubheading  Arguments and Values:: 
 
3681
 
 
3682
@i{number}---a @i{number}.
 
3683
 
 
3684
@i{real}---a @i{real}.
 
3685
 
 
3686
@subsubheading  Description::
 
3687
 
 
3688
@b{realpart} and @b{imagpart} return the real and
 
3689
imaginary parts of @i{number} respectively.
 
3690
If @i{number} is 
 
3691
 
 
3692
@i{real},
 
3693
 
 
3694
then @b{realpart} returns @i{number} and @b{imagpart}
 
3695
returns @t{(* 0 @i{number})}, which has the effect that the
 
3696
imaginary part of a @i{rational} is @t{0} and that of
 
3697
a @i{float} is a floating-point zero of the same format.
 
3698
 
 
3699
@subsubheading  Examples::
 
3700
 
 
3701
@example
 
3702
 (realpart #c(23 41)) @result{}  23
 
3703
 (imagpart #c(23 41.0)) @result{}  41.0
 
3704
 (realpart #c(23 41.0)) @result{}  23.0
 
3705
 (imagpart 23.0) @result{}  0.0
 
3706
@end example
 
3707
 
 
3708
@subsubheading  Exceptional Situations::
 
3709
 
 
3710
Should signal an error of @i{type} @b{type-error}
 
3711
                              if @i{number} is not a @i{number}.
 
3712
 
 
3713
@subsubheading  See Also::
 
3714
 
 
3715
@ref{complex}
 
3716
 
 
3717
@node upgraded-complex-part-type, realp, realpart, Numbers Dictionary
 
3718
@subsection upgraded-complex-part-type                                       [Function]
 
3719
 
 
3720
@code{upgraded-complex-part-type}  @i{typespec @r{&optional} environment} @result{}  @i{upgraded-typespec}
 
3721
 
 
3722
@subsubheading  Arguments and Values:: 
 
3723
 
 
3724
@i{typespec}---a @i{type specifier}.
 
3725
 
 
3726
@i{environment}---an @i{environment} @i{object}.
 
3727
  The default is @b{nil}, denoting the @i{null lexical environment}
 
3728
           and the and current @i{global environment}.
 
3729
 
 
3730
@i{upgraded-typespec}---a @i{type specifier}.
 
3731
 
 
3732
@subsubheading  Description::
 
3733
 
 
3734
@b{upgraded-complex-part-type} returns the part type of the
 
3735
most specialized @i{complex} number representation that can
 
3736
hold parts of @i{type} @i{typespec}.
 
3737
 
 
3738
The @i{typespec} is a @i{subtype} of 
 
3739
(and possibly @i{type equivalent} to)
 
3740
the @i{upgraded-typespec}.
 
3741
 
 
3742
The purpose of @b{upgraded-complex-part-type}
 
3743
is to reveal how an implementation does its @i{upgrading}.
 
3744
 
 
3745
@subsubheading  See Also::
 
3746
 
 
3747
@ref{complex}
 
3748
 (@i{function} and @i{type})
 
3749
 
 
3750
@subsubheading  Notes::
 
3751
 
 
3752
@node realp, numerator, upgraded-complex-part-type, Numbers Dictionary
 
3753
@subsection realp                                                            [Function]
 
3754
 
 
3755
@code{realp}  @i{object} @result{}  @i{generalized-boolean}
 
3756
 
 
3757
@subsubheading  Arguments and Values::
 
3758
 
 
3759
@i{object}---an @i{object}.
 
3760
 
 
3761
@i{generalized-boolean}---a @i{generalized boolean}.
 
3762
 
 
3763
@subsubheading  Description::
 
3764
 
 
3765
Returns @i{true} if @i{object} is of @i{type} @b{real};
 
3766
otherwise, returns @i{false}.
 
3767
 
 
3768
@subsubheading  Examples::
 
3769
@example
 
3770
 (realp 12) @result{}  @i{true}
 
3771
 (realp #c(5/3 7.2)) @result{}  @i{false}
 
3772
 (realp nil) @result{}  @i{false}
 
3773
 (realp (cons 1 2)) @result{}  @i{false}
 
3774
@end example
 
3775
 
 
3776
@subsubheading  Notes::
 
3777
 
 
3778
@example
 
3779
 (realp @i{object}) @equiv{} (typep @i{object} 'real)
 
3780
@end example
 
3781
 
 
3782
@node numerator, rational (Function), realp, Numbers Dictionary
 
3783
@subsection numerator, denominator                                           [Function]
 
3784
 
 
3785
@code{numerator}  @i{rational} @result{}  @i{numerator}
 
3786
 
 
3787
@code{denominator}  @i{rational} @result{}  @i{denominator}
 
3788
 
 
3789
@subsubheading  Arguments and Values::
 
3790
 
 
3791
@i{rational}---a @i{rational}.
 
3792
 
 
3793
@i{numerator}---an @i{integer}.
 
3794
 
 
3795
@i{denominator}---a positive @i{integer}.
 
3796
 
 
3797
@subsubheading  Description::
 
3798
 
 
3799
@b{numerator} and @b{denominator} reduce @i{rational}
 
3800
to canonical form and compute the numerator or denominator of that number.
 
3801
 
 
3802
@b{numerator} and @b{denominator} return the numerator 
 
3803
or denominator of the canonical form of @i{rational}.
 
3804
 
 
3805
If @i{rational} is an @i{integer}, 
 
3806
@b{numerator} returns @i{rational}
 
3807
and @b{denominator} returns 1.
 
3808
 
 
3809
@subsubheading  Examples::
 
3810
@example
 
3811
 (numerator 1/2) @result{}  1
 
3812
 (denominator 12/36) @result{}  3
 
3813
 (numerator -1) @result{}  -1
 
3814
 (denominator (/ -33)) @result{}  33
 
3815
 (numerator (/ 8 -6)) @result{}  -4
 
3816
 (denominator (/ 8 -6)) @result{}  3
 
3817
@end example
 
3818
 
 
3819
@subsubheading  See Also::
 
3820
 
 
3821
@ref{/}
 
3822
 
 
3823
@subsubheading  Notes::
 
3824
@example
 
3825
 (gcd (numerator x) (denominator x)) @result{}  1
 
3826
@end example
 
3827
 
 
3828
@node rational (Function), rationalp, numerator, Numbers Dictionary
 
3829
@subsection rational, rationalize                                            [Function]
 
3830
 
 
3831
@code{rational}  @i{number} @result{}  @i{rational}
 
3832
 
 
3833
@code{rationalize}  @i{number} @result{}  @i{rational}
 
3834
 
 
3835
@subsubheading  Arguments and Values::
 
3836
 
 
3837
@i{number}---a @i{real}.
 
3838
 
 
3839
@i{rational}---a @i{rational}.
 
3840
 
 
3841
@subsubheading  Description::
 
3842
 
 
3843
@b{rational} and @b{rationalize} convert 
 
3844
 
 
3845
@i{reals}
 
3846
 
 
3847
to @i{rationals}.
 
3848
 
 
3849
If @i{number} is already @i{rational}, it is returned.
 
3850
 
 
3851
If @i{number} is a @i{float}, 
 
3852
@b{rational} returns a @i{rational} 
 
3853
that is mathematically equal in value to the @i{float}. 
 
3854
@b{rationalize} returns a @i{rational} that
 
3855
approximates the @i{float} to the accuracy of 
 
3856
the underlying floating-point representation. 
 
3857
 
 
3858
@b{rational} assumes that the @i{float} is completely accurate.
 
3859
 
 
3860
@b{rationalize} assumes that the
 
3861
@i{float} is accurate only to the precision of the
 
3862
floating-point representation.
 
3863
 
 
3864
@subsubheading  Examples::
 
3865
@example
 
3866
 (rational 0) @result{}  0
 
3867
 (rationalize -11/100) @result{}  -11/100
 
3868
 (rational .1) @result{}  13421773/134217728 ;implementation-dependent
 
3869
 (rationalize .1) @result{}  1/10
 
3870
@end example
 
3871
 
 
3872
@subsubheading  Affected By::
 
3873
 
 
3874
The @i{implementation}.
 
3875
 
 
3876
@subsubheading  Exceptional Situations::
 
3877
 
 
3878
Should signal an error of @i{type} @b{type-error}
 
3879
                              if @i{number} is not a @i{real}.
 
3880
Might signal @b{arithmetic-error}.
 
3881
 
 
3882
@subsubheading  Notes::
 
3883
 
 
3884
It is always the case that
 
3885
 
 
3886
@example
 
3887
 (float (rational x) x) @equiv{} x
 
3888
@end example
 
3889
 
 
3890
and
 
3891
 
 
3892
@example
 
3893
 (float (rationalize x) x) @equiv{} x
 
3894
@end example
 
3895
 
 
3896
That is, rationalizing a @i{float} by either method
 
3897
and then converting it back
 
3898
to a @i{float} 
 
3899
of the same format produces the original @i{number}.
 
3900
 
 
3901
@node rationalp, ash, rational (Function), Numbers Dictionary
 
3902
@subsection rationalp                                                        [Function]
 
3903
 
 
3904
@code{rationalp}  @i{object} @result{}  @i{generalized-boolean}
 
3905
 
 
3906
@subsubheading  Arguments and Values::
 
3907
 
 
3908
@i{object}---an @i{object}.
 
3909
 
 
3910
@i{generalized-boolean}---a @i{generalized boolean}.
 
3911
 
 
3912
@subsubheading  Description::
 
3913
 
 
3914
Returns @i{true} if @i{object} is of @i{type} @b{rational};
 
3915
otherwise, returns @i{false}.
 
3916
 
 
3917
@subsubheading  Examples::
 
3918
 
 
3919
@example
 
3920
 (rationalp 12) @result{}  @i{true}
 
3921
 (rationalp 6/5) @result{}  @i{true}
 
3922
 (rationalp 1.212) @result{}  @i{false}
 
3923
@end example
 
3924
 
 
3925
@subsubheading  See Also::
 
3926
 
 
3927
@ref{rational (Function)}
 
3928
 
 
3929
@subsubheading  Notes::
 
3930
@example
 
3931
 (rationalp @i{object}) @equiv{} (typep @i{object} 'rational)
 
3932
@end example
 
3933
 
 
3934
@node ash, integer-length, rationalp, Numbers Dictionary
 
3935
@subsection ash                                                              [Function]
 
3936
 
 
3937
@code{ash}  @i{integer count} @result{}  @i{shifted-integer}
 
3938
 
 
3939
@subsubheading  Arguments and Values::
 
3940
 
 
3941
@i{integer}---an @i{integer}.
 
3942
 
 
3943
@i{count}---an @i{integer}.
 
3944
 
 
3945
@i{shifted-integer}---an @i{integer}.
 
3946
 
 
3947
@subsubheading  Description::
 
3948
 
 
3949
@b{ash} performs the arithmetic shift operation on the binary
 
3950
representation of @i{integer}, which is treated as if it were binary.
 
3951
 
 
3952
@b{ash} shifts @i{integer} arithmetically left by @i{count} bit
 
3953
positions if @i{count} is positive,
 
3954
or right @i{count} bit positions if @i{count} is negative.
 
3955
The shifted value of the same sign 
 
3956
as @i{integer} is returned.
 
3957
 
 
3958
Mathematically speaking, @b{ash} performs the computation
 
3959
@t{floor}(@i{integer}\cdot 2^@i{count}).
 
3960
Logically, @b{ash} 
 
3961
moves all of the bits in @i{integer} to the left,
 
3962
adding zero-bits at the right, or moves them to the right,
 
3963
discarding bits.  
 
3964
 
 
3965
@b{ash} is defined to behave as if @i{integer} were 
 
3966
represented in two's complement form, regardless of
 
3967
how @i{integers} are represented internally.
 
3968
@subsubheading  Examples::
 
3969
@example
 
3970
 (ash 16 1) @result{}  32
 
3971
 (ash 16 0) @result{}  16
 
3972
 (ash 16 -1) @result{}  8
 
3973
 (ash -100000000000000000000000000000000 -100) @result{}  -79
 
3974
@end example
 
3975
 
 
3976
@subsubheading  Exceptional Situations::
 
3977
 
 
3978
Should signal an error of @i{type} @b{type-error}
 
3979
                              if @i{integer} is not an @i{integer}.
 
3980
Should signal an error of @i{type} @b{type-error}
 
3981
                              if @i{count} is not an @i{integer}.
 
3982
Might signal @b{arithmetic-error}.
 
3983
 
 
3984
@subsubheading  Notes::
 
3985
 
 
3986
@example
 
3987
 (logbitp @i{j} (ash @i{n} @i{k}))
 
3988
 @equiv{} (and (>= @i{j} @i{k}) (logbitp (- @i{j} @i{k}) @i{n}))
 
3989
@end example
 
3990
 
 
3991
@node integer-length, integerp, ash, Numbers Dictionary
 
3992
@subsection integer-length                                                   [Function]
 
3993
 
 
3994
@code{integer-length}  @i{integer} @result{}  @i{number-of-bits}
 
3995
 
 
3996
@subsubheading  Arguments and Values::
 
3997
 
 
3998
@i{integer}---an @i{integer}.
 
3999
 
 
4000
@i{number-of-bits}---a non-negative @i{integer}.
 
4001
 
 
4002
@subsubheading  Description::
 
4003
 
 
4004
Returns the number of bits needed to represent @i{integer}
 
4005
in binary two's-complement format.
 
4006
 
 
4007
@subsubheading  Examples::
 
4008
 
 
4009
@example
 
4010
 (integer-length 0) @result{}  0
 
4011
 (integer-length 1) @result{}  1
 
4012
 (integer-length 3) @result{}  2
 
4013
 (integer-length 4) @result{}  3
 
4014
 (integer-length 7) @result{}  3
 
4015
 (integer-length -1) @result{}  0
 
4016
 (integer-length -4) @result{}  2
 
4017
 (integer-length -7) @result{}  3
 
4018
 (integer-length -8) @result{}  3
 
4019
 (integer-length (expt 2 9)) @result{}  10
 
4020
 (integer-length (1- (expt 2 9))) @result{}  9
 
4021
 (integer-length (- (expt 2 9))) @result{}  9
 
4022
 (integer-length (- (1+ (expt 2 9)))) @result{}  10
 
4023
@end example
 
4024
 
 
4025
@subsubheading  Exceptional Situations::
 
4026
 
 
4027
Should signal an error of @i{type} @b{type-error}
 
4028
                              if @i{integer} is not an @i{integer}.
 
4029
 
 
4030
@subsubheading  Notes::
 
4031
 
 
4032
This function could have been defined by:
 
4033
 
 
4034
@example
 
4035
(defun integer-length (integer)
 
4036
  (ceiling (log (if (minusp integer)
 
4037
                    (- integer)
 
4038
                    (1+ integer))
 
4039
                2)))
 
4040
@end example
 
4041
 
 
4042
If @i{integer} is non-negative, then its value can be represented
 
4043
in unsigned binary form in a field whose width in bits is
 
4044
no smaller than @t{(integer-length @i{integer})}.
 
4045
Regardless of the sign of @i{integer}, its value can be
 
4046
represented in signed binary two's-complement form in a field
 
4047
whose width in bits is no smaller than @t{(+ (integer-length @i{integer}) 1)}.
 
4048
 
 
4049
@node integerp, parse-integer, integer-length, Numbers Dictionary
 
4050
@subsection integerp                                                         [Function]
 
4051
 
 
4052
@code{integerp}  @i{object} @result{}  @i{generalized-boolean}
 
4053
 
 
4054
@subsubheading  Arguments and Values::
 
4055
 
 
4056
@i{object}---an @i{object}.
 
4057
 
 
4058
@i{generalized-boolean}---a @i{generalized boolean}.
 
4059
 
 
4060
@subsubheading  Description::
 
4061
 
 
4062
Returns @i{true} if @i{object} is of @i{type} @b{integer};
 
4063
otherwise, returns @i{false}.
 
4064
 
 
4065
@subsubheading  Examples::
 
4066
@example
 
4067
 (integerp 1) @result{}  @i{true}
 
4068
 (integerp (expt 2 130)) @result{}  @i{true}
 
4069
 (integerp 6/5) @result{}  @i{false}
 
4070
 (integerp nil) @result{}  @i{false}
 
4071
 
 
4072
@end example
 
4073
 
 
4074
@subsubheading  Notes::
 
4075
 
 
4076
@example
 
4077
 (integerp @i{object}) @equiv{} (typep @i{object} 'integer)
 
4078
@end example
 
4079
 
 
4080
@node parse-integer, boole, integerp, Numbers Dictionary
 
4081
@subsection parse-integer                                                    [Function]
 
4082
 
 
4083
@code{parse-integer}  @i{string @r{&key} start end radix junk-allowed} @result{}  @i{integer, pos}
 
4084
 
 
4085
@subsubheading  Arguments and Values::
 
4086
 
 
4087
@i{string}---a @i{string}.
 
4088
 
 
4089
@i{start}, @i{end}---@i{bounding index designators} of @i{string}.
 
4090
 The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.
 
4091
 
 
4092
@i{radix}---a @i{radix}.
 
4093
 The default is @t{10}.
 
4094
 
 
4095
@i{junk-allowed}---a @i{generalized boolean}.
 
4096
 The default is @i{false}.
 
4097
 
 
4098
@i{integer}---an @i{integer} or @i{false}.
 
4099
 
 
4100
@i{pos}---a @i{bounding index} of @i{string}.
 
4101
 
 
4102
@subsubheading  Description::
 
4103
 
 
4104
@b{parse-integer} parses an @i{integer} in the specified @i{radix}
 
4105
from the substring of @i{string} delimited by @i{start} and @i{end}.
 
4106
 
 
4107
@b{parse-integer} expects an optional sign (@t{+} or @t{-}) followed by
 
4108
a a non-empty sequence of digits to be interpreted in the specified @i{radix}.
 
4109
Optional leading and trailing @i{whitespace}_1 is ignored.
 
4110
 
 
4111
@b{parse-integer} does not recognize the syntactic radix-specifier
 
4112
prefixes @t{#O}, @t{#B}, @t{#X}, and @t{#@i{n}R}, 
 
4113
nor does it recognize a trailing decimal point.
 
4114
 
 
4115
If @i{junk-allowed} is @i{false}, an error of @i{type} @b{parse-error} is 
 
4116
signaled if substring does not consist entirely of the representation of a 
 
4117
signed @i{integer}, possibly surrounded on either side by @i{whitespace}_1 
 
4118
@i{characters}.
 
4119
 
 
4120
The first @i{value} returned is either
 
4121
    the @i{integer} that was parsed,
 
4122
 or else @b{nil} if no syntactically correct @i{integer} 
 
4123
    was seen but @i{junk-allowed} was @i{true}.
 
4124
 
 
4125
The second @i{value} is either 
 
4126
    the index into the @i{string} of the delimiter that terminated the parse,
 
4127
 or the upper @i{bounding index} of the substring if the parse terminated at
 
4128
    the end of the substring (as is always the case if @i{junk-allowed} 
 
4129
    is @i{false}).
 
4130
 
 
4131
@subsubheading  Examples::
 
4132
@example
 
4133
 (parse-integer "123") @result{}  123, 3
 
4134
 (parse-integer "123" :start 1 :radix 5) @result{}  13, 3
 
4135
 (parse-integer "no-integer" :junk-allowed t) @result{}  NIL, 0
 
4136
@end example
 
4137
 
 
4138
@subsubheading  Exceptional Situations::
 
4139
 
 
4140
If @i{junk-allowed} is @i{false}, 
 
4141
an error is signaled if substring does not consist entirely of
 
4142
the representation of an @i{integer}, 
 
4143
possibly surrounded on either side by
 
4144
@i{whitespace}_1 characters.
 
4145
 
 
4146
@node boole, boole-1, parse-integer, Numbers Dictionary
 
4147
@subsection boole                                                            [Function]
 
4148
 
 
4149
@code{boole}  @i{op integer-1 integer-2} @result{}  @i{result-integer}
 
4150
 
 
4151
@subsubheading  Arguments and Values:: 
 
4152
 
 
4153
@i{Op}---a @i{bit-wise logical operation specifier}.
 
4154
 
 
4155
@i{integer-1}---an @i{integer}.
 
4156
 
 
4157
@i{integer-2}---an @i{integer}.
 
4158
 
 
4159
@i{result-integer}---an @i{integer}.
 
4160
 
 
4161
@subsubheading  Description::
 
4162
 
 
4163
@b{boole} performs bit-wise logical operations on
 
4164
@i{integer-1} and @i{integer-2}, which are treated as if
 
4165
they were binary and in two's complement representation.
 
4166
 
 
4167
The operation to be performed and the return value are determined by 
 
4168
@i{op}.  
 
4169
 
 
4170
@b{boole} returns the values 
 
4171
specified for any @i{op} in Figure 12--16.
 
4172
 
 
4173
 
 
4174
 
 
4175
@format
 
4176
@group
 
4177
@noindent
 
4178
@w{  Op           Result                                      }
 
4179
@w{  @b{boole-1}      @i{integer-1}                                   }
 
4180
@w{  @b{boole-2}      @i{integer-2}                                   }
 
4181
@w{  @b{boole-andc1}  and complement of @i{integer-1} with @i{integer-2}  }
 
4182
@w{  @b{boole-andc2}  and @i{integer-1} with complement of @i{integer-2}  }
 
4183
@w{  @b{boole-and}    and                                         }
 
4184
@w{  @b{boole-c1}     complement of @i{integer-1}                     }
 
4185
@w{  @b{boole-c2}     complement of @i{integer-2}                     }
 
4186
@w{  @b{boole-clr}    always 0 (all zero bits)                    }
 
4187
@w{  @b{boole-eqv}    equivalence (exclusive nor)                 }
 
4188
@w{  @b{boole-ior}    inclusive or                                }
 
4189
@w{  @b{boole-nand}   not-and                                     }
 
4190
@w{  @b{boole-nor}    not-or                                      }
 
4191
@w{  @b{boole-orc1}   or complement of @i{integer-1} with @i{integer-2}   }
 
4192
@w{  @b{boole-orc2}   or @i{integer-1} with complement of @i{integer-2}   }
 
4193
@w{  @b{boole-set}    always -1 (all one bits)                    }
 
4194
@w{  @b{boole-xor}    exclusive or                                }
 
4195
 
 
4196
@noindent
 
4197
@w{         Figure 12--16: Bit-Wise Logical Operations        }
 
4198
 
 
4199
@end group
 
4200
@end format
 
4201
 
 
4202
 
 
4203
 
 
4204
@subsubheading  Examples::
 
4205
 
 
4206
@example
 
4207
 (boole boole-ior 1 16) @result{}  17
 
4208
 (boole boole-and -2 5) @result{}  4
 
4209
 (boole boole-eqv 17 15) @result{}  -31
 
4210
 
 
4211
;;; These examples illustrate the result of applying BOOLE and each
 
4212
;;; of the possible values of OP to each possible combination of bits.
 
4213
 (progn
 
4214
   (format t "~&Results of (BOOLE <op> #b0011 #b0101) ...~
 
4215
           ~
 
4216
   (dolist (symbol '(boole-1     boole-2    boole-and  boole-andc1
 
4217
                     boole-andc2 boole-c1   boole-c2   boole-clr
 
4218
                     boole-eqv   boole-ior  boole-nand boole-nor
 
4219
                     boole-orc1  boole-orc2 boole-set  boole-xor))
 
4220
     (let ((result (boole (symbol-value symbol) #b0011 #b0101)))
 
4221
       (format t "~& ~A~13T~3,' D~23T~:*~5,' B~31T ...~4,'0B~
 
4222
               symbol result (logand result #b1111)))))
 
4223
@t{ |> } Results of (BOOLE <op> #b0011 #b0101) ...
 
4224
@t{ |> } ---Op-------Decimal-----Binary----Bits---
 
4225
@t{ |> }  BOOLE-1       3          11    ...0011
 
4226
@t{ |> }  BOOLE-2       5         101    ...0101
 
4227
@t{ |> }  BOOLE-AND     1           1    ...0001
 
4228
@t{ |> }  BOOLE-ANDC1   4         100    ...0100
 
4229
@t{ |> }  BOOLE-ANDC2   2          10    ...0010
 
4230
@t{ |> }  BOOLE-C1     -4        -100    ...1100
 
4231
@t{ |> }  BOOLE-C2     -6        -110    ...1010
 
4232
@t{ |> }  BOOLE-CLR     0           0    ...0000
 
4233
@t{ |> }  BOOLE-EQV    -7        -111    ...1001
 
4234
@t{ |> }  BOOLE-IOR     7         111    ...0111
 
4235
@t{ |> }  BOOLE-NAND   -2         -10    ...1110
 
4236
@t{ |> }  BOOLE-NOR    -8       -1000    ...1000
 
4237
@t{ |> }  BOOLE-ORC1   -3         -11    ...1101
 
4238
@t{ |> }  BOOLE-ORC2   -5        -101    ...1011
 
4239
@t{ |> }  BOOLE-SET    -1          -1    ...1111
 
4240
@t{ |> }  BOOLE-XOR     6         110    ...0110
 
4241
@result{}  NIL
 
4242
@end example
 
4243
 
 
4244
@subsubheading  Exceptional Situations::
 
4245
 
 
4246
Should signal @b{type-error} if its first argument is not a 
 
4247
@i{bit-wise logical operation specifier} or if any subsequent argument is not
 
4248
an @i{integer}.
 
4249
 
 
4250
@subsubheading  See Also::
 
4251
 
 
4252
@ref{logand}
 
4253
 
 
4254
@subsubheading  Notes::  
 
4255
 
 
4256
In general,
 
4257
 
 
4258
@example
 
4259
 (boole boole-and x y) @equiv{} (logand x y)
 
4260
@end example
 
4261
 
 
4262
@i{Programmers} who would prefer to use numeric indices rather than 
 
4263
@i{bit-wise logical operation specifiers} can get an equivalent effect
 
4264
by a technique such as the following:
 
4265
 
 
4266
@example
 
4267
;; The order of the values in this `table' are such that
 
4268
;; (logand (boole (elt boole-n-vector n) #b0101 #b0011) #b1111) => n
 
4269
 (defconstant boole-n-vector
 
4270
    (vector boole-clr   boole-and  boole-andc1 boole-2
 
4271
            boole-andc2 boole-1    boole-xor   boole-ior
 
4272
            boole-nor   boole-eqv  boole-c1    boole-orc1
 
4273
            boole-c2    boole-orc2 boole-nand  boole-set))
 
4274
@result{}  BOOLE-N-VECTOR
 
4275
 (proclaim '(inline boole-n))
 
4276
@result{}  @i{implementation-dependent}
 
4277
 (defun boole-n (n integer &rest more-integers)
 
4278
   (apply #'boole (elt boole-n-vector n) integer more-integers))
 
4279
@result{}  BOOLE-N
 
4280
 (boole-n #b0111 5 3) @result{}  7
 
4281
 (boole-n #b0001 5 3) @result{}  1
 
4282
 (boole-n #b1101 5 3) @result{}  -3
 
4283
 (loop for n from #b0000 to #b1111 collect (boole-n n 5 3))
 
4284
@result{}  (0 1 2 3 4 5 6 7 -8 -7 -6 -5 -4 -3 -2 -1)
 
4285
@end example
 
4286
 
 
4287
@node boole-1, logand, boole, Numbers Dictionary
 
4288
@subsection boole-1,    boole-2,   boole-and,  boole-andc1, boole-andc2,
 
4289
@subheading boole-c1,   boole-c2,  boole-clr,  boole-eqv,   boole-ior,
 
4290
@subheading boole-nand, boole-nor, boole-orc1, boole-orc2,  boole-set, 
 
4291
@subheading boole-xor
 
4292
@flushright
 
4293
@i{[Constant Variable]}
 
4294
@end flushright
 
4295
 
 
4296
@subsubheading  Constant Value::
 
4297
 
 
4298
The identity and nature of the @i{values} of each of these @i{variables} 
 
4299
is @i{implementation-dependent},
 
4300
except that it must be @i{distinct} from each of the @i{values} of the others,
 
4301
and it must be a valid first @i{argument} to the @i{function} @b{boole}.
 
4302
 
 
4303
@subsubheading  Description::
 
4304
 
 
4305
Each of these @i{constants} has a @i{value} which is one of the 
 
4306
sixteen possible @i{bit-wise logical operation specifiers}.
 
4307
 
 
4308
@subsubheading  Examples::
 
4309
@example
 
4310
 (boole boole-ior 1 16) @result{}  17
 
4311
 (boole boole-and -2 5) @result{}  4
 
4312
 (boole boole-eqv 17 15) @result{}  -31
 
4313
@end example
 
4314
 
 
4315
@subsubheading  See Also::
 
4316
 
 
4317
@ref{boole}
 
4318
 
 
4319
@node logand, logbitp, boole-1, Numbers Dictionary
 
4320
@subsection logand,  logandc1, logandc2, logeqv,  logior,
 
4321
@subheading lognand, lognor,   lognot,   logorc1, logorc2,
 
4322
@subheading logxor
 
4323
@flushright
 
4324
@i{[Function]}
 
4325
@end flushright
 
4326
 
 
4327
@code{logand}  @i{@r{&rest} integers} @result{}  @i{result-integer}
 
4328
 
 
4329
@code{logandc}  @i{1} @result{}  @i{integer-1 integer-2}
 
4330
 @r{result-integer}
 
4331
@code{logandc}  @i{2} @result{}  @i{integer-1 integer-2}
 
4332
 @r{result-integer}
 
4333
@code{logeqv}  @i{@r{&rest} integers} @result{}  @i{result-integer}
 
4334
 
 
4335
@code{logior}  @i{@r{&rest} integers} @result{}  @i{result-integer}
 
4336
 
 
4337
@code{lognand}  @i{integer-1 integer-2} @result{}  @i{result-integer}
 
4338
 
 
4339
@code{lognor}  @i{integer-1 integer-2} @result{}  @i{result-integer}
 
4340
 
 
4341
@code{lognot}  @i{integer} @result{}  @i{result-integer}
 
4342
 
 
4343
@code{logorc}  @i{1} @result{}  @i{integer-1 integer-2}
 
4344
 @r{result-integer}
 
4345
@code{logorc}  @i{2} @result{}  @i{integer-1 integer-2}
 
4346
 @r{result-integer}
 
4347
@code{logxor}  @i{@r{&rest} integers} @result{}  @i{result-integer}
 
4348
 
 
4349
@subsubheading  Arguments and Values::
 
4350
 
 
4351
@i{integers}---@i{integers}.
 
4352
 
 
4353
@i{integer}---an @i{integer}.
 
4354
 
 
4355
@i{integer-1}---an @i{integer}.
 
4356
 
 
4357
@i{integer-2}---an @i{integer}.
 
4358
 
 
4359
@i{result-integer}---an @i{integer}.
 
4360
 
 
4361
@subsubheading  Description::
 
4362
 
 
4363
The @i{functions}
 
4364
       @b{logandc1},
 
4365
       @b{logandc2},
 
4366
       @b{logand},
 
4367
       @b{logeqv},
 
4368
       @b{logior},
 
4369
       @b{lognand},
 
4370
       @b{lognor}, 
 
4371
       @b{lognot},
 
4372
       @b{logorc1}, 
 
4373
       @b{logorc2},
 
4374
   and @b{logxor}
 
4375
perform bit-wise logical operations on their @i{arguments},
 
4376
that are treated as if they were binary.
 
4377
 
 
4378
Figure 12--17 lists the meaning of each of the @i{functions}.
 
4379
Where an `identity' is shown, it indicates the @i{value} @i{yielded}
 
4380
by the @i{function} when no @i{arguments} are supplied.
 
4381
 
 
4382
@format
 
4383
@group
 
4384
@noindent
 
4385
@w{  Function  Identity  Operation performed                         }
 
4386
@w{  @b{logandc1}  ---       and complement of @i{integer-1} with @i{integer-2}  }
 
4387
@w{  @b{logandc2}  ---       and @i{integer-1} with complement of @i{integer-2}  }
 
4388
@w{  @b{logand}    @t{-1}        and                                         }
 
4389
@w{  @b{logeqv}    @t{-1}        equivalence (exclusive nor)                 }
 
4390
@w{  @b{logior}    @t{0}         inclusive or                                }
 
4391
@w{  @b{lognand}   ---       complement of @i{integer-1} and @i{integer-2}       }
 
4392
@w{  @b{lognor}    ---       complement of @i{integer-1} or @i{integer-2}        }
 
4393
@w{  @b{lognot}    ---       complement                                  }
 
4394
@w{  @b{logorc1}   ---       or complement of @i{integer-1} with @i{integer-2}   }
 
4395
@w{  @b{logorc2}   ---       or @i{integer-1} with complement of @i{integer-2}   }
 
4396
@w{  @b{logxor}    @t{0}         exclusive or                                }
 
4397
 
 
4398
@noindent
 
4399
@w{       Figure 12--17: Bit-wise Logical Operations on Integers     }
 
4400
 
 
4401
@end group
 
4402
@end format
 
4403
 
 
4404
Negative @i{integers} are treated as if they were in two's-complement notation.
 
4405
 
 
4406
@subsubheading  Examples::
 
4407
 
 
4408
@example
 
4409
 (logior 1 2 4 8) @result{}  15
 
4410
 (logxor 1 3 7 15) @result{}  10
 
4411
 (logeqv) @result{}  -1
 
4412
 (logand 16 31) @result{}  16
 
4413
 (lognot 0) @result{}  -1
 
4414
 (lognot 1) @result{}  -2
 
4415
 (lognot -1) @result{}  0
 
4416
 (lognot (1+ (lognot 1000))) @result{}  999
 
4417
 
 
4418
;;; In the following example, m is a mask.  For each bit in
 
4419
;;; the mask that is a 1, the corresponding bits in x and y are
 
4420
;;; exchanged.  For each bit in the mask that is a 0, the 
 
4421
;;; corresponding bits of x and y are left unchanged.
 
4422
 (flet ((show (m x y)
 
4423
          (format t "~
 
4424
                  m x y)))
 
4425
   (let ((m #o007750)
 
4426
         (x #o452576)
 
4427
         (y #o317407))
 
4428
     (show m x y)
 
4429
     (let ((z (logand (logxor x y) m)))
 
4430
       (setq x (logxor z x))
 
4431
       (setq y (logxor z y))
 
4432
       (show m x y))))
 
4433
@t{ |> } m = #o007750
 
4434
@t{ |> } x = #o452576
 
4435
@t{ |> } y = #o317407
 
4436
@t{ |> } 
 
4437
@t{ |> } m = #o007750
 
4438
@t{ |> } x = #o457426
 
4439
@t{ |> } y = #o312557
 
4440
@result{}  NIL
 
4441
@end example
 
4442
 
 
4443
@subsubheading  Exceptional Situations::
 
4444
 
 
4445
Should signal @b{type-error} if any argument is not an @i{integer}.
 
4446
 
 
4447
@subsubheading  See Also::
 
4448
 
 
4449
@ref{boole}
 
4450
 
 
4451
@subsubheading  Notes::
 
4452
 
 
4453
@t{(logbitp @i{k} -1)} returns @i{true} for all values of @i{k}.
 
4454
 
 
4455
Because the following functions are not associative,
 
4456
they take exactly two arguments rather than any number
 
4457
of arguments.
 
4458
 
 
4459
@example
 
4460
 (lognand @i{n1} @i{n2}) @equiv{} (lognot (logand @i{n1} @i{n2}))
 
4461
 (lognor @i{n1} @i{n2}) @equiv{} (lognot (logior @i{n1} @i{n2}))
 
4462
 (logandc1 @i{n1} @i{n2}) @equiv{} (logand (lognot @i{n1}) @i{n2})
 
4463
 (logandc2 @i{n1} @i{n2}) @equiv{} (logand @i{n1} (lognot @i{n2}))
 
4464
 (logiorc1 @i{n1} @i{n2}) @equiv{} (logior (lognot @i{n1}) @i{n2})
 
4465
 (logiorc2 @i{n1} @i{n2}) @equiv{} (logior @i{n1} (lognot @i{n2}))
 
4466
 (logbitp @i{j} (lognot @i{x})) @equiv{} (not (logbitp @i{j} @i{x}))
 
4467
@end example
 
4468
 
 
4469
@node logbitp, logcount, logand, Numbers Dictionary
 
4470
@subsection logbitp                                                          [Function]
 
4471
 
 
4472
@code{logbitp}  @i{index integer} @result{}  @i{generalized-boolean}
 
4473
 
 
4474
@subsubheading  Arguments and Values::
 
4475
 
 
4476
@i{index}---a non-negative @i{integer}.
 
4477
 
 
4478
@i{integer}---an @i{integer}.
 
4479
 
 
4480
@i{generalized-boolean}---a @i{generalized boolean}.
 
4481
 
 
4482
@subsubheading  Description::
 
4483
 
 
4484
@b{logbitp} is used to test the value of a particular bit 
 
4485
in @i{integer}, that is treated as if it were binary.
 
4486
The value of @b{logbitp} is @i{true} if the bit in @i{integer} 
 
4487
whose index is @i{index} (that is, its weight is 2^@i{index}) 
 
4488
is a one-bit; otherwise it is @i{false}.
 
4489
 
 
4490
Negative @i{integers} are treated as if they were in 
 
4491
two's-complement notation.
 
4492
 
 
4493
@subsubheading  Examples::
 
4494
@example
 
4495
 (logbitp 1 1) @result{}  @i{false}
 
4496
 (logbitp 0 1) @result{}  @i{true}
 
4497
 (logbitp 3 10) @result{}  @i{true}
 
4498
 (logbitp 1000000 -1) @result{}  @i{true}
 
4499
 (logbitp 2 6) @result{}  @i{true}
 
4500
 (logbitp 0 6) @result{}  @i{false}
 
4501
@end example
 
4502
 
 
4503
@subsubheading  Exceptional Situations::
 
4504
 
 
4505
Should signal an error of @i{type} @b{type-error}
 
4506
                              if @i{index} is not a non-negative @i{integer}.
 
4507
Should signal an error of @i{type} @b{type-error}
 
4508
                              if @i{integer} is not an @i{integer}.
 
4509
 
 
4510
@subsubheading  Notes::
 
4511
 
 
4512
@example
 
4513
 (logbitp @i{k} @i{n}) @equiv{} (ldb-test (byte 1 @i{k}) @i{n})
 
4514
@end example
 
4515
 
 
4516
@node logcount, logtest, logbitp, Numbers Dictionary
 
4517
@subsection logcount                                                         [Function]
 
4518
 
 
4519
@code{logcount}  @i{integer} @result{}  @i{number-of-on-bits}
 
4520
 
 
4521
@subsubheading  Arguments and Values:: 
 
4522
 
 
4523
@i{integer}---an @i{integer}.
 
4524
 
 
4525
@i{number-of-on-bits}---a non-negative @i{integer}.
 
4526
 
 
4527
@subsubheading  Description::
 
4528
 
 
4529
Computes and returns the number of bits 
 
4530
in the two's-complement binary representation of @i{integer}
 
4531
that are `on' or `set'.
 
4532
If @i{integer} is negative, the @t{0} bits are counted;
 
4533
otherwise, the @t{1} bits are counted.
 
4534
 
 
4535
@subsubheading  Examples::
 
4536
 
 
4537
@example
 
4538
 (logcount 0) @result{}  0
 
4539
 (logcount -1) @result{}  0
 
4540
 (logcount 7) @result{}  3
 
4541
 (logcount  13) @result{}  3 ;Two's-complement binary: ...0001101
 
4542
 (logcount -13) @result{}  2 ;Two's-complement binary: ...1110011
 
4543
 (logcount  30) @result{}  4 ;Two's-complement binary: ...0011110
 
4544
 (logcount -30) @result{}  4 ;Two's-complement binary: ...1100010
 
4545
 (logcount (expt 2 100)) @result{}  1
 
4546
 (logcount (- (expt 2 100))) @result{}  100
 
4547
 (logcount (- (1+ (expt 2 100)))) @result{}  1
 
4548
@end example
 
4549
 
 
4550
@subsubheading  Exceptional Situations::
 
4551
 
 
4552
Should signal @b{type-error} if its argument is not an @i{integer}.
 
4553
 
 
4554
@subsubheading  Notes::
 
4555
 
 
4556
Even if the @i{implementation} does not represent @i{integers} internally
 
4557
in two's complement binary, @b{logcount} behaves as if it did.
 
4558
 
 
4559
The following identity always holds:
 
4560
 
 
4561
@example
 
4562
    (logcount @i{x})
 
4563
 @equiv{} (logcount (- (+ @i{x} 1)))
 
4564
 @equiv{} (logcount (lognot @i{x}))
 
4565
@end example
 
4566
 
 
4567
@node logtest, byte, logcount, Numbers Dictionary
 
4568
@subsection logtest                                                          [Function]
 
4569
 
 
4570
@code{logtest}  @i{integer-1 integer-2} @result{}  @i{generalized-boolean}
 
4571
 
 
4572
@subsubheading  Arguments and Values::
 
4573
 
 
4574
@i{integer-1}---an @i{integer}.
 
4575
 
 
4576
@i{integer-2}---an @i{integer}.
 
4577
 
 
4578
@i{generalized-boolean}---a @i{generalized boolean}.
 
4579
 
 
4580
@subsubheading  Description::
 
4581
 
 
4582
Returns @i{true} if any of the bits designated by the 1's 
 
4583
in @i{integer-1} is 1 in @i{integer-2};
 
4584
otherwise it is @i{false}.
 
4585
@i{integer-1} and @i{integer-2} are treated as if they were binary.
 
4586
 
 
4587
Negative @i{integer-1} and @i{integer-2} are treated as if
 
4588
they were represented in two's-complement binary.
 
4589
 
 
4590
@subsubheading  Examples::
 
4591
 
 
4592
@example
 
4593
 (logtest 1 7) @result{}  @i{true}
 
4594
 (logtest 1 2) @result{}  @i{false}
 
4595
 (logtest -2 -1) @result{}  @i{true}
 
4596
 (logtest 0 -1) @result{}  @i{false}
 
4597
@end example
 
4598
 
 
4599
@subsubheading  Exceptional Situations::
 
4600
 
 
4601
Should signal an error of @i{type} @b{type-error}
 
4602
                              if @i{integer-1} is not an @i{integer}.
 
4603
Should signal an error of @i{type} @b{type-error}
 
4604
                              if @i{integer-2} is not an @i{integer}.
 
4605
 
 
4606
@subsubheading  Notes::
 
4607
 
 
4608
@example
 
4609
 (logtest @i{x} @i{y}) @equiv{} (not (zerop (logand @i{x} @i{y})))
 
4610
@end example
 
4611
 
 
4612
@node byte, deposit-field, logtest, Numbers Dictionary
 
4613
@subsection byte, byte-size, byte-position                                   [Function]
 
4614
 
 
4615
@code{byte}  @i{size position} @result{}  @i{bytespec}
 
4616
 
 
4617
@code{byte-size}  @i{bytespec} @result{}  @i{size}
 
4618
 
 
4619
@code{byte-position}  @i{bytespec} @result{}  @i{position}
 
4620
 
 
4621
@subsubheading  Arguments and Values::
 
4622
 
 
4623
@i{size}, @i{position}---a non-negative @i{integer}.
 
4624
 
 
4625
@i{bytespec}---a @i{byte specifier}.
 
4626
 
 
4627
@subsubheading  Description::
 
4628
 
 
4629
@b{byte} returns a @i{byte specifier} that indicates
 
4630
a @i{byte} of width @i{size} and whose bits have weights            
 
4631
2^@i{@i{position} + @i{size} - 1\/} through 2^@i{position},
 
4632
and whose representation is
 
4633
@i{implementation-dependent}.                 
 
4634
 
 
4635
@b{byte-size} returns the number of bits specified by @i{bytespec}.
 
4636
 
 
4637
@b{byte-position} returns the position specified by @i{bytespec}.
 
4638
 
 
4639
@subsubheading  Examples::
 
4640
 
 
4641
@example
 
4642
 (setq b (byte 100 200)) @result{}  #<BYTE-SPECIFIER size 100 position 200>
 
4643
 (byte-size b) @result{}  100
 
4644
 (byte-position b) @result{}  200
 
4645
@end example
 
4646
 
 
4647
@subsubheading  See Also::
 
4648
 
 
4649
@ref{ldb}
 
4650
 
4651
@ref{dpb}
 
4652
 
 
4653
@subsubheading  Notes::
 
4654
 
 
4655
@example
 
4656
 (byte-size (byte @i{j} @i{k})) @equiv{} @i{j}
 
4657
 (byte-position (byte @i{j} @i{k})) @equiv{} @i{k}
 
4658
@end example
 
4659
 
 
4660
A @i{byte} of @i{size} of @t{0} is permissible; 
 
4661
it refers to a @i{byte} of width zero.  For example,
 
4662
 
 
4663
@example
 
4664
 (ldb (byte 0 3) #o7777) @result{}  0
 
4665
 (dpb #o7777 (byte 0 3) 0) @result{}  0
 
4666
@end example
 
4667
 
 
4668
@node deposit-field, dpb, byte, Numbers Dictionary
 
4669
@subsection deposit-field                                                    [Function]
 
4670
 
 
4671
@code{deposit-field}  @i{newbyte bytespec integer} @result{}  @i{result-integer}
 
4672
 
 
4673
@subsubheading  Arguments and Values::
 
4674
 
 
4675
@i{newbyte}---an @i{integer}.
 
4676
 
 
4677
@i{bytespec}---a @i{byte specifier}.
 
4678
 
 
4679
@i{integer}---an @i{integer}.
 
4680
 
 
4681
@i{result-integer}---an @i{integer}.
 
4682
 
 
4683
@subsubheading  Description::
 
4684
 
 
4685
Replaces a field of bits within @i{integer}; specifically,
 
4686
returns an @i{integer} that contains the bits of @i{newbyte}
 
4687
within the @i{byte} specified by @i{bytespec},
 
4688
and elsewhere contains the bits of @i{integer}.  
 
4689
 
 
4690
@subsubheading  Examples::
 
4691
 
 
4692
@example
 
4693
 (deposit-field 7 (byte 2 1) 0) @result{}  6
 
4694
 (deposit-field -1 (byte 4 0) 0) @result{}  15
 
4695
 (deposit-field 0 (byte 2 1) -3) @result{}  -7
 
4696
@end example
 
4697
 
 
4698
@subsubheading  See Also::
 
4699
 
 
4700
@ref{byte}
 
4701
,
 
4702
@ref{dpb}
 
4703
 
 
4704
@subsubheading  Notes::
 
4705
 
 
4706
@example
 
4707
 (logbitp @i{j} (deposit-field @i{m} (byte @i{s} @i{p}) @i{n}))
 
4708
 @equiv{} (if (and (>= @i{j} @i{p}) (< @i{j} (+ @i{p} @i{s})))
 
4709
        (logbitp @i{j} @i{m})
 
4710
        (logbitp @i{j} @i{n}))
 
4711
@end example
 
4712
 
 
4713
   @b{deposit-field} is to @b{mask-field} 
 
4714
as @b{dpb}           is to @b{ldb}.
 
4715
 
 
4716
@node dpb, ldb, deposit-field, Numbers Dictionary
 
4717
@subsection dpb                                                              [Function]
 
4718
 
 
4719
@code{dpb}  @i{newbyte bytespec integer} @result{}  @i{result-integer}
 
4720
 
 
4721
@subsubheading  Pronunciation::
 
4722
 
 
4723
    pronounced ,de  'pib 
 
4724
 or pronounced ,de  'pe b 
 
4725
 or pronounced 'd\=e 'p\=e 'b\=e 
 
4726
 
 
4727
@subsubheading  Arguments and Values::
 
4728
 
 
4729
@i{newbyte}---an @i{integer}.
 
4730
 
 
4731
@i{bytespec}---a @i{byte specifier}.
 
4732
 
 
4733
@i{integer}---an @i{integer}.
 
4734
 
 
4735
@i{result-integer}---an @i{integer}.
 
4736
 
 
4737
@subsubheading  Description::
 
4738
 
 
4739
@b{dpb} (deposit byte) is used to 
 
4740
replace a field of bits within @i{integer}.  
 
4741
@b{dpb} returns an @i{integer} that is 
 
4742
the same as @i{integer} except in the bits specified by @i{bytespec}.
 
4743
 
 
4744
Let @t{s} be the size specified
 
4745
by @i{bytespec}; then the low @t{s} bits of @i{newbyte} appear in
 
4746
the result in the byte specified by @i{bytespec}.
 
4747
@i{Newbyte} is interpreted as
 
4748
being right-justified, as if it were the result of @b{ldb}.
 
4749
 
 
4750
@subsubheading  Examples::
 
4751
 
 
4752
@example
 
4753
 (dpb 1 (byte 1 10) 0) @result{}  1024
 
4754
 (dpb -2 (byte 2 10) 0) @result{}  2048
 
4755
 (dpb 1 (byte 2 10) 2048) @result{}  1024
 
4756
@end example
 
4757
 
 
4758
@subsubheading  See Also::
 
4759
 
 
4760
@ref{byte}
 
4761
 
4762
@ref{deposit-field}
 
4763
 
4764
@ref{ldb}
 
4765
 
 
4766
@subsubheading  Notes::
 
4767
 
 
4768
@example
 
4769
 (logbitp @i{j} (dpb @i{m} (byte @i{s} @i{p}) @i{n}))
 
4770
 @equiv{} (if (and (>= @i{j} @i{p}) (< @i{j} (+ @i{p} @i{s})))
 
4771
        (logbitp (- @i{j} @i{p}) @i{m})
 
4772
        (logbitp @i{j} @i{n}))
 
4773
@end example
 
4774
 
 
4775
In general,
 
4776
 
 
4777
@example
 
4778
 (dpb @i{x} (byte 0 @i{y}) @i{z}) @result{}  @i{z}
 
4779
@end example
 
4780
 
 
4781
for all valid values of @i{x}, @i{y}, and @i{z}.
 
4782
 
 
4783
Historically, the name ``dpb'' comes from a DEC PDP-10 assembly language
 
4784
instruction meaning ``deposit byte.''
 
4785
 
 
4786
@node ldb, ldb-test, dpb, Numbers Dictionary
 
4787
@subsection ldb                                                              [Accessor]
 
4788
 
 
4789
@code{ldb}  @i{bytespec integer} @result{}  @i{byte}
 
4790
 
 
4791
(setf (@code{ ldb} @i{bytespec place}) new-byte)@*
 
4792
 
 
4793
@subsubheading  Pronunciation::
 
4794
 
 
4795
    pronounced 'lid ib
 
4796
 or pronounced 'lid e b
 
4797
 or pronounced 'el 'd\=e 'b\=e 
 
4798
 
 
4799
@subsubheading  Arguments and Values::
 
4800
 
 
4801
@i{bytespec}---a @i{byte specifier}.
 
4802
 
 
4803
@i{integer}---an @i{integer}.
 
4804
 
 
4805
@i{byte}, @i{new-byte}---a non-negative @i{integer}.
 
4806
 
 
4807
@subsubheading  Description::
 
4808
 
 
4809
@b{ldb} extracts and returns the @i{byte} of @i{integer}
 
4810
specified by @i{bytespec}.
 
4811
 
 
4812
@b{ldb} returns an @i{integer} in which the bits with weights 
 
4813
2^@i{(@i{s}-1)} through 2^0 are the same as those in 
 
4814
@i{integer} with weights 2^@i{(@i{p}+@i{s}-1)} 
 
4815
through 2^@i{p}, and all other bits zero; @i{s} is
 
4816
@t{(byte-size @i{bytespec})} 
 
4817
and @i{p} is @t{(byte-position @i{bytespec})}.
 
4818
 
 
4819
@b{setf} may be used with @b{ldb} to modify
 
4820
a byte within the @i{integer} that is stored
 
4821
in a given @i{place}.
 
4822
 
 
4823
The order of evaluation, when an @b{ldb} form is supplied
 
4824
to @b{setf}, is exactly left-to-right.
 
4825
 
 
4826
@ITindex{order of evaluation}
 
4827
 
 
4828
@ITindex{evaluation order}
 
4829
 
 
4830
The effect is to perform a @b{dpb} operation
 
4831
and then store the result back into the @i{place}.
 
4832
 
 
4833
@subsubheading  Examples::
 
4834
 
 
4835
@example
 
4836
 (ldb (byte 2 1) 10) @result{}  1
 
4837
 (setq a (list 8)) @result{}  (8)
 
4838
 (setf (ldb (byte 2 1) (car a)) 1) @result{}  1
 
4839
 a @result{}  (10)
 
4840
@end example
 
4841
 
 
4842
@subsubheading  See Also::
 
4843
 
 
4844
@ref{byte}
 
4845
,
 
4846
@b{byte-position},
 
4847
@b{byte-size},
 
4848
@ref{dpb}
 
4849
 
 
4850
@subsubheading  Notes::
 
4851
 
 
4852
@example
 
4853
 (logbitp @i{j} (ldb (byte @i{s} @i{p}) @i{n}))
 
4854
    @equiv{} (and (< @i{j} @i{s}) (logbitp (+ @i{j} @i{p}) @i{n}))
 
4855
@end example
 
4856
 
 
4857
In general,
 
4858
 
 
4859
@example
 
4860
 (ldb (byte 0 @i{x}) @i{y}) @result{}  0
 
4861
@end example
 
4862
 
 
4863
for all valid values of @i{x} and @i{y}.
 
4864
 
 
4865
Historically, the name ``ldb'' comes from a DEC PDP-10 assembly language
 
4866
instruction meaning ``load byte.''
 
4867
 
 
4868
@node ldb-test, mask-field, ldb, Numbers Dictionary
 
4869
@subsection ldb-test                                                         [Function]
 
4870
 
 
4871
@code{ldb-test}  @i{bytespec integer} @result{}  @i{generalized-boolean}
 
4872
 
 
4873
@subsubheading  Arguments and Values::
 
4874
 
 
4875
@i{bytespec}---a @i{byte specifier}.
 
4876
 
 
4877
@i{integer}---an @i{integer}.
 
4878
 
 
4879
@i{generalized-boolean}---a @i{generalized boolean}.
 
4880
 
 
4881
@subsubheading  Description::
 
4882
 
 
4883
Returns @i{true} if any of the bits of the byte in @i{integer}
 
4884
specified by @i{bytespec} is non-zero; otherwise returns @i{false}.
 
4885
 
 
4886
@subsubheading  Examples::
 
4887
 
 
4888
@example
 
4889
 (ldb-test (byte 4 1) 16) @result{}  @i{true}
 
4890
 (ldb-test (byte 3 1) 16) @result{}  @i{false}
 
4891
 (ldb-test (byte 3 2) 16) @result{}  @i{true}
 
4892
@end example
 
4893
 
 
4894
@subsubheading  See Also::
 
4895
 
 
4896
@ref{byte}
 
4897
 
4898
@ref{ldb}
 
4899
 
4900
@ref{zerop}
 
4901
 
 
4902
@subsubheading  Notes::
 
4903
@example
 
4904
 (ldb-test bytespec n) @equiv{}
 
4905
 (not (zerop (ldb bytespec n))) @equiv{}
 
4906
 (logtest (ldb bytespec -1) n)
 
4907
@end example
 
4908
 
 
4909
@node mask-field, most-positive-fixnum, ldb-test, Numbers Dictionary
 
4910
@subsection mask-field                                                       [Accessor]
 
4911
 
 
4912
@code{mask-field}  @i{bytespec integer} @result{}  @i{masked-integer}
 
4913
 
 
4914
(setf (@code{         mask-field} @i{bytespec place}) new-masked-integer)@*
 
4915
 
 
4916
@subsubheading  Arguments and Values::
 
4917
 
 
4918
@i{bytespec}---a @i{byte specifier}.
 
4919
 
 
4920
@i{integer}---an @i{integer}.
 
4921
 
 
4922
@i{masked-integer}, @i{new-masked-integer}---a non-negative @i{integer}.
 
4923
 
 
4924
@subsubheading  Description::
 
4925
 
 
4926
@b{mask-field} performs a ``mask'' operation on @i{integer}.
 
4927
It returns an @i{integer} that has the same bits as @i{integer} in 
 
4928
the @i{byte} specified by @i{bytespec}, but that has zero-bits everywhere else.
 
4929
 
 
4930
@b{setf} may be used with @b{mask-field}
 
4931
to modify a byte within the @i{integer} that is stored
 
4932
in a given @i{place}.
 
4933
The effect is to perform a @b{deposit-field} operation
 
4934
and then store the result back into the @i{place}.
 
4935
 
 
4936
@subsubheading  Examples::
 
4937
 
 
4938
@example
 
4939
 (mask-field (byte 1 5) -1) @result{}  32
 
4940
 (setq a 15) @result{}  15
 
4941
 (mask-field (byte 2 0) a) @result{}  3
 
4942
 a @result{}  15
 
4943
 (setf (mask-field (byte 2 0) a) 1) @result{}  1
 
4944
 a @result{}  13
 
4945
@end example
 
4946
 
 
4947
@subsubheading  See Also::
 
4948
 
 
4949
@ref{byte}
 
4950
,
 
4951
@ref{ldb}
 
4952
 
 
4953
@subsubheading  Notes::
 
4954
 
 
4955
@example
 
4956
 (ldb @i{bs} (mask-field @i{bs} @i{n})) @equiv{} (ldb @i{bs} @i{n})
 
4957
 (logbitp @i{j} (mask-field (byte @i{s} @i{p}) @i{n}))
 
4958
   @equiv{} (and (>= @i{j} @i{p}) (< @i{j} @i{s}) (logbitp @i{j} @i{n}))
 
4959
 (mask-field @i{bs} @i{n}) @equiv{} (logand @i{n} (dpb -1 @i{bs} 0))
 
4960
@end example
 
4961
 
 
4962
@node most-positive-fixnum, decode-float, mask-field, Numbers Dictionary
 
4963
@subsection most-positive-fixnum, most-negative-fixnum              [Constant Variable]
 
4964
 
 
4965
@subsubheading  Constant Value::
 
4966
 
 
4967
@i{implementation-dependent}.
 
4968
 
 
4969
@subsubheading  Description::
 
4970
 
 
4971
@b{most-positive-fixnum} is that @i{fixnum} closest in value 
 
4972
to positive infinity provided by the implementation,
 
4973
 
 
4974
and greater than or equal to both 2^@r{15} - 1 and 
 
4975
@b{array-dimension-limit}.
 
4976
 
 
4977
@b{most-negative-fixnum} is that @i{fixnum} closest in value
 
4978
to negative infinity provided by the implementation,
 
4979
 
 
4980
and less than or equal to -2^@r{15}.
 
4981
 
 
4982
@node decode-float, float, most-positive-fixnum, Numbers Dictionary
 
4983
@subsection decode-float, scale-float, float-radix, float-sign, 
 
4984
@subheading float-digits, float-precision, integer-decode-float
 
4985
@flushright
 
4986
@i{[Function]}
 
4987
@end flushright
 
4988
 
 
4989
@code{decode-float}  @i{float} @result{}  @i{significand, exponent, sign}
 
4990
 
 
4991
@code{scale-float}  @i{float integer} @result{}  @i{scaled-float}
 
4992
 
 
4993
@code{float-radix}  @i{float} @result{}  @i{float-radix}
 
4994
 
 
4995
@code{float-sign}  @i{float-1 @r{&optional} float-2} @result{}  @i{signed-float}
 
4996
 
 
4997
@code{float-digits}  @i{float} @result{}  @i{digits1}
 
4998
 
 
4999
@code{float-precision}  @i{float} @result{}  @i{digits2}
 
5000
 
 
5001
@code{integer-decode-float}  @i{float} @result{}  @i{significand, exponent, integer-sign}
 
5002
 
 
5003
@subsubheading  Arguments and Values::
 
5004
 
 
5005
@i{digits1}---a non-negative @i{integer}.
 
5006
 
 
5007
@i{digits2}---a non-negative @i{integer}.
 
5008
 
 
5009
@i{exponent}---an @i{integer}.
 
5010
 
 
5011
@i{float}---a @i{float}.
 
5012
 
 
5013
@i{float-1}---a @i{float}.
 
5014
 
 
5015
@i{float-2}---a @i{float}.
 
5016
 
 
5017
@i{float-radix}---an @i{integer}.
 
5018
 
 
5019
@i{integer}---a non-negative @i{integer}.
 
5020
 
 
5021
@i{integer-sign}---the @i{integer} @t{-1},
 
5022
                    or the @i{integer} @t{1}.
 
5023
 
 
5024
@i{scaled-float}---a @i{float}.
 
5025
 
 
5026
@i{sign}---A @i{float} of the same @i{type} as @i{float}
 
5027
               but numerically equal to @t{1.0} or @t{-1.0}.
 
5028
 
 
5029
@i{signed-float}---a @i{float}.
 
5030
 
 
5031
@i{significand}---a @i{float}.
 
5032
 
 
5033
@subsubheading  Description::
 
5034
 
 
5035
@b{decode-float} computes three values that characterize
 
5036
@i{float}.
 
5037
The first value is of the same @i{type}
 
5038
as @i{float} and 
 
5039
represents the significand.
 
5040
The second value represents the exponent
 
5041
to which the radix (notated in this description by @i{b}) must
 
5042
be raised to obtain the value that, when multiplied with the first
 
5043
result, produces the absolute value of @i{float}.
 
5044
If @i{float} is zero, any @i{integer} value may be returned, 
 
5045
provided that the identity shown for @b{scale-float} holds.
 
5046
The third value
 
5047
is of the same @i{type} as @i{float}
 
5048
and is 1.0 if @i{float} is greater
 
5049
than or equal to zero or -1.0 otherwise.
 
5050
 
 
5051
@b{decode-float} 
 
5052
divides @i{float} by an integral power of @i{b}
 
5053
so as to bring its value between 1/@i{b} (inclusive) and~1 (exclusive),
 
5054
and returns the quotient as the first value.
 
5055
If @i{float} is zero, however, the result
 
5056
equals the absolute value of @i{float} (that is, if there is a negative
 
5057
zero, its significand is considered to be a positive zero).
 
5058
 
 
5059
@b{scale-float} returns
 
5060
@t{(* @i{float} (expt (float @i{b} @i{float}) 
 
5061
@i{integer}))\/}, where @i{b} is the radix of the floating-point
 
5062
representation. @i{float} is not necessarily between 1/@i{b} and~1.
 
5063
 
 
5064
@b{float-radix} returns 
 
5065
the radix of @i{float}.
 
5066
 
 
5067
@b{float-sign} returns a number @t{z} such
 
5068
that @t{z} and @i{float-1} have the same sign and also such that
 
5069
@t{z} and @i{float-2} have the same absolute value.
 
5070
If @i{float-2} is not supplied, its value is @t{(float 1 @i{float-1})}.
 
5071
If an implementation
 
5072
has distinct representations for negative zero and positive zero,
 
5073
then @t{(float-sign -0.0)} @result{}  @t{-1.0}.
 
5074
 
 
5075
@b{float-digits} returns
 
5076
the number of radix @i{b} digits
 
5077
used in the representation of @i{float} (including any implicit
 
5078
digits, such as a ``hidden bit'').
 
5079
 
 
5080
@b{float-precision}
 
5081
returns
 
5082
the number of significant radix @i{b} digits present in @i{float};
 
5083
if @i{float} is a @i{float}
 
5084
zero, then the result is an @i{integer} zero.
 
5085
 
 
5086
For @i{normalized} @i{floats},
 
5087
the results of @b{float-digits} and @b{float-precision} are the same,
 
5088
but the precision is less than the number of representation digits 
 
5089
for a @i{denormalized} or zero number.
 
5090
 
 
5091
@b{integer-decode-float} computes three values that characterize
 
5092
@i{float} - 
 
5093
the significand scaled so as to be an @i{integer},
 
5094
and the same last two
 
5095
values that are returned by @b{decode-float}.
 
5096
If @i{float} is zero, @b{integer-decode-float} returns 
 
5097
zero as the first value.
 
5098
The second value bears the same relationship to the first value
 
5099
as for @b{decode-float}:
 
5100
 
 
5101
@example
 
5102
 (multiple-value-bind (signif expon sign)
 
5103
                      (integer-decode-float f)
 
5104
   (scale-float (float signif f) expon)) @equiv{} (abs f)
 
5105
@end example
 
5106
 
 
5107
@subsubheading  Examples::
 
5108
 
 
5109
@example
 
5110
 ;; Note that since the purpose of this functionality is to expose
 
5111
 ;; details of the implementation, all of these examples are necessarily
 
5112
 ;; very implementation-dependent.  Results may vary widely.
 
5113
 ;; Values shown here are chosen consistently from one particular implementation.
 
5114
 (decode-float .5) @result{}  0.5, 0, 1.0
 
5115
 (decode-float 1.0) @result{}  0.5, 1, 1.0
 
5116
 (scale-float 1.0 1) @result{}  2.0
 
5117
 (scale-float 10.01 -2) @result{}  2.5025
 
5118
 (scale-float 23.0 0) @result{}  23.0
 
5119
 (float-radix 1.0) @result{}  2
 
5120
 (float-sign 5.0) @result{}  1.0
 
5121
 (float-sign -5.0) @result{}  -1.0
 
5122
 (float-sign 0.0) @result{}  1.0
 
5123
 (float-sign 1.0 0.0) @result{}  0.0
 
5124
 (float-sign 1.0 -10.0) @result{}  10.0
 
5125
 (float-sign -1.0 10.0) @result{}  -10.0
 
5126
 (float-digits 1.0) @result{}  24
 
5127
 (float-precision 1.0) @result{}  24
 
5128
 (float-precision least-positive-single-float) @result{}  1
 
5129
 (integer-decode-float 1.0) @result{}  8388608, -23, 1
 
5130
@end example
 
5131
 
 
5132
@subsubheading  Affected By::
 
5133
 
 
5134
The implementation's representation for @i{floats}.
 
5135
 
 
5136
@subsubheading  Exceptional Situations::
 
5137
 
 
5138
The functions @b{decode-float}, @b{float-radix}, @b{float-digits},
 
5139
@b{float-precision}, and @b{integer-decode-float} should signal an error
 
5140
if their only argument is not a @i{float}.
 
5141
 
 
5142
The @i{function} @b{scale-float} should signal an error if its first argument
 
5143
is not a @i{float} or if its second argument is not an @i{integer}.
 
5144
 
 
5145
The @i{function} @b{float-sign} should signal an error if its first argument
 
5146
is not a @i{float} or if its second argument is supplied but is 
 
5147
not a @i{float}.
 
5148
 
 
5149
@subsubheading  Notes::
 
5150
 
 
5151
The product of the first result of @b{decode-float} or @b{integer-decode-float},
 
5152
of the radix raised to the power of the second result, and of the third result
 
5153
is exactly equal to the value of @i{float}.
 
5154
 
 
5155
@example
 
5156
 (multiple-value-bind (signif expon sign)
 
5157
                      (decode-float f)
 
5158
   (scale-float signif expon))
 
5159
@equiv{} (abs f)
 
5160
@end example
 
5161
 
 
5162
and
 
5163
 
 
5164
@example
 
5165
 (multiple-value-bind (signif expon sign)
 
5166
                      (decode-float f)
 
5167
   (* (scale-float signif expon) sign))
 
5168
@equiv{} f
 
5169
@end example
 
5170
 
 
5171
@node float, floatp, decode-float, Numbers Dictionary
 
5172
@subsection float                                                            [Function]
 
5173
 
 
5174
@code{float}  @i{number @r{&optional} prototype} @result{}  @i{float}
 
5175
 
 
5176
@subsubheading  Arguments and Values::
 
5177
 
 
5178
@i{number}---a @i{real}.
 
5179
 
 
5180
@i{prototype}---a @i{float}.
 
5181
 
 
5182
@i{float}---a @i{float}.
 
5183
 
 
5184
@subsubheading  Description::
 
5185
 
 
5186
@b{float} converts a 
 
5187
 
 
5188
@i{real}
 
5189
 
 
5190
number to a @i{float}.
 
5191
 
 
5192
If a @i{prototype} is supplied,
 
5193
a @i{float} is returned that is mathematically equal to @i{number}
 
5194
but has the same format as @i{prototype}.
 
5195
 
 
5196
If @i{prototype} is not supplied,
 
5197
then if the @i{number} is already a @i{float}, it is returned;
 
5198
otherwise, a @i{float} is returned that is mathematically equal to @i{number}
 
5199
but is a @i{single float}.
 
5200
 
 
5201
@subsubheading  Examples:: 
 
5202
 
 
5203
@example
 
5204
 (float 0) @result{}  0.0
 
5205
 (float 1 .5) @result{}  1.0
 
5206
 (float 1.0) @result{}  1.0
 
5207
 (float 1/2) @result{}  0.5
 
5208
@result{}  1.0d0
 
5209
@i{OR}@result{} 1.0
 
5210
 (eql (float 1.0 1.0d0) 1.0d0) @result{}  @i{true}
 
5211
@end example
 
5212
 
 
5213
@subsubheading  See Also::
 
5214
 
 
5215
@ref{coerce}
 
5216
 
 
5217
@node floatp, most-positive-short-float, float, Numbers Dictionary
 
5218
@subsection floatp                                                           [Function]
 
5219
 
 
5220
@code{floatp}  @i{object}
 
5221
 @r{generalized-boolean}
 
5222
 
 
5223
@subsubheading  Arguments and Values::
 
5224
 
 
5225
@i{object}---an @i{object}.
 
5226
 
 
5227
@i{generalized-boolean}---a @i{generalized boolean}.
 
5228
 
 
5229
@subsubheading  Description::
 
5230
 
 
5231
Returns @i{true} if @i{object} is of @i{type} @b{float};
 
5232
otherwise, returns @i{false}.
 
5233
 
 
5234
@subsubheading  Examples::
 
5235
 
 
5236
@example
 
5237
 (floatp 1.2d2) @result{}  @i{true}
 
5238
 (floatp 1.212) @result{}  @i{true}
 
5239
 (floatp 1.2s2) @result{}  @i{true}
 
5240
 (floatp (expt 2 130)) @result{}  @i{false}
 
5241
@end example
 
5242
 
 
5243
@subsubheading  Notes::
 
5244
 
 
5245
@example
 
5246
 (floatp @i{object}) @equiv{} (typep @i{object} 'float)
 
5247
@end example
 
5248
 
 
5249
@node most-positive-short-float, short-float-epsilon, floatp, Numbers Dictionary
 
5250
@subsection most-positive-short-float, least-positive-short-float,
 
5251
@subheading least-positive-normalized-short-float,
 
5252
@subheading most-positive-double-float, least-positive-double-float,
 
5253
@subheading least-positive-normalized-double-float,
 
5254
@subheading most-positive-long-float, least-positive-long-float, 
 
5255
@subheading least-positive-normalized-long-float,
 
5256
@subheading most-positive-single-float, least-positive-single-float,
 
5257
@subheading least-positive-normalized-single-float,
 
5258
@subheading most-negative-short-float, least-negative-short-float,
 
5259
@subheading least-negative-normalized-short-float,
 
5260
@subheading most-negative-single-float, least-negative-single-float,
 
5261
@subheading least-negative-normalized-single-float,
 
5262
@subheading most-negative-double-float, least-negative-double-float,
 
5263
@subheading least-negative-normalized-double-float,
 
5264
@subheading most-negative-long-float, least-negative-long-float,
 
5265
@subheading least-negative-normalized-long-float
 
5266
@flushright
 
5267
@i{[Constant Variable]}
 
5268
@end flushright
 
5269
 
 
5270
@subsubheading  Constant Value::
 
5271
 
 
5272
@i{implementation-dependent}.
 
5273
 
 
5274
@subsubheading  Description::
 
5275
 
 
5276
These @i{constant variables} provide a way for programs to examine
 
5277
the @i{implementation-defined} limits for the various float formats.
 
5278
 
 
5279
Of these @i{variables},
 
5280
 each which has ``@t{-normalized}'' in its @i{name}
 
5281
  must have a @i{value} which is a @i{normalized} @i{float}, and
 
5282
 each which does not have ``@t{-normalized}'' in its name
 
5283
  may have a @i{value} which is either a @i{normalized} @i{float} 
 
5284
  or a @i{denormalized} @i{float}, as appropriate.
 
5285
 
 
5286
Of these @i{variables},
 
5287
 each which has ``@t{short-float}'' in its name
 
5288
  must have a @i{value} which is a @i{short float},
 
5289
 each which has ``@t{single-float}'' in its name
 
5290
  must have a @i{value} which is a @i{single float},
 
5291
 each which has ``@t{double-float}'' in its name
 
5292
  must have a @i{value} which is a @i{double float}, and
 
5293
 each which has ``@t{long-float}'' in its name
 
5294
  must have a @i{value} which is a @i{long float}.
 
5295
 
 
5296
@table @asis
 
5297
 
 
5298
@item @t{*}  
 
5299
@b{most-positive-short-float},
 
5300
              @b{most-positive-single-float},
 
5301
        @b{most-positive-double-float},
 
5302
              @b{most-positive-long-float}
 
5303
 
 
5304
  Each of these @i{constant variables} has as its @i{value} 
 
5305
  the positive @i{float} of the largest magnitude 
 
5306
  (closest in value to, but not equal to, positive infinity)
 
5307
  for the float format implied by its name.
 
5308
 
 
5309
@item @t{*}  
 
5310
@b{least-positive-short-float},
 
5311
              @b{least-positive-normalized-short-float},
 
5312
        @b{least-positive-single-float},
 
5313
              @b{least-positive-normalized-single-float},
 
5314
        @b{least-positive-double-float},
 
5315
              @b{least-positive-normalized-double-float},
 
5316
        @b{least-positive-long-float},
 
5317
              @b{least-positive-normalized-long-float}
 
5318
 
 
5319
  Each of these @i{constant variables} has as its @i{value}
 
5320
  the smallest positive (nonzero) @i{float}
 
5321
  for the float format implied by its name.
 
5322
 
 
5323
@item @t{*}  
 
5324
@b{least-negative-short-float},
 
5325
              @b{least-negative-normalized-short-float},
 
5326
        @b{least-negative-single-float},
 
5327
              @b{least-negative-normalized-single-float},
 
5328
        @b{least-negative-double-float},
 
5329
              @b{least-negative-normalized-double-float},
 
5330
        @b{least-negative-long-float},
 
5331
              @b{least-negative-normalized-long-float}
 
5332
 
 
5333
  Each of these @i{constant variables} has as its @i{value}
 
5334
  the negative (nonzero) @i{float} of the smallest magnitude
 
5335
  for the float format implied by its name.
 
5336
  (If an implementation supports minus zero as a @i{different} 
 
5337
   @i{object} from positive zero, this value must not be minus zero.)
 
5338
 
 
5339
@item @t{*}  
 
5340
@b{most-negative-short-float},
 
5341
              @b{most-negative-single-float},
 
5342
        @b{most-negative-double-float},
 
5343
              @b{most-negative-long-float}
 
5344
 
 
5345
  Each of these @i{constant variables} has as its @i{value}
 
5346
  the negative @i{float} of the largest magnitude 
 
5347
  (closest in value to, but not equal to, negative infinity)
 
5348
  for the float format implied by its name.
 
5349
 
 
5350
@end table
 
5351
 
 
5352
@subsubheading  Notes::
 
5353
 
 
5354
@node short-float-epsilon, arithmetic-error, most-positive-short-float, Numbers Dictionary
 
5355
@subsection short-float-epsilon, short-float-negative-epsilon,
 
5356
@subheading single-float-epsilon, single-float-negative-epsilon,
 
5357
@subheading double-float-epsilon, double-float-negative-epsilon,
 
5358
@subheading long-float-epsilon, long-float-negative-epsilon
 
5359
@flushright
 
5360
@i{[Constant Variable]}
 
5361
@end flushright
 
5362
 
 
5363
@subsubheading  Constant Value::
 
5364
 
 
5365
@i{implementation-dependent}.
 
5366
 
 
5367
@subsubheading  Description::
 
5368
 
 
5369
The value of each of the constants @b{short-float-epsilon}, 
 
5370
@b{single-float-epsilon},
 
5371
@b{double-float-epsilon}, and @b{long-float-epsilon} is 
 
5372
the smallest positive @i{float} \epsilon of the given format, 
 
5373
such that the following expression is @i{true} when evaluated:
 
5374
 
 
5375
@t{(not (= (float 1 \epsilon) (+ (float 1 \epsilon) \epsilon)))\/}
 
5376
 
 
5377
The value of each of the constants @b{short-float-negative-epsilon}, 
 
5378
@b{single-float-negative-epsilon},
 
5379
@b{double-float-negative-epsilon}, and  
 
5380
@b{long-float-negative-epsilon} is the smallest positive
 
5381
@i{float} \epsilon of the given format, such that the following
 
5382
expression is @i{true} when evaluated:
 
5383
 
 
5384
@t{(not (= (float 1 \epsilon) (- (float 1 \epsilon) \epsilon)))\/}
 
5385
 
 
5386
@node arithmetic-error, arithmetic-error-operands, short-float-epsilon, Numbers Dictionary
 
5387
@subsection arithmetic-error                                           [Condition Type]
 
5388
 
 
5389
@subsubheading  Class Precedence List::
 
5390
@b{arithmetic-error},
 
5391
@b{error},
 
5392
@b{serious-condition},
 
5393
@b{condition},
 
5394
@b{t}
 
5395
 
 
5396
@subsubheading  Description::
 
5397
 
 
5398
The @i{type} @b{arithmetic-error} consists of error conditions
 
5399
that occur during arithmetic operations.
 
5400
The operation and operands are initialized with
 
5401
the initialization arguments named @t{:operation} and @t{:operands} to @b{make-condition},
 
5402
and are @i{accessed} by
 
5403
the functions @b{arithmetic-error-operation} and 
 
5404
@b{arithmetic-error-operands}.
 
5405
 
 
5406
@subsubheading  See Also::
 
5407
 
 
5408
@b{arithmetic-error-operation}, 
 
5409
@ref{arithmetic-error-operands}
 
5410
 
 
5411
@node arithmetic-error-operands, division-by-zero, arithmetic-error, Numbers Dictionary
 
5412
@subsection arithmetic-error-operands, arithmetic-error-operation            [Function]
 
5413
 
 
5414
@code{arithmetic-error-operands}  @i{condition} @result{}  @i{operands}
 
5415
 
 
5416
@code{arithmetic-error-operation}  @i{condition} @result{}  @i{operation}
 
5417
 
 
5418
@subsubheading  Arguments and Values::
 
5419
 
 
5420
@i{condition}---a @i{condition} of @i{type} @b{arithmetic-error}.
 
5421
 
 
5422
@i{operands}---a @i{list}.
 
5423
 
 
5424
@i{operation}---a @i{function designator}.
 
5425
 
 
5426
@subsubheading  Description::
 
5427
 
 
5428
@b{arithmetic-error-operands} returns a @i{list} of the operands 
 
5429
which were used in the offending call to the operation that signaled 
 
5430
the @i{condition}.
 
5431
 
 
5432
@b{arithmetic-error-operation} returns a @i{list} of 
 
5433
the offending operation in the offending call that signaled the @i{condition}.
 
5434
 
 
5435
@subsubheading  See Also::
 
5436
 
 
5437
@b{arithmetic-error},
 
5438
@ref{Conditions}
 
5439
 
 
5440
@subsubheading  Notes::
 
5441
 
 
5442
@node division-by-zero, floating-point-invalid-operation, arithmetic-error-operands, Numbers Dictionary
 
5443
@subsection division-by-zero                                           [Condition Type]
 
5444
 
 
5445
@subsubheading  Class Precedence List::
 
5446
@b{division-by-zero},
 
5447
@b{arithmetic-error},
 
5448
@b{error},
 
5449
@b{serious-condition},
 
5450
@b{condition},
 
5451
@b{t}
 
5452
 
 
5453
@subsubheading  Description::
 
5454
 
 
5455
The @i{type} @b{division-by-zero} consists of error conditions that
 
5456
occur because of division by zero.
 
5457
 
 
5458
@node floating-point-invalid-operation, floating-point-inexact, division-by-zero, Numbers Dictionary
 
5459
@subsection floating-point-invalid-operation                           [Condition Type]
 
5460
 
 
5461
@subsubheading  Class Precedence List::
 
5462
@b{floating-point-invalid-operation},
 
5463
@b{arithmetic-error},
 
5464
@b{error},
 
5465
@b{serious-condition},
 
5466
@b{condition},
 
5467
@b{t}
 
5468
 
 
5469
@subsubheading  Description::
 
5470
 
 
5471
The @i{type} @b{floating-point-invalid-operation} consists of
 
5472
error conditions that occur because of certain 
 
5473
floating point traps. 
 
5474
 
 
5475
It is @i{implementation-dependent} whether floating point traps
 
5476
occur, and whether or how they may be enabled or disabled.  Therefore,
 
5477
conforming code may establish handlers for this condition, but must not
 
5478
depend on its being @i{signaled}.
 
5479
 
 
5480
@node floating-point-inexact, floating-point-overflow, floating-point-invalid-operation, Numbers Dictionary
 
5481
@subsection floating-point-inexact                                     [Condition Type]
 
5482
 
 
5483
@subsubheading  Class Precedence List::
 
5484
@b{floating-point-inexact},
 
5485
@b{arithmetic-error},
 
5486
@b{error},
 
5487
@b{serious-condition},
 
5488
@b{condition},
 
5489
@b{t}
 
5490
 
 
5491
@subsubheading  Description::
 
5492
 
 
5493
The @i{type} @b{floating-point-inexact} consists of 
 
5494
error conditions that occur because of certain 
 
5495
floating point traps.
 
5496
 
 
5497
It is @i{implementation-dependent} whether floating point traps
 
5498
occur, and whether or how they may be enabled or disabled.  Therefore,
 
5499
conforming code may establish handlers for this condition, but must not
 
5500
depend on its being @i{signaled}.
 
5501
 
 
5502
@node floating-point-overflow, floating-point-underflow, floating-point-inexact, Numbers Dictionary
 
5503
@subsection floating-point-overflow                                    [Condition Type]
 
5504
 
 
5505
@subsubheading  Class Precedence List::
 
5506
@b{floating-point-overflow},
 
5507
@b{arithmetic-error},
 
5508
@b{error},
 
5509
@b{serious-condition},
 
5510
@b{condition},
 
5511
@b{t}
 
5512
 
 
5513
@subsubheading  Description::
 
5514
 
 
5515
The @i{type} @b{floating-point-overflow} consists of error
 
5516
conditions that occur because of floating-point overflow.
 
5517
 
 
5518
@node floating-point-underflow,  , floating-point-overflow, Numbers Dictionary
 
5519
@subsection floating-point-underflow                                   [Condition Type]
 
5520
 
 
5521
@subsubheading  Class Precedence List::
 
5522
@b{floating-point-underflow},
 
5523
@b{arithmetic-error},
 
5524
@b{error},
 
5525
@b{serious-condition},
 
5526
@b{condition},
 
5527
@b{t}
 
5528
 
 
5529
@subsubheading  Description::
 
5530
 
 
5531
The @i{type} @b{floating-point-underflow} consists of 
 
5532
error conditions that occur because of floating-point underflow.
 
5533
 
 
5534
@c end of including dict-numbers
 
5535
 
 
5536
@c %**end of chapter
 
5537