blob: 48733461ee81901b05940dd7f1b2e20219889efa [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:
Fred Drake1b914b31997-09-30 20:14:50 +00009
Guido van Rossum14a80241997-07-17 16:13:45 +000010\begin{funcdesc}{acos}{x}
Fred Drake1b914b31997-09-30 20:14:50 +000011Return the arc cosine of \var{x}.
Guido van Rossum14a80241997-07-17 16:13:45 +000012\end{funcdesc}
Fred Drake1b914b31997-09-30 20:14:50 +000013
14\begin{funcdesc}{acosh}{x}
15Return the hyperbolic arc cosine of \var{x}.
16\end{funcdesc}
17
18\begin{funcdesc}{asin}{x}
19Return the arc sine of \var{x}.
20\end{funcdesc}
21
22\begin{funcdesc}{asinh}{x}
23Return the hyperbolic arc sine of \var{x}.
24\end{funcdesc}
25
26\begin{funcdesc}{atan}{x}
27Return the arc tangent of \var{x}.
28\end{funcdesc}
29
30\begin{funcdesc}{atanh}{x}
31Return the hyperbolic arc tangent of \var{x}.
32\end{funcdesc}
33
34\begin{funcdesc}{cos}{x}
35Return the cosine of \var{x}.
36\end{funcdesc}
37
38\begin{funcdesc}{cosh}{x}
39Return the hyperbolic cosine of \var{x}.
40\end{funcdesc}
41
42\begin{funcdesc}{exp}{x}
43Return the exponential value $\mbox{e}^x$.
44\end{funcdesc}
45
46\begin{funcdesc}{log}{x}
47Return the natural logarithm of \var{x}.
48\end{funcdesc}
49
50\begin{funcdesc}{log10}{x}
51Return the base-10 logarithm of \var{x}.
52\end{funcdesc}
53
54\begin{funcdesc}{sin}{x}
55Return the sine of \var{x}.
56\end{funcdesc}
57
58\begin{funcdesc}{sinh}{x}
59Return the hyperbolic sine of \var{x}.
60\end{funcdesc}
61
62\begin{funcdesc}{sqrt}{x}
63Return the square root of \var{x}.
64\end{funcdesc}
65
66\begin{funcdesc}{tan}{x}
67Return the tangent of \var{x}.
68\end{funcdesc}
69
70\begin{funcdesc}{tanh}{x}
71Return the hyperbolic tangent of \var{x}.
72\end{funcdesc}
Guido van Rossum14a80241997-07-17 16:13:45 +000073
74The module also defines two mathematical constants:
Fred Drake1b914b31997-09-30 20:14:50 +000075
Guido van Rossum14a80241997-07-17 16:13:45 +000076\begin{datadesc}{pi}
Fred Drake1b914b31997-09-30 20:14:50 +000077The mathematical constant \emph{pi}, as a real.
Guido van Rossum14a80241997-07-17 16:13:45 +000078\end{datadesc}
Fred Drake1b914b31997-09-30 20:14:50 +000079
80\begin{datadesc}{e}
81The mathematical constant \emph{e}, as a real.
82\end{datadesc}
Guido van Rossum14a80241997-07-17 16:13:45 +000083
84Note that the selection of functions is similar, but not identical, to
Fred Drakeaa5dba01998-01-09 21:30:03 +000085that in module \code{math}\refbimodindex{math}. The reason for having
86two modules is, that some users aren't interested in complex numbers,
87and perhaps don't even know what they are. They would rather have
88\code{math.sqrt(-1)} raise an exception than return a complex number.
89Also note that the functions defined in \code{cmath} always return a
90complex number, even if the answer can be expressed as a real number
91(in which case the complex number has an imaginary part of zero).