blob: 7addda43b7afe9165d306063b0e6fe290ebf53dc [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{math} ---
2 Mathematical functions (\function{sin()} etc.).}
Fred Drakeb91e9341998-07-23 17:59:49 +00003\declaremodule{builtin}{math}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00004
Fred Drakeb91e9341998-07-23 17:59:49 +00005
6\modulesynopsis{Mathematical functions (\function{sin()} etc.).}
7
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00008This module is always available.
Fred Drake7c418ed1998-01-22 17:37:50 +00009It provides access to the mathematical functions defined by the \C{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000010standard.
11They are:
Fred Drakeb55e07f1997-09-30 21:59:27 +000012
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000013\begin{funcdesc}{acos}{x}
Fred Drakeb55e07f1997-09-30 21:59:27 +000014Return the arc cosine of \var{x}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000015\end{funcdesc}
Fred Drakeb55e07f1997-09-30 21:59:27 +000016
17\begin{funcdesc}{asin}{x}
18Return the arc sine of \var{x}.
19\end{funcdesc}
20
21\begin{funcdesc}{atan}{x}
22Return the arc tangent of \var{x}.
23\end{funcdesc}
24
Fred Drake64583d31998-12-08 16:10:44 +000025\begin{funcdesc}{atan2}{y, x}
26Return \code{atan(\var{y} / \var{x})}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000027\end{funcdesc}
28
29\begin{funcdesc}{ceil}{x}
Fred Drake7c418ed1998-01-22 17:37:50 +000030Return the ceiling of \var{x} as a real.
Fred Drakeb55e07f1997-09-30 21:59:27 +000031\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 Rossumf259efe1997-11-25 01:00:40 +000042Return \code{e**\var{x}}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000043\end{funcdesc}
44
45\begin{funcdesc}{fabs}{x}
46Return the absolute value of the real \var{x}.
47\end{funcdesc}
48
49\begin{funcdesc}{floor}{x}
Fred Drake7c418ed1998-01-22 17:37:50 +000050Return the floor of \var{x} as a real.
Fred Drakeb55e07f1997-09-30 21:59:27 +000051\end{funcdesc}
52
53\begin{funcdesc}{fmod}{x, y}
Fred Draked327a8d1998-01-09 21:26:51 +000054Return \code{\var{x} \%\ \var{y}}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000055\end{funcdesc}
56
57\begin{funcdesc}{frexp}{x}
58Return the matissa and exponent for \var{x}. The mantissa is
59positive.
60\end{funcdesc}
61
62\begin{funcdesc}{hypot}{x, y}
Fred Draked327a8d1998-01-09 21:26:51 +000063Return the Euclidean distance, \code{sqrt(\var{x}*\var{x} + \var{y}*\var{y})}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000064\end{funcdesc}
65
66\begin{funcdesc}{ldexp}{x, i}
Guido van Rossumf259efe1997-11-25 01:00:40 +000067Return \code{\var{x} * (2**\var{i})}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000068\end{funcdesc}
69
Fred Drake7c418ed1998-01-22 17:37:50 +000070\begin{funcdesc}{log}{x}
71Return the natural logarithm of \var{x}.
72\end{funcdesc}
73
74\begin{funcdesc}{log10}{x}
75Return the base-10 logarithm of \var{x}.
76\end{funcdesc}
77
Fred Drakeb55e07f1997-09-30 21:59:27 +000078\begin{funcdesc}{modf}{x}
79Return the fractional and integer parts of \var{x}. Both results
Fred Drake7c418ed1998-01-22 17:37:50 +000080carry the sign of \var{x}. The integer part is returned as a real.
Fred Drakeb55e07f1997-09-30 21:59:27 +000081\end{funcdesc}
82
83\begin{funcdesc}{pow}{x, y}
Guido van Rossumf259efe1997-11-25 01:00:40 +000084Return \code{\var{x}**\var{y}}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000085\end{funcdesc}
86
87\begin{funcdesc}{sin}{x}
88Return the sine of \var{x}.
89\end{funcdesc}
90
91\begin{funcdesc}{sinh}{x}
92Return the hyperbolic sine of \var{x}.
93\end{funcdesc}
94
95\begin{funcdesc}{sqrt}{x}
96Return the square root of \var{x}.
97\end{funcdesc}
98
99\begin{funcdesc}{tan}{x}
100Return the tangent of \var{x}.
101\end{funcdesc}
102
103\begin{funcdesc}{tanh}{x}
104Return the hyperbolic tangent of \var{x}.
105\end{funcdesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000106
Fred Drake7c418ed1998-01-22 17:37:50 +0000107Note that \function{frexp()} and \function{modf()} have a different
108call/return pattern than their \C{} equivalents: they take a single
109argument and return a pair of values, rather than returning their
110second return value through an `output parameter' (there is no such
111thing in Python).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000112
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000113The module also defines two mathematical constants:
Guido van Rossume47da0a1997-07-17 16:34:52 +0000114
Fred Drakeb55e07f1997-09-30 21:59:27 +0000115\begin{datadesc}{pi}
116The mathematical constant \emph{pi}.
117\end{datadesc}
118
119\begin{datadesc}{e}
120The mathematical constant \emph{e}.
121\end{datadesc}
122
Fred Drake2950b2d1997-10-13 22:06:17 +0000123\begin{seealso}
124 \seemodule{cmath}{Complex number versions of many of these functions.}
125\end{seealso}