emacs.d/clones/lisp/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node121.html

84 lines
5.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE>12. Numbers</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Numbers">
<meta name="keywords" value="clm">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<b>Common Lisp the Language, 2nd Edition</b>
<BR> <HR><A NAME=tex2html3029 HREF="node122.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3027 HREF="clm.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3021 HREF="node120.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3031 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3032 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html3030 HREF="node122.html"> PrecisionContagion, and </A>
<B>Up:</B> <A NAME=tex2html3028 HREF="clm.html">Common Lisp the Language</A>
<B> Previous:</B> <A NAME=tex2html3022 HREF="node120.html"> An Example</A>
<HR> <P>
<H1><A NAME=SECTION001600000000000000000>12. Numbers</A></H1>
<P>
<A NAME=NUMBER>Common</A>
Lisp provides several different representations for numbers.
These representations may be divided into four categories: integers,
ratios, floating-point numbers, and complex numbers. Many numeric
functions will accept any kind of number; they are <i>generic</i>. Other
functions accept only certain kinds of numbers.
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
Note that this remark, predating the design of the Common Lisp Object System,
uses the term ``generic'' in a generic sense and not necessarily
in the technical sense used by CLOS
(see chapter <A HREF="node15.html#DTYPES">2</A>).
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
In general, numbers in Common Lisp are not true objects; <tt>eq</tt> cannot
be counted upon to operate on them reliably. In particular,
it is possible that the expression
<P><pre>
(let ((x z) (y z)) (eq x y))
</pre><P>
may be false rather than true if the value of <tt>z</tt> is a number.
<P>
<hr>
<b>Rationale:</b> This odd breakdown of <tt>eq</tt> in the case of numbers
allows the implementor enough design freedom to produce exceptionally
efficient numerical code on conventional architectures.
MacLisp requires this freedom, for example, in order to produce compiled
numerical code equal in speed to Fortran.
Common Lisp makes this same restriction,
if not for this freedom, then at least for the sake of compatibility.
<hr>
<P>
If two objects are to be compared for ``identity,'' but either might be
a number, then the predicate <tt>eql</tt> is probably appropriate;
if both objects are known to be numbers, then <tt>=</tt>
may be preferable.
<P>
<HR>
<UL>
<LI> <A NAME=tex2html3033 HREF="node122.html#SECTION001610000000000000000"> Precision, Contagion, and Coercion</A>
<LI> <A NAME=tex2html3034 HREF="node123.html#SECTION001620000000000000000"> Predicates on Numbers</A>
<LI> <A NAME=tex2html3035 HREF="node124.html#SECTION001630000000000000000"> Comparisons on Numbers</A>
<LI> <A NAME=tex2html3036 HREF="node125.html#SECTION001640000000000000000"> Arithmetic Operations</A>
<LI> <A NAME=tex2html3037 HREF="node126.html#SECTION001650000000000000000"> Irrational and Transcendental Functions</A>
<UL>
<LI> <A NAME=tex2html3038 HREF="node127.html#SECTION001651000000000000000"> Exponential and Logarithmic Functions</A>
<LI> <A NAME=tex2html3039 HREF="node128.html#SECTION001652000000000000000"> Trigonometric and Related Functions</A>
<LI> <A NAME=tex2html3040 HREF="node129.html#SECTION001653000000000000000"> Branch Cuts, Principal Values, and Boundary Conditions in the Complex Plane</A>
</UL>
<LI> <A NAME=tex2html3041 HREF="node130.html#SECTION001660000000000000000"> Type Conversions and Component Extractions on Numbers</A>
<LI> <A NAME=tex2html3042 HREF="node131.html#SECTION001670000000000000000"> Logical Operations on Numbers</A>
<LI> <A NAME=tex2html3043 HREF="node132.html#SECTION001680000000000000000"> Byte Manipulation Functions</A>
<LI> <A NAME=tex2html3044 HREF="node133.html#SECTION001690000000000000000"> Random Numbers</A>
<LI> <A NAME=tex2html3045 HREF="node134.html#SECTION0016100000000000000000"> Implementation Parameters</A>
</UL>
<BR> <HR><A NAME=tex2html3029 HREF="node122.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3027 HREF="clm.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3021 HREF="node120.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3031 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3032 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html3030 HREF="node122.html"> PrecisionContagion, and </A>
<B>Up:</B> <A NAME=tex2html3028 HREF="clm.html">Common Lisp the Language</A>
<B> Previous:</B> <A NAME=tex2html3022 HREF="node120.html"> An Example</A>
<HR> <P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>