Guido van Rossum | 14a8024 | 1997-07-17 16:13:45 +0000 | [diff] [blame] | 1 | \section{Built-in Module \sectcode{cmath}} |
| 2 | \label{module-cmath} |
| 3 | |
| 4 | \bimodindex{cmath} |
| 5 | \renewcommand{\indexsubitem}{(in module cmath)} |
| 6 | This module is always available. |
| 7 | It provides access to mathematical functions for complex numbers. |
| 8 | The functions are: |
| 9 | \iftexi |
| 10 | \begin{funcdesc}{acos}{x} |
| 11 | \funcline{asin}{x} |
| 12 | \funcline{atan}{x} |
| 13 | \funcline{cos}{x} |
| 14 | \funcline{cosh}{x} |
| 15 | \funcline{exp}{x} |
| 16 | \funcline{log}{x} |
| 17 | \funcline{log10}{x} |
| 18 | \funcline{sin}{x} |
| 19 | \funcline{sinh}{x} |
| 20 | \funcline{sqrt}{x} |
| 21 | \funcline{tan}{x} |
| 22 | \funcline{tanh}{x} |
| 23 | \end{funcdesc} |
| 24 | \else |
| 25 | \code{acos(\varvars{x})}, |
| 26 | \code{acosh(\varvars{x})}, |
| 27 | \code{asin(\varvars{x})}, |
| 28 | \code{asinh(\varvars{x})}, |
| 29 | \code{atan(\varvars{x})}, |
| 30 | \code{atanh(\varvars{x})}, |
| 31 | \code{cos(\varvars{x})}, |
| 32 | \code{cosh(\varvars{x})}, |
| 33 | \code{exp(\varvars{x})}, |
| 34 | \code{log(\varvars{x})}, |
| 35 | \code{log10(\varvars{x})}, |
| 36 | \code{sin(\varvars{x})}, |
| 37 | \code{sinh(\varvars{x})}, |
| 38 | \code{sqrt(\varvars{x})}, |
| 39 | \code{tan(\varvars{x})}, |
| 40 | \code{tanh(\varvars{x})}. |
| 41 | \fi |
| 42 | |
| 43 | The module also defines two mathematical constants: |
| 44 | \iftexi |
| 45 | \begin{datadesc}{pi} |
| 46 | \dataline{e} |
| 47 | \end{datadesc} |
| 48 | \else |
| 49 | \code{pi} and \code{e}. |
| 50 | \fi |
| 51 | |
| 52 | Note that the selection of functions is similar, but not identical, to |
| 53 | that in module \code{math}. The reason for having two modules is, |
| 54 | that some users aren't interested in complex numbers, and perhaps |
Guido van Rossum | 246d965 | 1997-07-17 16:14:12 +0000 | [diff] [blame] | 55 | don't even know what they are. They would rather have \code{math.sqrt(-1)} |
Guido van Rossum | 14a8024 | 1997-07-17 16:13:45 +0000 | [diff] [blame] | 56 | raise an exception than return a complex number. Also note that the |
| 57 | functions defined in \code{cmath} always return a complex number, even |
| 58 | if the answer can be expressed as a real number (in which case the |
| 59 | complex number has an imaginary part of zero). |