68 lines
4.1 KiB
HTML
68 lines
4.1 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>2.1.4. Complex Numbers</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value=" Complex 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=tex2html1755 HREF="node21.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html1753 HREF="node16.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html1749 HREF="node19.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html1757 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html1758 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html1756 HREF="node21.html"> Characters</A>
|
|
<B>Up:</B> <A NAME=tex2html1754 HREF="node16.html"> Numbers</A>
|
|
<B> Previous:</B> <A NAME=tex2html1750 HREF="node19.html"> Floating-Point Numbers</A>
|
|
<HR> <P>
|
|
<H2><A NAME=SECTION00614000000000000000>2.1.4. Complex Numbers</A></H2>
|
|
<P>
|
|
Complex numbers (type <tt>complex</tt>)
|
|
are represented in Cartesian form, with a real part and an imaginary
|
|
part, each of which is a non-complex number (integer, ratio, or floating-point
|
|
number). It should be emphasized that the parts of a complex
|
|
number are not necessarily floating-point numbers; in this, Common Lisp
|
|
is like PL/I and differs from Fortran. However, both parts must
|
|
be of the same type: either both are rational, or both are of the
|
|
same floating-point format.
|
|
<P>
|
|
Complex numbers may be notated by writing the characters <tt>#C</tt>
|
|
followed by a list of the real and imaginary parts.
|
|
If the two parts as notated are not of the same type, then
|
|
they are converted according to the rules of floating-point contagion
|
|
as described in chapter <A HREF="node121.html#NUMBER">12</A>.
|
|
(Indeed, <tt>#C(<i>a</i> <i>b</i>)</tt> is equivalent to <tt>#,(complex <i>a</i> <i>b</i>)</tt>;
|
|
see the description of the function <tt>complex</tt>.)
|
|
For example:
|
|
<P><pre>
|
|
#C(3.0s1 2.0s-1) ;Real and imaginary parts are short format
|
|
#C(5 -3) ;A Gaussian integer
|
|
#C(5/3 7.0) ;Will be converted internally to <tt>#C(1.66666 7.0)</tt>
|
|
#C(0 1) ;The imaginary unit, that is, <i>i</i>
|
|
</pre>
|
|
<P>
|
|
The type of a specific complex number is indicated by a list
|
|
of the word <tt>complex</tt> and the type of the components; for example,
|
|
a specialized representation for complex numbers with short floating-point
|
|
parts would be of type <tt>(complex short-float)</tt>. The type <tt>complex</tt>
|
|
encompasses all complex representations.
|
|
<P>
|
|
A complex number of type <tt>(complex rational)</tt>, that is, one whose
|
|
components are rational, can never have a zero imaginary part.
|
|
If the result of a computation would be a complex rational
|
|
with a zero imaginary part, the result is immediately
|
|
converted to a non-complex rational number by taking the
|
|
real part. This is called the rule of <i>complex canonicalization</i>.
|
|
This rule does not apply to floating-point complex numbers;
|
|
<tt>#C(5.0 0.0)</tt> and <tt>5.0</tt> are different.
|
|
<P>
|
|
<BR> <HR><A NAME=tex2html1755 HREF="node21.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html1753 HREF="node16.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html1749 HREF="node19.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html1757 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html1758 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html1756 HREF="node21.html"> Characters</A>
|
|
<B>Up:</B> <A NAME=tex2html1754 HREF="node16.html"> Numbers</A>
|
|
<B> Previous:</B> <A NAME=tex2html1750 HREF="node19.html"> Floating-Point Numbers</A>
|
|
<HR> <P>
|
|
<HR>
|
|
<P><ADDRESS>
|
|
AI.Repository@cs.cmu.edu
|
|
</ADDRESS>
|
|
</BODY>
|