Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 1 | \section{Built-in Module \sectcode{math}} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 2 | \label{module-math} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 3 | |
| 4 | \bimodindex{math} |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 5 | \setindexsubitem{(in module math)} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 6 | This module is always available. |
Fred Drake | 7c418ed | 1998-01-22 17:37:50 +0000 | [diff] [blame] | 7 | It provides access to the mathematical functions defined by the \C{} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 8 | standard. |
| 9 | They are: |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 10 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 11 | \begin{funcdesc}{acos}{x} |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 12 | Return the arc cosine of \var{x}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 13 | \end{funcdesc} |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 14 | |
| 15 | \begin{funcdesc}{asin}{x} |
| 16 | Return the arc sine of \var{x}. |
| 17 | \end{funcdesc} |
| 18 | |
| 19 | \begin{funcdesc}{atan}{x} |
| 20 | Return the arc tangent of \var{x}. |
| 21 | \end{funcdesc} |
| 22 | |
| 23 | \begin{funcdesc}{atan2}{x, y} |
Fred Drake | d327a8d | 1998-01-09 21:26:51 +0000 | [diff] [blame] | 24 | Return \code{atan(\var{x} / \var{y})}. |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 25 | \end{funcdesc} |
| 26 | |
| 27 | \begin{funcdesc}{ceil}{x} |
Fred Drake | 7c418ed | 1998-01-22 17:37:50 +0000 | [diff] [blame] | 28 | Return the ceiling of \var{x} as a real. |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 29 | \end{funcdesc} |
| 30 | |
| 31 | \begin{funcdesc}{cos}{x} |
| 32 | Return the cosine of \var{x}. |
| 33 | \end{funcdesc} |
| 34 | |
| 35 | \begin{funcdesc}{cosh}{x} |
| 36 | Return the hyperbolic cosine of \var{x}. |
| 37 | \end{funcdesc} |
| 38 | |
| 39 | \begin{funcdesc}{exp}{x} |
Guido van Rossum | f259efe | 1997-11-25 01:00:40 +0000 | [diff] [blame] | 40 | Return \code{e**\var{x}}. |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 41 | \end{funcdesc} |
| 42 | |
| 43 | \begin{funcdesc}{fabs}{x} |
| 44 | Return the absolute value of the real \var{x}. |
| 45 | \end{funcdesc} |
| 46 | |
| 47 | \begin{funcdesc}{floor}{x} |
Fred Drake | 7c418ed | 1998-01-22 17:37:50 +0000 | [diff] [blame] | 48 | Return the floor of \var{x} as a real. |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 49 | \end{funcdesc} |
| 50 | |
| 51 | \begin{funcdesc}{fmod}{x, y} |
Fred Drake | d327a8d | 1998-01-09 21:26:51 +0000 | [diff] [blame] | 52 | Return \code{\var{x} \%\ \var{y}}. |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 53 | \end{funcdesc} |
| 54 | |
| 55 | \begin{funcdesc}{frexp}{x} |
| 56 | Return the matissa and exponent for \var{x}. The mantissa is |
| 57 | positive. |
| 58 | \end{funcdesc} |
| 59 | |
| 60 | \begin{funcdesc}{hypot}{x, y} |
Fred Drake | d327a8d | 1998-01-09 21:26:51 +0000 | [diff] [blame] | 61 | Return the Euclidean distance, \code{sqrt(\var{x}*\var{x} + \var{y}*\var{y})}. |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 62 | \end{funcdesc} |
| 63 | |
| 64 | \begin{funcdesc}{ldexp}{x, i} |
Guido van Rossum | f259efe | 1997-11-25 01:00:40 +0000 | [diff] [blame] | 65 | Return \code{\var{x} * (2**\var{i})}. |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 66 | \end{funcdesc} |
| 67 | |
Fred Drake | 7c418ed | 1998-01-22 17:37:50 +0000 | [diff] [blame] | 68 | \begin{funcdesc}{log}{x} |
| 69 | Return the natural logarithm of \var{x}. |
| 70 | \end{funcdesc} |
| 71 | |
| 72 | \begin{funcdesc}{log10}{x} |
| 73 | Return the base-10 logarithm of \var{x}. |
| 74 | \end{funcdesc} |
| 75 | |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 76 | \begin{funcdesc}{modf}{x} |
| 77 | Return the fractional and integer parts of \var{x}. Both results |
Fred Drake | 7c418ed | 1998-01-22 17:37:50 +0000 | [diff] [blame] | 78 | carry the sign of \var{x}. The integer part is returned as a real. |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 79 | \end{funcdesc} |
| 80 | |
| 81 | \begin{funcdesc}{pow}{x, y} |
Guido van Rossum | f259efe | 1997-11-25 01:00:40 +0000 | [diff] [blame] | 82 | Return \code{\var{x}**\var{y}}. |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 83 | \end{funcdesc} |
| 84 | |
| 85 | \begin{funcdesc}{sin}{x} |
| 86 | Return the sine of \var{x}. |
| 87 | \end{funcdesc} |
| 88 | |
| 89 | \begin{funcdesc}{sinh}{x} |
| 90 | Return the hyperbolic sine of \var{x}. |
| 91 | \end{funcdesc} |
| 92 | |
| 93 | \begin{funcdesc}{sqrt}{x} |
| 94 | Return the square root of \var{x}. |
| 95 | \end{funcdesc} |
| 96 | |
| 97 | \begin{funcdesc}{tan}{x} |
| 98 | Return the tangent of \var{x}. |
| 99 | \end{funcdesc} |
| 100 | |
| 101 | \begin{funcdesc}{tanh}{x} |
| 102 | Return the hyperbolic tangent of \var{x}. |
| 103 | \end{funcdesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 104 | |
Fred Drake | 7c418ed | 1998-01-22 17:37:50 +0000 | [diff] [blame] | 105 | Note that \function{frexp()} and \function{modf()} have a different |
| 106 | call/return pattern than their \C{} equivalents: they take a single |
| 107 | argument and return a pair of values, rather than returning their |
| 108 | second return value through an `output parameter' (there is no such |
| 109 | thing in Python). |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 110 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 111 | The module also defines two mathematical constants: |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 112 | |
Fred Drake | b55e07f | 1997-09-30 21:59:27 +0000 | [diff] [blame] | 113 | \begin{datadesc}{pi} |
| 114 | The mathematical constant \emph{pi}. |
| 115 | \end{datadesc} |
| 116 | |
| 117 | \begin{datadesc}{e} |
| 118 | The mathematical constant \emph{e}. |
| 119 | \end{datadesc} |
| 120 | |
Fred Drake | 2950b2d | 1997-10-13 22:06:17 +0000 | [diff] [blame] | 121 | \begin{seealso} |
| 122 | \seemodule{cmath}{Complex number versions of many of these functions.} |
| 123 | \end{seealso} |