85 lines
5.1 KiB
HTML
85 lines
5.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. 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=tex2html1705 HREF="node17.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html1703 HREF="node15.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html1697 HREF="node15.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html1707 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html1708 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html1706 HREF="node17.html"> Integers</A>
|
||
|
<B>Up:</B> <A NAME=tex2html1704 HREF="node15.html"> Data Types</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html1698 HREF="node15.html"> Data Types</A>
|
||
|
<HR> <P>
|
||
|
<H1><A NAME=SECTION00610000000000000000>2.1. Numbers</A></H1>
|
||
|
<P>
|
||
|
Several kinds of numbers are defined in Common Lisp.
|
||
|
They are divided into <i>integers</i>; <i>ratios</i>;
|
||
|
<i>floating-point numbers</i>, with names provided for
|
||
|
up to four different floating-point representations; and <i>complex numbers</i>.
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
X3J13 voted in March 1989 (REAL-NUMBER-TYPE) <A NAME=493> </A> to add the type <tt>real</tt>.
|
||
|
<P>
|
||
|
The <tt>number</tt> data type encompasses all kinds of
|
||
|
numbers. For convenience, there are names for some
|
||
|
subclasses of numbers as well. Integers and ratios are of
|
||
|
type <tt>rational</tt>. Rational numbers and floating-point
|
||
|
numbers are of type <tt>real</tt>. Real numbers and complex
|
||
|
numbers are of type <tt>number</tt>.
|
||
|
<P>
|
||
|
Although the names of these types were chosen with the
|
||
|
terminology of mathematics in mind, the correspondences
|
||
|
are not always exact. Integers and ratios model the
|
||
|
corresponding mathematical concepts directly. Numbers
|
||
|
of type <tt>float</tt> may be used to approximate real
|
||
|
numbers, both rational and irrational. The <tt>real</tt> type
|
||
|
includes all Common Lisp numbers that represent
|
||
|
mathematical real numbers, though there are
|
||
|
mathematical real numbers (irrational numbers)
|
||
|
that do not have an exact Common Lisp representation.
|
||
|
Only <tt>real</tt> numbers may be ordered using the <tt><</tt>, <tt>></tt>, <tt><=</tt>,
|
||
|
and <tt>>=</tt> functions.
|
||
|
<P>
|
||
|
<hr>
|
||
|
<b>Compatibility note:</b>
|
||
|
The Fortran 77 standard defines the term
|
||
|
<i>real datum</i> to mean ``a processor approximation to the value
|
||
|
of a real number.'' In practice the Fortran <i>basic real</i> type
|
||
|
is the floating-point data type that Common Lisp calls
|
||
|
<tt>single-float</tt>. The Fortran <i>double precision</i> type is
|
||
|
Common Lisp's <tt>double-float</tt>. The Pascal <tt>real</tt> data type is
|
||
|
an ``implementation-defined subset of the real numbers.'' In
|
||
|
practice this is usually a floating-point type, often what
|
||
|
Common Lisp calls <tt>double-float</tt>.
|
||
|
<P>
|
||
|
A translation of an algorithm written in Fortran or Pascal
|
||
|
that uses <tt>real</tt> data usually will use some appropriate
|
||
|
precision of Common Lisp's <tt>float</tt> type. Some algorithms may
|
||
|
gain accuracy or flexibility by using Common Lisp's
|
||
|
<tt>rational</tt> or <tt>real</tt> type instead.
|
||
|
<hr>
|
||
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
<P>
|
||
|
<HR>
|
||
|
<UL>
|
||
|
<LI> <A NAME=tex2html1709 HREF="node17.html#SECTION00611000000000000000"> Integers</A>
|
||
|
<LI> <A NAME=tex2html1710 HREF="node18.html#SECTION00612000000000000000"> Ratios</A>
|
||
|
<LI> <A NAME=tex2html1711 HREF="node19.html#SECTION00613000000000000000"> Floating-Point Numbers</A>
|
||
|
<LI> <A NAME=tex2html1712 HREF="node20.html#SECTION00614000000000000000"> Complex Numbers</A>
|
||
|
</UL>
|
||
|
<BR> <HR><A NAME=tex2html1705 HREF="node17.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html1703 HREF="node15.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html1697 HREF="node15.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html1707 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html1708 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html1706 HREF="node17.html"> Integers</A>
|
||
|
<B>Up:</B> <A NAME=tex2html1704 HREF="node15.html"> Data Types</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html1698 HREF="node15.html"> Data Types</A>
|
||
|
<HR> <P>
|
||
|
<HR>
|
||
|
<P><ADDRESS>
|
||
|
AI.Repository@cs.cmu.edu
|
||
|
</ADDRESS>
|
||
|
</BODY>
|