blob: c40030b30f72e01a446cb35ac13079c7976947b1 [file] [log] [blame]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001\section{Built-in Module \sectcode{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}
5\renewcommand{\indexsubitem}{(in module math)}
6This module is always available.
Fred Drake7c418ed1998-01-22 17:37:50 +00007It provides access to the mathematical functions defined by the \C{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00008standard.
9They are:
Fred Drakeb55e07f1997-09-30 21:59:27 +000010
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000011\begin{funcdesc}{acos}{x}
Fred Drakeb55e07f1997-09-30 21:59:27 +000012Return the arc cosine of \var{x}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000013\end{funcdesc}
Fred Drakeb55e07f1997-09-30 21:59:27 +000014
15\begin{funcdesc}{asin}{x}
16Return the arc sine of \var{x}.
17\end{funcdesc}
18
19\begin{funcdesc}{atan}{x}
20Return the arc tangent of \var{x}.
21\end{funcdesc}
22
23\begin{funcdesc}{atan2}{x, y}
Fred Draked327a8d1998-01-09 21:26:51 +000024Return \code{atan(\var{x} / \var{y})}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000025\end{funcdesc}
26
27\begin{funcdesc}{ceil}{x}
Fred Drake7c418ed1998-01-22 17:37:50 +000028Return the ceiling of \var{x} as a real.
Fred Drakeb55e07f1997-09-30 21:59:27 +000029\end{funcdesc}
30
31\begin{funcdesc}{cos}{x}
32Return the cosine of \var{x}.
33\end{funcdesc}
34
35\begin{funcdesc}{cosh}{x}
36Return the hyperbolic cosine of \var{x}.
37\end{funcdesc}
38
39\begin{funcdesc}{exp}{x}
Guido van Rossumf259efe1997-11-25 01:00:40 +000040Return \code{e**\var{x}}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000041\end{funcdesc}
42
43\begin{funcdesc}{fabs}{x}
44Return the absolute value of the real \var{x}.
45\end{funcdesc}
46
47\begin{funcdesc}{floor}{x}
Fred Drake7c418ed1998-01-22 17:37:50 +000048Return the floor of \var{x} as a real.
Fred Drakeb55e07f1997-09-30 21:59:27 +000049\end{funcdesc}
50
51\begin{funcdesc}{fmod}{x, y}
Fred Draked327a8d1998-01-09 21:26:51 +000052Return \code{\var{x} \%\ \var{y}}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000053\end{funcdesc}
54
55\begin{funcdesc}{frexp}{x}
56Return the matissa and exponent for \var{x}. The mantissa is
57positive.
58\end{funcdesc}
59
60\begin{funcdesc}{hypot}{x, y}
Fred Draked327a8d1998-01-09 21:26:51 +000061Return the Euclidean distance, \code{sqrt(\var{x}*\var{x} + \var{y}*\var{y})}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000062\end{funcdesc}
63
64\begin{funcdesc}{ldexp}{x, i}
Guido van Rossumf259efe1997-11-25 01:00:40 +000065Return \code{\var{x} * (2**\var{i})}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000066\end{funcdesc}
67
Fred Drake7c418ed1998-01-22 17:37:50 +000068\begin{funcdesc}{log}{x}
69Return the natural logarithm of \var{x}.
70\end{funcdesc}
71
72\begin{funcdesc}{log10}{x}
73Return the base-10 logarithm of \var{x}.
74\end{funcdesc}
75
Fred Drakeb55e07f1997-09-30 21:59:27 +000076\begin{funcdesc}{modf}{x}
77Return the fractional and integer parts of \var{x}. Both results
Fred Drake7c418ed1998-01-22 17:37:50 +000078carry the sign of \var{x}. The integer part is returned as a real.
Fred Drakeb55e07f1997-09-30 21:59:27 +000079\end{funcdesc}
80
81\begin{funcdesc}{pow}{x, y}
Guido van Rossumf259efe1997-11-25 01:00:40 +000082Return \code{\var{x}**\var{y}}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000083\end{funcdesc}
84
85\begin{funcdesc}{sin}{x}
86Return the sine of \var{x}.
87\end{funcdesc}
88
89\begin{funcdesc}{sinh}{x}
90Return the hyperbolic sine of \var{x}.
91\end{funcdesc}
92
93\begin{funcdesc}{sqrt}{x}
94Return the square root of \var{x}.
95\end{funcdesc}
96
97\begin{funcdesc}{tan}{x}
98Return the tangent of \var{x}.
99\end{funcdesc}
100
101\begin{funcdesc}{tanh}{x}
102Return the hyperbolic tangent of \var{x}.
103\end{funcdesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000104
Fred Drake7c418ed1998-01-22 17:37:50 +0000105Note that \function{frexp()} and \function{modf()} have a different
106call/return pattern than their \C{} equivalents: they take a single
107argument and return a pair of values, rather than returning their
108second return value through an `output parameter' (there is no such
109thing in Python).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000110
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000111The module also defines two mathematical constants:
Guido van Rossume47da0a1997-07-17 16:34:52 +0000112
Fred Drakeb55e07f1997-09-30 21:59:27 +0000113\begin{datadesc}{pi}
114The mathematical constant \emph{pi}.
115\end{datadesc}
116
117\begin{datadesc}{e}
118The mathematical constant \emph{e}.
119\end{datadesc}
120
Fred Drake2950b2d1997-10-13 22:06:17 +0000121\begin{seealso}
122 \seemodule{cmath}{Complex number versions of many of these functions.}
123\end{seealso}