blob: 7ecda2e22fc3b2a232b8f03230cfc60287ea99ef [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{math}}
Fred Drakeb91e9341998-07-23 17:59:49 +00002\declaremodule{builtin}{math}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00003
Fred Drakeb91e9341998-07-23 17:59:49 +00004
5\modulesynopsis{Mathematical functions (\function{sin()} etc.).}
6
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00007This module is always available.
Fred Drake7c418ed1998-01-22 17:37:50 +00008It provides access to the mathematical functions defined by the \C{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00009standard.
10They are:
Fred Drakeb55e07f1997-09-30 21:59:27 +000011
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000012\begin{funcdesc}{acos}{x}
Fred Drakeb55e07f1997-09-30 21:59:27 +000013Return the arc cosine of \var{x}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000014\end{funcdesc}
Fred Drakeb55e07f1997-09-30 21:59:27 +000015
16\begin{funcdesc}{asin}{x}
17Return the arc sine of \var{x}.
18\end{funcdesc}
19
20\begin{funcdesc}{atan}{x}
21Return the arc tangent of \var{x}.
22\end{funcdesc}
23
24\begin{funcdesc}{atan2}{x, y}
Fred Draked327a8d1998-01-09 21:26:51 +000025Return \code{atan(\var{x} / \var{y})}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000026\end{funcdesc}
27
28\begin{funcdesc}{ceil}{x}
Fred Drake7c418ed1998-01-22 17:37:50 +000029Return the ceiling of \var{x} as a real.
Fred Drakeb55e07f1997-09-30 21:59:27 +000030\end{funcdesc}
31
32\begin{funcdesc}{cos}{x}
33Return the cosine of \var{x}.
34\end{funcdesc}
35
36\begin{funcdesc}{cosh}{x}
37Return the hyperbolic cosine of \var{x}.
38\end{funcdesc}
39
40\begin{funcdesc}{exp}{x}
Guido van Rossumf259efe1997-11-25 01:00:40 +000041Return \code{e**\var{x}}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000042\end{funcdesc}
43
44\begin{funcdesc}{fabs}{x}
45Return the absolute value of the real \var{x}.
46\end{funcdesc}
47
48\begin{funcdesc}{floor}{x}
Fred Drake7c418ed1998-01-22 17:37:50 +000049Return the floor of \var{x} as a real.
Fred Drakeb55e07f1997-09-30 21:59:27 +000050\end{funcdesc}
51
52\begin{funcdesc}{fmod}{x, y}
Fred Draked327a8d1998-01-09 21:26:51 +000053Return \code{\var{x} \%\ \var{y}}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000054\end{funcdesc}
55
56\begin{funcdesc}{frexp}{x}
57Return the matissa and exponent for \var{x}. The mantissa is
58positive.
59\end{funcdesc}
60
61\begin{funcdesc}{hypot}{x, y}
Fred Draked327a8d1998-01-09 21:26:51 +000062Return the Euclidean distance, \code{sqrt(\var{x}*\var{x} + \var{y}*\var{y})}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000063\end{funcdesc}
64
65\begin{funcdesc}{ldexp}{x, i}
Guido van Rossumf259efe1997-11-25 01:00:40 +000066Return \code{\var{x} * (2**\var{i})}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000067\end{funcdesc}
68
Fred Drake7c418ed1998-01-22 17:37:50 +000069\begin{funcdesc}{log}{x}
70Return the natural logarithm of \var{x}.
71\end{funcdesc}
72
73\begin{funcdesc}{log10}{x}
74Return the base-10 logarithm of \var{x}.
75\end{funcdesc}
76
Fred Drakeb55e07f1997-09-30 21:59:27 +000077\begin{funcdesc}{modf}{x}
78Return the fractional and integer parts of \var{x}. Both results
Fred Drake7c418ed1998-01-22 17:37:50 +000079carry the sign of \var{x}. The integer part is returned as a real.
Fred Drakeb55e07f1997-09-30 21:59:27 +000080\end{funcdesc}
81
82\begin{funcdesc}{pow}{x, y}
Guido van Rossumf259efe1997-11-25 01:00:40 +000083Return \code{\var{x}**\var{y}}.
Fred Drakeb55e07f1997-09-30 21:59:27 +000084\end{funcdesc}
85
86\begin{funcdesc}{sin}{x}
87Return the sine of \var{x}.
88\end{funcdesc}
89
90\begin{funcdesc}{sinh}{x}
91Return the hyperbolic sine of \var{x}.
92\end{funcdesc}
93
94\begin{funcdesc}{sqrt}{x}
95Return the square root of \var{x}.
96\end{funcdesc}
97
98\begin{funcdesc}{tan}{x}
99Return the tangent of \var{x}.
100\end{funcdesc}
101
102\begin{funcdesc}{tanh}{x}
103Return the hyperbolic tangent of \var{x}.
104\end{funcdesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000105
Fred Drake7c418ed1998-01-22 17:37:50 +0000106Note that \function{frexp()} and \function{modf()} have a different
107call/return pattern than their \C{} equivalents: they take a single
108argument and return a pair of values, rather than returning their
109second return value through an `output parameter' (there is no such
110thing in Python).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000111
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000112The module also defines two mathematical constants:
Guido van Rossume47da0a1997-07-17 16:34:52 +0000113
Fred Drakeb55e07f1997-09-30 21:59:27 +0000114\begin{datadesc}{pi}
115The mathematical constant \emph{pi}.
116\end{datadesc}
117
118\begin{datadesc}{e}
119The mathematical constant \emph{e}.
120\end{datadesc}
121
Fred Drake2950b2d1997-10-13 22:06:17 +0000122\begin{seealso}
123 \seemodule{cmath}{Complex number versions of many of these functions.}
124\end{seealso}