Fred Drake | 3a0351c | 1998-04-04 07:23:21 +0000 | [diff] [blame^] | 1 | \section{Built-in Module \module{cmath}} |
Guido van Rossum | 14a8024 | 1997-07-17 16:13:45 +0000 | [diff] [blame] | 2 | \label{module-cmath} |
| 3 | |
| 4 | \bimodindex{cmath} |
Guido van Rossum | 14a8024 | 1997-07-17 16:13:45 +0000 | [diff] [blame] | 5 | This module is always available. |
| 6 | It provides access to mathematical functions for complex numbers. |
| 7 | The functions are: |
Fred Drake | 1b914b3 | 1997-09-30 20:14:50 +0000 | [diff] [blame] | 8 | |
Guido van Rossum | 14a8024 | 1997-07-17 16:13:45 +0000 | [diff] [blame] | 9 | \begin{funcdesc}{acos}{x} |
Fred Drake | 1b914b3 | 1997-09-30 20:14:50 +0000 | [diff] [blame] | 10 | Return the arc cosine of \var{x}. |
Guido van Rossum | 14a8024 | 1997-07-17 16:13:45 +0000 | [diff] [blame] | 11 | \end{funcdesc} |
Fred Drake | 1b914b3 | 1997-09-30 20:14:50 +0000 | [diff] [blame] | 12 | |
| 13 | \begin{funcdesc}{acosh}{x} |
| 14 | Return the hyperbolic arc cosine of \var{x}. |
| 15 | \end{funcdesc} |
| 16 | |
| 17 | \begin{funcdesc}{asin}{x} |
| 18 | Return the arc sine of \var{x}. |
| 19 | \end{funcdesc} |
| 20 | |
| 21 | \begin{funcdesc}{asinh}{x} |
| 22 | Return the hyperbolic arc sine of \var{x}. |
| 23 | \end{funcdesc} |
| 24 | |
| 25 | \begin{funcdesc}{atan}{x} |
| 26 | Return the arc tangent of \var{x}. |
| 27 | \end{funcdesc} |
| 28 | |
| 29 | \begin{funcdesc}{atanh}{x} |
| 30 | Return the hyperbolic arc tangent of \var{x}. |
| 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 | c57aff2 | 1998-02-11 22:33:28 +0000 | [diff] [blame] | 42 | Return the exponential value \code{e**\var{x}}. |
Fred Drake | 1b914b3 | 1997-09-30 20:14:50 +0000 | [diff] [blame] | 43 | \end{funcdesc} |
| 44 | |
| 45 | \begin{funcdesc}{log}{x} |
| 46 | Return the natural logarithm of \var{x}. |
| 47 | \end{funcdesc} |
| 48 | |
| 49 | \begin{funcdesc}{log10}{x} |
| 50 | Return the base-10 logarithm of \var{x}. |
| 51 | \end{funcdesc} |
| 52 | |
| 53 | \begin{funcdesc}{sin}{x} |
| 54 | Return the sine of \var{x}. |
| 55 | \end{funcdesc} |
| 56 | |
| 57 | \begin{funcdesc}{sinh}{x} |
| 58 | Return the hyperbolic sine of \var{x}. |
| 59 | \end{funcdesc} |
| 60 | |
| 61 | \begin{funcdesc}{sqrt}{x} |
| 62 | Return the square root of \var{x}. |
| 63 | \end{funcdesc} |
| 64 | |
| 65 | \begin{funcdesc}{tan}{x} |
| 66 | Return the tangent of \var{x}. |
| 67 | \end{funcdesc} |
| 68 | |
| 69 | \begin{funcdesc}{tanh}{x} |
| 70 | Return the hyperbolic tangent of \var{x}. |
| 71 | \end{funcdesc} |
Guido van Rossum | 14a8024 | 1997-07-17 16:13:45 +0000 | [diff] [blame] | 72 | |
| 73 | The module also defines two mathematical constants: |
Fred Drake | 1b914b3 | 1997-09-30 20:14:50 +0000 | [diff] [blame] | 74 | |
Guido van Rossum | 14a8024 | 1997-07-17 16:13:45 +0000 | [diff] [blame] | 75 | \begin{datadesc}{pi} |
Fred Drake | 1b914b3 | 1997-09-30 20:14:50 +0000 | [diff] [blame] | 76 | The mathematical constant \emph{pi}, as a real. |
Guido van Rossum | 14a8024 | 1997-07-17 16:13:45 +0000 | [diff] [blame] | 77 | \end{datadesc} |
Fred Drake | 1b914b3 | 1997-09-30 20:14:50 +0000 | [diff] [blame] | 78 | |
| 79 | \begin{datadesc}{e} |
| 80 | The mathematical constant \emph{e}, as a real. |
| 81 | \end{datadesc} |
Guido van Rossum | 14a8024 | 1997-07-17 16:13:45 +0000 | [diff] [blame] | 82 | |
| 83 | Note that the selection of functions is similar, but not identical, to |
Fred Drake | aa5dba0 | 1998-01-09 21:30:03 +0000 | [diff] [blame] | 84 | that in module \code{math}\refbimodindex{math}. The reason for having |
| 85 | two modules is, that some users aren't interested in complex numbers, |
| 86 | and perhaps don't even know what they are. They would rather have |
| 87 | \code{math.sqrt(-1)} raise an exception than return a complex number. |
| 88 | Also note that the functions defined in \code{cmath} always return a |
| 89 | complex number, even if the answer can be expressed as a real number |
| 90 | (in which case the complex number has an imaginary part of zero). |