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