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