File: LISP-tutorial-4.html

package info (click to toggle)
cmucl 20c-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 42,524 kB
  • sloc: lisp: 358,331; ansic: 28,385; asm: 3,777; sh: 1,236; makefile: 366; csh: 31
file content (64 lines) | stat: -rw-r--r-- 2,444 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<HTML>
<HEAD>
<TITLE>Common LISP Hints: Numbers</TITLE>
</HEAD>
<BODY>
<A HREF="LISP-tutorial-3.html"><IMG SRC="prev.gif" ALT="Previous"></A>
<A HREF="LISP-tutorial-5.html"><IMG SRC="next.gif" ALT="Next"></A>
<A HREF="LISP-tutorial.html#toc4"><IMG SRC="toc.gif" ALT="Contents"></A>
<HR>
<H2><A NAME="s4">4. Numbers</A></H2>

<P>An integer is a string of digits optionally preceded by + or -. A real
number looks like an integer, except that it has a decimal point and
optionally can be written in scientific notation. A rational looks like
two integers with a / between them. LISP supports complex numbers,
which are written <CODE>#c(r i)</CODE> (where r is the real part and i is the
imaginary part). A number is any of the above. Here are some numbers:</P>
<P>
<OL>
<LI>        5</LI>
<LI>        17</LI>
<LI>        -34</LI>
<LI>        +6</LI>
<LI>        3.1415</LI>
<LI>        1.722e-15</LI>
<LI>        #c(1.722e-15 0.75)</LI>
</OL>
</P>
<P>The standard arithmetic functions are all available: <CODE>+</CODE>, <CODE>-</CODE>,
<CODE>*</CODE>, <CODE>/</CODE>, <CODE>floor</CODE>, 
<CODE>ceiling</CODE>, <CODE>mod</CODE>, <CODE>sin</CODE>, <CODE>cos</CODE>, <CODE>tan</CODE>, <CODE>sqrt</CODE>,
<CODE>exp</CODE>, <CODE>expt</CODE>, and so forth. All of them
accept any kind of number as an argument. <CODE>+</CODE>, <CODE>-</CODE>, <CODE>*</CODE>, and
<CODE>/</CODE> return a
number according to type contagion: an integer plus a rational is a
rational, a rational plus a real is a real, and a real plus a complex
is a complex. Here are some examples:</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
&gt; (+ 3 3/4)             ;type contagion
15/4 
&gt; (exp 1)               ;e
2.7182817 
&gt; (exp 3)               ;e*e*e
20.085537 
&gt; (expt 3 4.2)          ;exponent with a base other than e
100.90418
&gt; (+ 5 6 7 (* 8 9 10))  ;the fns +-*/ all accept multiple arguments
</PRE>
</CODE></BLOCKQUOTE>
</P>
<P>There is no limit to the absolute value of an integer except the memory
size of your computer. Be warned that computations with bignums (as
large integers are called) can be slow. (So can computations with
rationals, especially compared to the corresponding computations with
small integers or floats.)</P>

<HR>
<A HREF="LISP-tutorial-3.html"><IMG SRC="prev.gif" ALT="Previous"></A>
<A HREF="LISP-tutorial-5.html"><IMG SRC="next.gif" ALT="Next"></A>
<A HREF="LISP-tutorial.html#toc4"><IMG SRC="toc.gif" ALT="Contents"></A>
</BODY>
</HTML>