blob: adce12f22d3f4c50ceb8d2877775794bb68b1d21 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{cmath}}
Guido van Rossum14a80241997-07-17 16:13:45 +00002\label{module-cmath}
3
4\bimodindex{cmath}
Guido van Rossum14a80241997-07-17 16:13:45 +00005This module is always available.
6It provides access to mathematical functions for complex numbers.
7The functions are:
Fred Drake1b914b31997-09-30 20:14:50 +00008
Guido van Rossum14a80241997-07-17 16:13:45 +00009\begin{funcdesc}{acos}{x}
Fred Drake1b914b31997-09-30 20:14:50 +000010Return the arc cosine of \var{x}.
Guido van Rossum14a80241997-07-17 16:13:45 +000011\end{funcdesc}
Fred Drake1b914b31997-09-30 20:14:50 +000012
13\begin{funcdesc}{acosh}{x}
14Return the hyperbolic arc cosine of \var{x}.
15\end{funcdesc}
16
17\begin{funcdesc}{asin}{x}
18Return the arc sine of \var{x}.
19\end{funcdesc}
20
21\begin{funcdesc}{asinh}{x}
22Return the hyperbolic arc sine of \var{x}.
23\end{funcdesc}
24
25\begin{funcdesc}{atan}{x}
26Return the arc tangent of \var{x}.
27\end{funcdesc}
28
29\begin{funcdesc}{atanh}{x}
30Return the hyperbolic arc tangent of \var{x}.
31\end{funcdesc}
32
33\begin{funcdesc}{cos}{x}
34Return the cosine of \var{x}.
35\end{funcdesc}
36
37\begin{funcdesc}{cosh}{x}
38Return the hyperbolic cosine of \var{x}.
39\end{funcdesc}
40
41\begin{funcdesc}{exp}{x}
Guido van Rossumc57aff21998-02-11 22:33:28 +000042Return the exponential value \code{e**\var{x}}.
Fred Drake1b914b31997-09-30 20:14:50 +000043\end{funcdesc}
44
45\begin{funcdesc}{log}{x}
46Return the natural logarithm of \var{x}.
47\end{funcdesc}
48
49\begin{funcdesc}{log10}{x}
50Return the base-10 logarithm of \var{x}.
51\end{funcdesc}
52
53\begin{funcdesc}{sin}{x}
54Return the sine of \var{x}.
55\end{funcdesc}
56
57\begin{funcdesc}{sinh}{x}
58Return the hyperbolic sine of \var{x}.
59\end{funcdesc}
60
61\begin{funcdesc}{sqrt}{x}
62Return the square root of \var{x}.
63\end{funcdesc}
64
65\begin{funcdesc}{tan}{x}
66Return the tangent of \var{x}.
67\end{funcdesc}
68
69\begin{funcdesc}{tanh}{x}
70Return the hyperbolic tangent of \var{x}.
71\end{funcdesc}
Guido van Rossum14a80241997-07-17 16:13:45 +000072
73The module also defines two mathematical constants:
Fred Drake1b914b31997-09-30 20:14:50 +000074
Guido van Rossum14a80241997-07-17 16:13:45 +000075\begin{datadesc}{pi}
Fred Drake1b914b31997-09-30 20:14:50 +000076The mathematical constant \emph{pi}, as a real.
Guido van Rossum14a80241997-07-17 16:13:45 +000077\end{datadesc}
Fred Drake1b914b31997-09-30 20:14:50 +000078
79\begin{datadesc}{e}
80The mathematical constant \emph{e}, as a real.
81\end{datadesc}
Guido van Rossum14a80241997-07-17 16:13:45 +000082
83Note that the selection of functions is similar, but not identical, to
Fred Drakeaa5dba01998-01-09 21:30:03 +000084that in module \code{math}\refbimodindex{math}. The reason for having
85two modules is, that some users aren't interested in complex numbers,
86and perhaps don't even know what they are. They would rather have
87\code{math.sqrt(-1)} raise an exception than return a complex number.
88Also note that the functions defined in \code{cmath} always return a
89complex number, even if the answer can be expressed as a real number
90(in which case the complex number has an imaginary part of zero).