diff options
author | Georg Brandl <georg@python.org> | 2007-03-17 16:08:45 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2007-03-17 16:08:45 (GMT) |
commit | 2b869943fa284be9f3b9572df10b334f12962aa6 (patch) | |
tree | 4b14375b0251356b2399d78107c2cb3d4f7fc111 /Doc | |
parent | 6f187743ffbce522c9d686ae5393272c1eb85dcc (diff) | |
download | cpython-2b869943fa284be9f3b9572df10b334f12962aa6.zip cpython-2b869943fa284be9f3b9572df10b334f12962aa6.tar.gz cpython-2b869943fa284be9f3b9572df10b334f12962aa6.tar.bz2 |
Patch #1675423: PyComplex_AsCComplex() now tries to convert an object
to complex using its __complex__() method before falling back to the
__float__() method. Therefore, the functions in the cmath module now
can operate on objects that define a __complex__() method.
(backport)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/api/concrete.tex | 11 | ||||
-rw-r--r-- | Doc/lib/libcmath.tex | 9 |
2 files changed, 16 insertions, 4 deletions
diff --git a/Doc/api/concrete.tex b/Doc/api/concrete.tex index e2d3e52..3b2945e 100644 --- a/Doc/api/concrete.tex +++ b/Doc/api/concrete.tex @@ -443,7 +443,9 @@ booleans. The following macros are available, however. \begin{cfuncdesc}{double}{PyFloat_AsDouble}{PyObject *pyfloat} Return a C \ctype{double} representation of the contents of - \var{pyfloat}. + \var{pyfloat}. If \var{pyfloat} is not a Python floating point + object but has a \method{__float__} method, this method will first + be called to convert \var{pyfloat} into a float. \end{cfuncdesc} \begin{cfuncdesc}{double}{PyFloat_AS_DOUBLE}{PyObject *pyfloat} @@ -558,8 +560,11 @@ typedef struct { \end{cfuncdesc} \begin{cfuncdesc}{Py_complex}{PyComplex_AsCComplex}{PyObject *op} - Return the \ctype{Py_complex} value of the complex number - \var{op}. + Return the \ctype{Py_complex} value of the complex number \var{op}. + \versionchanged[If \var{op} is not a Python complex number object + but has a \method{__complex__} method, this method + will first be called to convert \var{op} to a Python + complex number object]{2.6} \end{cfuncdesc} diff --git a/Doc/lib/libcmath.tex b/Doc/lib/libcmath.tex index 54e0cdb..f8aa45b 100644 --- a/Doc/lib/libcmath.tex +++ b/Doc/lib/libcmath.tex @@ -5,7 +5,14 @@ \modulesynopsis{Mathematical functions for complex numbers.} This module is always available. It provides access to mathematical -functions for complex numbers. The functions are: +functions for complex numbers. The functions in this module accept +integers, floating-point numbers or complex numbers as arguments. +They will also accept any Python object that has either a +\method{__complex__} or a \method{__float__} method: these methods are +used to convert the object to a complex or floating-point number, respectively, and +the function is then applied to the result of the conversion. + +The functions are: \begin{funcdesc}{acos}{x} Return the arc cosine of \var{x}. |