blob: 935b9403c10454d6c91499bc8e14d0412d00d56b [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.
7It provides access to the mathematical functions defined by the C
8standard.
9They are:
10\iftexi
11\begin{funcdesc}{acos}{x}
12\funcline{asin}{x}
13\funcline{atan}{x}
14\funcline{atan2}{x, y}
15\funcline{ceil}{x}
16\funcline{cos}{x}
17\funcline{cosh}{x}
18\funcline{exp}{x}
19\funcline{fabs}{x}
20\funcline{floor}{x}
21\funcline{fmod}{x, y}
22\funcline{frexp}{x}
Guido van Rossum411a8bd1994-10-20 22:00:28 +000023\funcline{hypot}{x, y}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000024\funcline{ldexp}{x, y}
25\funcline{log}{x}
26\funcline{log10}{x}
27\funcline{modf}{x}
28\funcline{pow}{x, y}
29\funcline{sin}{x}
30\funcline{sinh}{x}
31\funcline{sqrt}{x}
32\funcline{tan}{x}
33\funcline{tanh}{x}
34\end{funcdesc}
35\else
36\code{acos(\varvars{x})},
37\code{asin(\varvars{x})},
38\code{atan(\varvars{x})},
39\code{atan2(\varvars{x\, y})},
40\code{ceil(\varvars{x})},
41\code{cos(\varvars{x})},
42\code{cosh(\varvars{x})},
43\code{exp(\varvars{x})},
44\code{fabs(\varvars{x})},
45\code{floor(\varvars{x})},
46\code{fmod(\varvars{x\, y})},
47\code{frexp(\varvars{x})},
Guido van Rossum31cce971995-01-04 19:17:34 +000048\code{hypot(\varvars{x\, y})},
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000049\code{ldexp(\varvars{x\, y})},
50\code{log(\varvars{x})},
51\code{log10(\varvars{x})},
52\code{modf(\varvars{x})},
53\code{pow(\varvars{x\, y})},
54\code{sin(\varvars{x})},
55\code{sinh(\varvars{x})},
56\code{sqrt(\varvars{x})},
57\code{tan(\varvars{x})},
58\code{tanh(\varvars{x})}.
59\fi
60
61Note that \code{frexp} and \code{modf} have a different call/return
62pattern than their C equivalents: they take a single argument and
63return a pair of values, rather than returning their second return
64value through an `output parameter' (there is no such thing in Python).
65
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000066The module also defines two mathematical constants:
67\iftexi
68\begin{datadesc}{pi}
69\dataline{e}
70\end{datadesc}
71\else
72\code{pi} and \code{e}.
73\fi
Guido van Rossume47da0a1997-07-17 16:34:52 +000074
75\begin{seealso}
76\seealso{cmath}{versions of these functions that can handle complex numbers}
77\end{seealso}