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