blob: 0a4a6670c08acb0d491db7890edc4d03c33e3b64 [file] [log] [blame]
Guido van Rossum14a80241997-07-17 16:13:45 +00001\section{Built-in Module \sectcode{cmath}}
2\label{module-cmath}
3
4\bimodindex{cmath}
5\renewcommand{\indexsubitem}{(in module cmath)}
6This module is always available.
7It provides access to mathematical functions for complex numbers.
8The functions are:
9\iftexi
10\begin{funcdesc}{acos}{x}
11\funcline{asin}{x}
12\funcline{atan}{x}
13\funcline{cos}{x}
14\funcline{cosh}{x}
15\funcline{exp}{x}
16\funcline{log}{x}
17\funcline{log10}{x}
18\funcline{sin}{x}
19\funcline{sinh}{x}
20\funcline{sqrt}{x}
21\funcline{tan}{x}
22\funcline{tanh}{x}
23\end{funcdesc}
24\else
25\code{acos(\varvars{x})},
26\code{acosh(\varvars{x})},
27\code{asin(\varvars{x})},
28\code{asinh(\varvars{x})},
29\code{atan(\varvars{x})},
30\code{atanh(\varvars{x})},
31\code{cos(\varvars{x})},
32\code{cosh(\varvars{x})},
33\code{exp(\varvars{x})},
34\code{log(\varvars{x})},
35\code{log10(\varvars{x})},
36\code{sin(\varvars{x})},
37\code{sinh(\varvars{x})},
38\code{sqrt(\varvars{x})},
39\code{tan(\varvars{x})},
40\code{tanh(\varvars{x})}.
41\fi
42
43The module also defines two mathematical constants:
44\iftexi
45\begin{datadesc}{pi}
46\dataline{e}
47\end{datadesc}
48\else
49\code{pi} and \code{e}.
50\fi
51
52Note that the selection of functions is similar, but not identical, to
53that in module \code{math}. The reason for having two modules is,
54that some users aren't interested in complex numbers, and perhaps
Guido van Rossum246d9651997-07-17 16:14:12 +000055don't even know what they are. They would rather have \code{math.sqrt(-1)}
Guido van Rossum14a80241997-07-17 16:13:45 +000056raise an exception than return a complex number. Also note that the
57functions defined in \code{cmath} always return a complex number, even
58if the answer can be expressed as a real number (in which case the
59complex number has an imaginary part of zero).