blob: 1cc6b202dbcca4a5d4be5bc99a5f36cd626b1496 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{math}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-math}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00003
4\bimodindex{math}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00005This module is always available.
Fred Drake7c418ed1998-01-22 17:37:50 +00006It provides access to the mathematical functions defined by the \C{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00007standard.
8They are:
Fred Drakeb55e07f1997-09-30 21:59:27 +00009
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000010\begin{funcdesc}{acos}{x}
Fred Drakeb55e07f1997-09-30 21:59:27 +000011Return the arc cosine of \var{x}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000012\end{funcdesc}
Fred Drakeb55e07f1997-09-30 21:59:27 +000013
14\begin{funcdesc}{asin}{x}
15Return the arc sine of \var{x}.
16\end{funcdesc}
17
18\begin{funcdesc}{atan}{x}
19Return the arc tangent of \var{x}.
20\end{funcdesc}
21
22\begin{funcdesc}{atan2}{x, y}
Fred Draked327a8d1998-01-09 21:26:51 +000023Return \code{atan(\var{x} / \var{y})}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000024\end{funcdesc}
25
26\begin{funcdesc}{ceil}{x}
Fred Drake7c418ed1998-01-22 17:37:50 +000027Return the ceiling of \var{x} as a real.
Fred Drakeb55e07f1997-09-30 21:59:27 +000028\end{funcdesc}
29
30\begin{funcdesc}{cos}{x}
31Return the cosine of \var{x}.
32\end{funcdesc}
33
34\begin{funcdesc}{cosh}{x}
35Return the hyperbolic cosine of \var{x}.
36\end{funcdesc}
37
38\begin{funcdesc}{exp}{x}
Guido van Rossumf259efe1997-11-25 01:00:40 +000039Return \code{e**\var{x}}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000040\end{funcdesc}
41
42\begin{funcdesc}{fabs}{x}
43Return the absolute value of the real \var{x}.
44\end{funcdesc}
45
46\begin{funcdesc}{floor}{x}
Fred Drake7c418ed1998-01-22 17:37:50 +000047Return the floor of \var{x} as a real.
Fred Drakeb55e07f1997-09-30 21:59:27 +000048\end{funcdesc}
49
50\begin{funcdesc}{fmod}{x, y}
Fred Draked327a8d1998-01-09 21:26:51 +000051Return \code{\var{x} \%\ \var{y}}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000052\end{funcdesc}
53
54\begin{funcdesc}{frexp}{x}
55Return the matissa and exponent for \var{x}. The mantissa is
56positive.
57\end{funcdesc}
58
59\begin{funcdesc}{hypot}{x, y}
Fred Draked327a8d1998-01-09 21:26:51 +000060Return the Euclidean distance, \code{sqrt(\var{x}*\var{x} + \var{y}*\var{y})}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000061\end{funcdesc}
62
63\begin{funcdesc}{ldexp}{x, i}
Guido van Rossumf259efe1997-11-25 01:00:40 +000064Return \code{\var{x} * (2**\var{i})}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000065\end{funcdesc}
66
Fred Drake7c418ed1998-01-22 17:37:50 +000067\begin{funcdesc}{log}{x}
68Return the natural logarithm of \var{x}.
69\end{funcdesc}
70
71\begin{funcdesc}{log10}{x}
72Return the base-10 logarithm of \var{x}.
73\end{funcdesc}
74
Fred Drakeb55e07f1997-09-30 21:59:27 +000075\begin{funcdesc}{modf}{x}
76Return the fractional and integer parts of \var{x}. Both results
Fred Drake7c418ed1998-01-22 17:37:50 +000077carry the sign of \var{x}. The integer part is returned as a real.
Fred Drakeb55e07f1997-09-30 21:59:27 +000078\end{funcdesc}
79
80\begin{funcdesc}{pow}{x, y}
Guido van Rossumf259efe1997-11-25 01:00:40 +000081Return \code{\var{x}**\var{y}}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000082\end{funcdesc}
83
84\begin{funcdesc}{sin}{x}
85Return the sine of \var{x}.
86\end{funcdesc}
87
88\begin{funcdesc}{sinh}{x}
89Return the hyperbolic sine of \var{x}.
90\end{funcdesc}
91
92\begin{funcdesc}{sqrt}{x}
93Return the square root of \var{x}.
94\end{funcdesc}
95
96\begin{funcdesc}{tan}{x}
97Return the tangent of \var{x}.
98\end{funcdesc}
99
100\begin{funcdesc}{tanh}{x}
101Return the hyperbolic tangent of \var{x}.
102\end{funcdesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000103
Fred Drake7c418ed1998-01-22 17:37:50 +0000104Note that \function{frexp()} and \function{modf()} have a different
105call/return pattern than their \C{} equivalents: they take a single
106argument and return a pair of values, rather than returning their
107second return value through an `output parameter' (there is no such
108thing in Python).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000109
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000110The module also defines two mathematical constants:
Guido van Rossume47da0a1997-07-17 16:34:52 +0000111
Fred Drakeb55e07f1997-09-30 21:59:27 +0000112\begin{datadesc}{pi}
113The mathematical constant \emph{pi}.
114\end{datadesc}
115
116\begin{datadesc}{e}
117The mathematical constant \emph{e}.
118\end{datadesc}
119
Fred Drake2950b2d1997-10-13 22:06:17 +0000120\begin{seealso}
121 \seemodule{cmath}{Complex number versions of many of these functions.}
122\end{seealso}