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