Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b0fc4903
Commit
b0fc4903
authored
Oct 14, 2014
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20152: Convert the cmath module to Argument Clinic.
parent
c7dc55eb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1120 additions
and
224 deletions
+1120
-224
Misc/NEWS
Misc/NEWS
+2
-2
Modules/clinic/cmathmodule.c.h
Modules/clinic/cmathmodule.c.h
+851
-0
Modules/cmathmodule.c
Modules/cmathmodule.c
+267
-222
No files found.
Misc/NEWS
View file @
b0fc4903
...
...
@@ -16,8 +16,6 @@ Core and Builtins
- Issue #22604: Fix assertion error in debug mode when dividing a complex
number by (nan+0j).
- Issue #20152: Convert the array module to Argument Clinic.
- Issue #21052: Do not raise ImportWarning when sys.path_hooks or sys.meta_path
are set to None.
...
...
@@ -177,6 +175,8 @@ Core and Builtins
Library
-------
-
Issue
#
20152
:
Convert
the
array
and
cmath
modules
to
Argument
Clinic
.
-
Issue
#
18643
:
Add
socket
.
socketpair
()
on
Windows
.
-
Issue
#
22435
:
Fix
a
file
descriptor
leak
when
SocketServer
bind
fails
.
...
...
Modules/clinic/cmathmodule.c.h
0 → 100644
View file @
b0fc4903
/*[clinic input]
preserve
[clinic start generated code]*/
PyDoc_STRVAR
(
cmath_acos__doc__
,
"acos($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the arc cosine of z."
);
#define CMATH_ACOS_METHODDEF \
{"acos", (PyCFunction)cmath_acos, METH_VARARGS, cmath_acos__doc__},
static
Py_complex
cmath_acos_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_acos
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:acos"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_acos_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_acosh__doc__
,
"acosh($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the hyperbolic arccosine of z."
);
#define CMATH_ACOSH_METHODDEF \
{"acosh", (PyCFunction)cmath_acosh, METH_VARARGS, cmath_acosh__doc__},
static
Py_complex
cmath_acosh_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_acosh
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:acosh"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_acosh_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_asin__doc__
,
"asin($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the arc sine of z."
);
#define CMATH_ASIN_METHODDEF \
{"asin", (PyCFunction)cmath_asin, METH_VARARGS, cmath_asin__doc__},
static
Py_complex
cmath_asin_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_asin
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:asin"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_asin_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_asinh__doc__
,
"asinh($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the hyperbolic arc sine of z."
);
#define CMATH_ASINH_METHODDEF \
{"asinh", (PyCFunction)cmath_asinh, METH_VARARGS, cmath_asinh__doc__},
static
Py_complex
cmath_asinh_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_asinh
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:asinh"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_asinh_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_atan__doc__
,
"atan($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the arc tangent of z."
);
#define CMATH_ATAN_METHODDEF \
{"atan", (PyCFunction)cmath_atan, METH_VARARGS, cmath_atan__doc__},
static
Py_complex
cmath_atan_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_atan
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:atan"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_atan_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_atanh__doc__
,
"atanh($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the hyperbolic arc tangent of z."
);
#define CMATH_ATANH_METHODDEF \
{"atanh", (PyCFunction)cmath_atanh, METH_VARARGS, cmath_atanh__doc__},
static
Py_complex
cmath_atanh_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_atanh
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:atanh"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_atanh_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_cos__doc__
,
"cos($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the cosine of z."
);
#define CMATH_COS_METHODDEF \
{"cos", (PyCFunction)cmath_cos, METH_VARARGS, cmath_cos__doc__},
static
Py_complex
cmath_cos_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_cos
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:cos"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_cos_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_cosh__doc__
,
"cosh($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the hyperbolic cosine of z."
);
#define CMATH_COSH_METHODDEF \
{"cosh", (PyCFunction)cmath_cosh, METH_VARARGS, cmath_cosh__doc__},
static
Py_complex
cmath_cosh_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_cosh
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:cosh"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_cosh_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_exp__doc__
,
"exp($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the exponential value e**z."
);
#define CMATH_EXP_METHODDEF \
{"exp", (PyCFunction)cmath_exp, METH_VARARGS, cmath_exp__doc__},
static
Py_complex
cmath_exp_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_exp
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:exp"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_exp_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_log10__doc__
,
"log10($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the base-10 logarithm of z."
);
#define CMATH_LOG10_METHODDEF \
{"log10", (PyCFunction)cmath_log10, METH_VARARGS, cmath_log10__doc__},
static
Py_complex
cmath_log10_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_log10
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:log10"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_log10_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_sin__doc__
,
"sin($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the sine of z."
);
#define CMATH_SIN_METHODDEF \
{"sin", (PyCFunction)cmath_sin, METH_VARARGS, cmath_sin__doc__},
static
Py_complex
cmath_sin_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_sin
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:sin"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_sin_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_sinh__doc__
,
"sinh($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the hyperbolic sine of z."
);
#define CMATH_SINH_METHODDEF \
{"sinh", (PyCFunction)cmath_sinh, METH_VARARGS, cmath_sinh__doc__},
static
Py_complex
cmath_sinh_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_sinh
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:sinh"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_sinh_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_sqrt__doc__
,
"sqrt($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the square root of z."
);
#define CMATH_SQRT_METHODDEF \
{"sqrt", (PyCFunction)cmath_sqrt, METH_VARARGS, cmath_sqrt__doc__},
static
Py_complex
cmath_sqrt_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_sqrt
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:sqrt"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_sqrt_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_tan__doc__
,
"tan($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the tangent of z."
);
#define CMATH_TAN_METHODDEF \
{"tan", (PyCFunction)cmath_tan, METH_VARARGS, cmath_tan__doc__},
static
Py_complex
cmath_tan_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_tan
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:tan"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_tan_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_tanh__doc__
,
"tanh($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return the hyperbolic tangent of z."
);
#define CMATH_TANH_METHODDEF \
{"tanh", (PyCFunction)cmath_tanh, METH_VARARGS, cmath_tanh__doc__},
static
Py_complex
cmath_tanh_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_tanh
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
Py_complex
_return_value
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:tanh"
,
&
z
))
goto
exit
;
/* modifications for z */
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
goto
exit
);
_return_value
=
cmath_tanh_impl
(
module
,
z
);
PyFPE_END_PROTECT
(
_return_value
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
goto
exit
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
goto
exit
;
}
else
{
return_value
=
PyComplex_FromCComplex
(
_return_value
);
}
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_log__doc__
,
"log($module, x, y_obj=None, /)
\n
"
"--
\n
"
"
\n
"
"The logarithm of z to the given base.
\n
"
"
\n
"
"If the base not specified, returns the natural logarithm (base e) of z."
);
#define CMATH_LOG_METHODDEF \
{"log", (PyCFunction)cmath_log, METH_VARARGS, cmath_log__doc__},
static
PyObject
*
cmath_log_impl
(
PyModuleDef
*
module
,
Py_complex
x
,
PyObject
*
y_obj
);
static
PyObject
*
cmath_log
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
x
;
PyObject
*
y_obj
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"D|O:log"
,
&
x
,
&
y_obj
))
goto
exit
;
return_value
=
cmath_log_impl
(
module
,
x
,
y_obj
);
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_phase__doc__
,
"phase($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return argument, also known as the phase angle, of a complex."
);
#define CMATH_PHASE_METHODDEF \
{"phase", (PyCFunction)cmath_phase, METH_VARARGS, cmath_phase__doc__},
static
PyObject
*
cmath_phase_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_phase
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:phase"
,
&
z
))
goto
exit
;
return_value
=
cmath_phase_impl
(
module
,
z
);
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_polar__doc__
,
"polar($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Convert a complex from rectangular coordinates to polar coordinates.
\n
"
"
\n
"
"r is the distance from 0 and phi the phase angle."
);
#define CMATH_POLAR_METHODDEF \
{"polar", (PyCFunction)cmath_polar, METH_VARARGS, cmath_polar__doc__},
static
PyObject
*
cmath_polar_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_polar
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:polar"
,
&
z
))
goto
exit
;
return_value
=
cmath_polar_impl
(
module
,
z
);
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_rect__doc__
,
"rect($module, r, phi, /)
\n
"
"--
\n
"
"
\n
"
"Convert from polar coordinates to rectangular coordinates."
);
#define CMATH_RECT_METHODDEF \
{"rect", (PyCFunction)cmath_rect, METH_VARARGS, cmath_rect__doc__},
static
PyObject
*
cmath_rect_impl
(
PyModuleDef
*
module
,
double
r
,
double
phi
);
static
PyObject
*
cmath_rect
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
double
r
;
double
phi
;
if
(
!
PyArg_ParseTuple
(
args
,
"dd:rect"
,
&
r
,
&
phi
))
goto
exit
;
return_value
=
cmath_rect_impl
(
module
,
r
,
phi
);
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_isfinite__doc__
,
"isfinite($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Return True if both the real and imaginary parts of z are finite, else False."
);
#define CMATH_ISFINITE_METHODDEF \
{"isfinite", (PyCFunction)cmath_isfinite, METH_VARARGS, cmath_isfinite__doc__},
static
PyObject
*
cmath_isfinite_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_isfinite
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:isfinite"
,
&
z
))
goto
exit
;
return_value
=
cmath_isfinite_impl
(
module
,
z
);
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_isnan__doc__
,
"isnan($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Checks if the real or imaginary part of z not a number (NaN)."
);
#define CMATH_ISNAN_METHODDEF \
{"isnan", (PyCFunction)cmath_isnan, METH_VARARGS, cmath_isnan__doc__},
static
PyObject
*
cmath_isnan_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_isnan
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:isnan"
,
&
z
))
goto
exit
;
return_value
=
cmath_isnan_impl
(
module
,
z
);
exit:
return
return_value
;
}
PyDoc_STRVAR
(
cmath_isinf__doc__
,
"isinf($module, z, /)
\n
"
"--
\n
"
"
\n
"
"Checks if the real or imaginary part of z is infinite."
);
#define CMATH_ISINF_METHODDEF \
{"isinf", (PyCFunction)cmath_isinf, METH_VARARGS, cmath_isinf__doc__},
static
PyObject
*
cmath_isinf_impl
(
PyModuleDef
*
module
,
Py_complex
z
);
static
PyObject
*
cmath_isinf
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_complex
z
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:isinf"
,
&
z
))
goto
exit
;
return_value
=
cmath_isinf_impl
(
module
,
z
);
exit:
return
return_value
;
}
/*[clinic end generated code: output=4407f898ae07c83d input=a9049054013a1b77]*/
Modules/cmathmodule.c
View file @
b0fc4903
...
...
@@ -8,6 +8,41 @@
float.h. We assume that FLT_RADIX is either 2 or 16. */
#include <float.h>
#include "clinic/cmathmodule.c.h"
/*[clinic input]
output preset file
module cmath
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=ef7e0fdd8a143c03]*/
/*[python input]
class Py_complex_protected_converter(Py_complex_converter):
def modify(self):
return 'errno = 0; PyFPE_START_PROTECT("complex function", goto exit);'
class Py_complex_protected_return_converter(CReturnConverter):
type = "Py_complex"
def render(self, function, data):
self.declare(data)
data.return_conversion.append("""
PyFPE_END_PROTECT(_return_value);
if (errno == EDOM) {{
PyErr_SetString(PyExc_ValueError, "math domain error");
goto exit;
}}
else if (errno == ERANGE) {{
PyErr_SetString(PyExc_OverflowError, "math range error");
goto exit;
}}
else {{
return_value = PyComplex_FromCComplex(_return_value);
}}
""".strip())
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=231019039a6fbb9a]*/
#if (FLT_RADIX != 2 && FLT_RADIX != 16)
#error "Modules/cmathmodule.c expects FLT_RADIX to be 2 or 16"
#endif
...
...
@@ -48,12 +83,12 @@
#define CM_SCALE_DOWN (-(CM_SCALE_UP+1)/2)
/* forward declarations */
static
Py_complex
c
_asinh
(
Py_complex
);
static
Py_complex
c
_atanh
(
Py_complex
);
static
Py_complex
c
_cosh
(
Py_complex
);
static
Py_complex
c
_sinh
(
Py_complex
);
static
Py_complex
c
_sqrt
(
Py_complex
);
static
Py_complex
c
_tanh
(
Py_complex
);
static
Py_complex
c
math_asinh_impl
(
PyModuleDef
*
,
Py_complex
);
static
Py_complex
c
math_atanh_impl
(
PyModuleDef
*
,
Py_complex
);
static
Py_complex
c
math_cosh_impl
(
PyModuleDef
*
,
Py_complex
);
static
Py_complex
c
math_sinh_impl
(
PyModuleDef
*
,
Py_complex
);
static
Py_complex
c
math_sqrt_impl
(
PyModuleDef
*
,
Py_complex
);
static
Py_complex
c
math_tanh_impl
(
PyModuleDef
*
,
Py_complex
);
static
PyObject
*
math_error
(
void
);
/* Code to deal with special values (infinities, NaNs, etc.). */
...
...
@@ -123,8 +158,18 @@ special_type(double d)
static
Py_complex
acos_special_values
[
7
][
7
];
/*[clinic input]
cmath.acos -> Py_complex_protected
z: Py_complex_protected
/
Return the arc cosine of z.
[clinic start generated code]*/
static
Py_complex
c_acos
(
Py_complex
z
)
cmath_acos_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=7c1dd21ff818db6b input=bd6cbd78ae851927]*/
{
Py_complex
s1
,
s2
,
r
;
...
...
@@ -145,10 +190,10 @@ c_acos(Py_complex z)
}
else
{
s1
.
real
=
1
.
-
z
.
real
;
s1
.
imag
=
-
z
.
imag
;
s1
=
c
_sqrt
(
s1
);
s1
=
c
math_sqrt_impl
(
module
,
s1
);
s2
.
real
=
1
.
+
z
.
real
;
s2
.
imag
=
z
.
imag
;
s2
=
c
_sqrt
(
s2
);
s2
=
c
math_sqrt_impl
(
module
,
s2
);
r
.
real
=
2
.
*
atan2
(
s1
.
real
,
s2
.
real
);
r
.
imag
=
m_asinh
(
s2
.
real
*
s1
.
imag
-
s2
.
imag
*
s1
.
real
);
}
...
...
@@ -156,16 +201,18 @@ c_acos(Py_complex z)
return
r
;
}
PyDoc_STRVAR
(
c_acos_doc
,
"acos(x)
\n
"
"
\n
"
"Return the arc cosine of x."
);
static
Py_complex
acosh_special_values
[
7
][
7
];
/*[clinic input]
cmath.acosh = cmath.acos
Return the hyperbolic arccosine of z.
[clinic start generated code]*/
static
Py_complex
c_acosh
(
Py_complex
z
)
cmath_acosh_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=c23c776429def981 input=bc016412080bb3e9]*/
{
Py_complex
s1
,
s2
,
r
;
...
...
@@ -178,10 +225,10 @@ c_acosh(Py_complex z)
}
else
{
s1
.
real
=
z
.
real
-
1
.;
s1
.
imag
=
z
.
imag
;
s1
=
c
_sqrt
(
s1
);
s1
=
c
math_sqrt_impl
(
module
,
s1
);
s2
.
real
=
z
.
real
+
1
.;
s2
.
imag
=
z
.
imag
;
s2
=
c
_sqrt
(
s2
);
s2
=
c
math_sqrt_impl
(
module
,
s2
);
r
.
real
=
m_asinh
(
s1
.
real
*
s2
.
real
+
s1
.
imag
*
s2
.
imag
);
r
.
imag
=
2
.
*
atan2
(
s1
.
imag
,
s2
.
real
);
}
...
...
@@ -189,35 +236,38 @@ c_acosh(Py_complex z)
return
r
;
}
PyDoc_STRVAR
(
c_acosh_doc
,
"acosh(x)
\n
"
"
\n
"
"Return the hyperbolic arccosine of x."
);
/*[clinic input]
cmath.asin = cmath.acos
Return the arc sine of z.
[clinic start generated code]*/
static
Py_complex
c_asin
(
Py_complex
z
)
cmath_asin_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=42d2346d46690826 input=be0bf0cfdd5239c5]*/
{
/* asin(z) = -i asinh(iz) */
Py_complex
s
,
r
;
s
.
real
=
-
z
.
imag
;
s
.
imag
=
z
.
real
;
s
=
c
_asinh
(
s
);
s
=
c
math_asinh_impl
(
module
,
s
);
r
.
real
=
s
.
imag
;
r
.
imag
=
-
s
.
real
;
return
r
;
}
PyDoc_STRVAR
(
c_asin_doc
,
"asin(x)
\n
"
"
\n
"
"Return the arc sine of x."
);
static
Py_complex
asinh_special_values
[
7
][
7
];
/*[clinic input]
cmath.asinh = cmath.acos
Return the hyperbolic arc sine of z.
[clinic start generated code]*/
static
Py_complex
c_asinh
(
Py_complex
z
)
cmath_asinh_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=0c6664823c7b1b35 input=5a21fa0242928c9b]*/
{
Py_complex
s1
,
s2
,
r
;
...
...
@@ -235,10 +285,10 @@ c_asinh(Py_complex z)
}
else
{
s1
.
real
=
1
.
+
z
.
imag
;
s1
.
imag
=
-
z
.
real
;
s1
=
c
_sqrt
(
s1
);
s1
=
c
math_sqrt_impl
(
module
,
s1
);
s2
.
real
=
1
.
-
z
.
imag
;
s2
.
imag
=
z
.
real
;
s2
=
c
_sqrt
(
s2
);
s2
=
c
math_sqrt_impl
(
module
,
s2
);
r
.
real
=
m_asinh
(
s1
.
real
*
s2
.
imag
-
s2
.
real
*
s1
.
imag
);
r
.
imag
=
atan2
(
z
.
imag
,
s1
.
real
*
s2
.
real
-
s1
.
imag
*
s2
.
imag
);
}
...
...
@@ -246,20 +296,22 @@ c_asinh(Py_complex z)
return
r
;
}
PyDoc_STRVAR
(
c_asinh_doc
,
"asinh(x)
\n
"
"
\n
"
"Return the hyperbolic arc sine of x."
);
/*[clinic input]
cmath.atan = cmath.acos
Return the arc tangent of z.
[clinic start generated code]*/
static
Py_complex
c_atan
(
Py_complex
z
)
cmath_atan_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=b7d44f02c6a5c3b5 input=3b21ff7d5eac632a]*/
{
/* atan(z) = -i atanh(iz) */
Py_complex
s
,
r
;
s
.
real
=
-
z
.
imag
;
s
.
imag
=
z
.
real
;
s
=
c
_atanh
(
s
);
s
=
c
math_atanh_impl
(
module
,
s
);
r
.
real
=
s
.
imag
;
r
.
imag
=
-
s
.
real
;
return
r
;
...
...
@@ -295,16 +347,18 @@ c_atan2(Py_complex z)
return
atan2
(
z
.
imag
,
z
.
real
);
}
PyDoc_STRVAR
(
c_atan_doc
,
"atan(x)
\n
"
"
\n
"
"Return the arc tangent of x."
);
static
Py_complex
atanh_special_values
[
7
][
7
];
/*[clinic input]
cmath.atanh = cmath.acos
Return the hyperbolic arc tangent of z.
[clinic start generated code]*/
static
Py_complex
c_atanh
(
Py_complex
z
)
cmath_atanh_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=279e0b9fefc8da7c input=df19cdc9f9d431c9]*/
{
Py_complex
r
;
double
ay
,
h
;
...
...
@@ -313,7 +367,7 @@ c_atanh(Py_complex z)
/* Reduce to case where z.real >= 0., using atanh(z) = -atanh(-z). */
if
(
z
.
real
<
0
.)
{
return
_Py_c_neg
(
c
_atanh
(
_Py_c_neg
(
z
)));
return
_Py_c_neg
(
c
math_atanh_impl
(
module
,
_Py_c_neg
(
z
)));
}
ay
=
fabs
(
z
.
imag
);
...
...
@@ -350,34 +404,38 @@ c_atanh(Py_complex z)
return
r
;
}
PyDoc_STRVAR
(
c_atanh_doc
,
"atanh(x)
\n
"
"
\n
"
"Return the hyperbolic arc tangent of x."
);
/*[clinic input]
cmath.cos = cmath.acos
Return the cosine of z.
[clinic start generated code]*/
static
Py_complex
c_cos
(
Py_complex
z
)
cmath_cos_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=9d1cdc1b5e761667 input=6022e39b77127ac7]*/
{
/* cos(z) = cosh(iz) */
Py_complex
r
;
r
.
real
=
-
z
.
imag
;
r
.
imag
=
z
.
real
;
r
=
c
_cosh
(
r
);
r
=
c
math_cosh_impl
(
module
,
r
);
return
r
;
}
PyDoc_STRVAR
(
c_cos_doc
,
"cos(x)
\n
"
"
\n
"
"Return the cosine of x."
);
/* cosh(infinity + i*y) needs to be dealt with specially */
static
Py_complex
cosh_special_values
[
7
][
7
];
/*[clinic input]
cmath.cosh = cmath.acos
Return the hyperbolic cosine of z.
[clinic start generated code]*/
static
Py_complex
c_cosh
(
Py_complex
z
)
cmath_cosh_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=f3b5d3282b3024d3 input=d6b66339e9cc332b]*/
{
Py_complex
r
;
double
x_minus_one
;
...
...
@@ -426,18 +484,20 @@ c_cosh(Py_complex z)
return
r
;
}
PyDoc_STRVAR
(
c_cosh_doc
,
"cosh(x)
\n
"
"
\n
"
"Return the hyperbolic cosine of x."
);
/* exp(infinity + i*y) and exp(-infinity + i*y) need special treatment for
finite y */
static
Py_complex
exp_special_values
[
7
][
7
];
/*[clinic input]
cmath.exp = cmath.acos
Return the exponential value e**z.
[clinic start generated code]*/
static
Py_complex
c_exp
(
Py_complex
z
)
cmath_exp_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=6f8825eb2bcad9ba input=8b9e6cf8a92174c3]*/
{
Py_complex
r
;
double
l
;
...
...
@@ -486,12 +546,6 @@ c_exp(Py_complex z)
return
r
;
}
PyDoc_STRVAR
(
c_exp_doc
,
"exp(x)
\n
"
"
\n
"
"Return the exponential value e**x."
);
static
Py_complex
log_special_values
[
7
][
7
];
static
Py_complex
...
...
@@ -564,8 +618,15 @@ c_log(Py_complex z)
}
/*[clinic input]
cmath.log10 = cmath.acos
Return the base-10 logarithm of z.
[clinic start generated code]*/
static
Py_complex
c_log10
(
Py_complex
z
)
cmath_log10_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=c7c426ca0e782341 input=cff5644f73c1519c]*/
{
Py_complex
r
;
int
errno_save
;
...
...
@@ -578,36 +639,40 @@ c_log10(Py_complex z)
return
r
;
}
PyDoc_STRVAR
(
c_log10_doc
,
"log10(x)
\n
"
"
\n
"
"Return the base-10 logarithm of x."
);
/*[clinic input]
cmath.sin = cmath.acos
Return the sine of z.
[clinic start generated code]*/
static
Py_complex
c_sin
(
Py_complex
z
)
cmath_sin_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=e7f5e2b253825ac7 input=2d3519842a8b4b85]*/
{
/* sin(z) = -i sin(iz) */
Py_complex
s
,
r
;
s
.
real
=
-
z
.
imag
;
s
.
imag
=
z
.
real
;
s
=
c
_sinh
(
s
);
s
=
c
math_sinh_impl
(
module
,
s
);
r
.
real
=
s
.
imag
;
r
.
imag
=
-
s
.
real
;
return
r
;
}
PyDoc_STRVAR
(
c_sin_doc
,
"sin(x)
\n
"
"
\n
"
"Return the sine of x."
);
/* sinh(infinity + i*y) needs to be dealt with specially */
static
Py_complex
sinh_special_values
[
7
][
7
];
/*[clinic input]
cmath.sinh = cmath.acos
Return the hyperbolic sine of z.
[clinic start generated code]*/
static
Py_complex
c_sinh
(
Py_complex
z
)
cmath_sinh_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=d71fff8298043a95 input=d2d3fc8c1ddfd2dd]*/
{
Py_complex
r
;
double
x_minus_one
;
...
...
@@ -655,16 +720,18 @@ c_sinh(Py_complex z)
return
r
;
}
PyDoc_STRVAR
(
c_sinh_doc
,
"sinh(x)
\n
"
"
\n
"
"Return the hyperbolic sine of x."
);
static
Py_complex
sqrt_special_values
[
7
][
7
];
/*[clinic input]
cmath.sqrt = cmath.acos
Return the square root of z.
[clinic start generated code]*/
static
Py_complex
c_sqrt
(
Py_complex
z
)
cmath_sqrt_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=b6bda283d0c5a7b4 input=7088b166fc9a58c7]*/
{
/*
Method: use symmetries to reduce to the case when x = z.real and y
...
...
@@ -730,36 +797,40 @@ c_sqrt(Py_complex z)
return
r
;
}
PyDoc_STRVAR
(
c_sqrt_doc
,
"sqrt(x)
\n
"
"
\n
"
"Return the square root of x."
);
/*[clinic input]
cmath.tan = cmath.acos
Return the tangent of z.
[clinic start generated code]*/
static
Py_complex
c_tan
(
Py_complex
z
)
cmath_tan_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=df374bacf36d99b4 input=fc167e528767888e]*/
{
/* tan(z) = -i tanh(iz) */
Py_complex
s
,
r
;
s
.
real
=
-
z
.
imag
;
s
.
imag
=
z
.
real
;
s
=
c
_tanh
(
s
);
s
=
c
math_tanh_impl
(
module
,
s
);
r
.
real
=
s
.
imag
;
r
.
imag
=
-
s
.
real
;
return
r
;
}
PyDoc_STRVAR
(
c_tan_doc
,
"tan(x)
\n
"
"
\n
"
"Return the tangent of x."
);
/* tanh(infinity + i*y) needs to be dealt with specially */
static
Py_complex
tanh_special_values
[
7
][
7
];
/*[clinic input]
cmath.tanh = cmath.acos
Return the hyperbolic tangent of z.
[clinic start generated code]*/
static
Py_complex
c_tanh
(
Py_complex
z
)
cmath_tanh_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=f578773d27a18e96 input=22f67f9dc6d29685]*/
{
/* Formula:
...
...
@@ -822,25 +893,33 @@ c_tanh(Py_complex z)
return
r
;
}
PyDoc_STRVAR
(
c_tanh_doc
,
"tanh(x)
\n
"
"
\n
"
"Return the hyperbolic tangent of x."
);
/*[clinic input]
cmath.log
x: Py_complex
y_obj: object = NULL
/
The logarithm of z to the given base.
If the base not specified, returns the natural logarithm (base e) of z.
[clinic start generated code]*/
static
PyObject
*
cmath_log
(
PyObject
*
self
,
PyObject
*
args
)
cmath_log_impl
(
PyModuleDef
*
module
,
Py_complex
x
,
PyObject
*
y_obj
)
/*[clinic end generated code: output=35e2a1e5229b5a46 input=ee0e823a7c6e68ea]*/
{
Py_complex
x
;
Py_complex
y
;
if
(
!
PyArg_ParseTuple
(
args
,
"D|D"
,
&
x
,
&
y
))
return
NULL
;
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
return
0
)
x
=
c_log
(
x
);
if
(
PyTuple_GET_SIZE
(
args
)
==
2
)
{
if
(
y_obj
!=
NULL
)
{
y
=
PyComplex_AsCComplex
(
y_obj
);
if
(
PyErr_Occurred
())
{
return
NULL
;
}
y
=
c_log
(
y
);
x
=
_Py_c_quot
(
x
,
y
);
}
...
...
@@ -850,10 +929,6 @@ cmath_log(PyObject *self, PyObject *args)
return
PyComplex_FromCComplex
(
x
);
}
PyDoc_STRVAR
(
cmath_log_doc
,
"log(x[, base]) -> the logarithm of x to the given base.
\n
\
If the base not specified, returns the natural logarithm (base e) of x."
);
/* And now the glue to make them available from Python: */
...
...
@@ -869,57 +944,22 @@ math_error(void)
return
NULL
;
}
static
PyObject
*
math_1
(
PyObject
*
args
,
Py_complex
(
*
func
)(
Py_complex
))
{
Py_complex
x
,
r
;
if
(
!
PyArg_ParseTuple
(
args
,
"D"
,
&
x
))
return
NULL
;
errno
=
0
;
PyFPE_START_PROTECT
(
"complex function"
,
return
0
);
r
=
(
*
func
)(
x
);
PyFPE_END_PROTECT
(
r
);
if
(
errno
==
EDOM
)
{
PyErr_SetString
(
PyExc_ValueError
,
"math domain error"
);
return
NULL
;
}
else
if
(
errno
==
ERANGE
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"math range error"
);
return
NULL
;
}
else
{
return
PyComplex_FromCComplex
(
r
);
}
}
#define FUNC1(stubname, func) \
static PyObject * stubname(PyObject *self, PyObject *args) { \
return math_1(args, func); \
}
/*[clinic input]
cmath.phase
FUNC1
(
cmath_acos
,
c_acos
)
FUNC1
(
cmath_acosh
,
c_acosh
)
FUNC1
(
cmath_asin
,
c_asin
)
FUNC1
(
cmath_asinh
,
c_asinh
)
FUNC1
(
cmath_atan
,
c_atan
)
FUNC1
(
cmath_atanh
,
c_atanh
)
FUNC1
(
cmath_cos
,
c_cos
)
FUNC1
(
cmath_cosh
,
c_cosh
)
FUNC1
(
cmath_exp
,
c_exp
)
FUNC1
(
cmath_log10
,
c_log10
)
FUNC1
(
cmath_sin
,
c_sin
)
FUNC1
(
cmath_sinh
,
c_sinh
)
FUNC1
(
cmath_sqrt
,
c_sqrt
)
FUNC1
(
cmath_tan
,
c_tan
)
FUNC1
(
cmath_tanh
,
c_tanh
)
z: Py_complex
/
Return argument, also known as the phase angle, of a complex.
[clinic start generated code]*/
static
PyObject
*
cmath_phase
(
PyObject
*
self
,
PyObject
*
args
)
cmath_phase_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=e09eaf373cb624c3 input=5cf75228ba94b69d]*/
{
Py_complex
z
;
double
phi
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:phase"
,
&
z
))
return
NULL
;
errno
=
0
;
PyFPE_START_PROTECT
(
"arg function"
,
return
0
)
phi
=
c_atan2
(
z
);
...
...
@@ -930,17 +970,23 @@ cmath_phase(PyObject *self, PyObject *args)
return
PyFloat_FromDouble
(
phi
);
}
PyDoc_STRVAR
(
cmath_phase_doc
,
"phase(z) -> float
\n\n
\
Return argument, also known as the phase angle, of a complex."
);
/*[clinic input]
cmath.polar
z: Py_complex
/
Convert a complex from rectangular coordinates to polar coordinates.
r is the distance from 0 and phi the phase angle.
[clinic start generated code]*/
static
PyObject
*
cmath_polar
(
PyObject
*
self
,
PyObject
*
args
)
cmath_polar_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=07d41b16c877875a input=26c353574fd1a861]*/
{
Py_complex
z
;
double
r
,
phi
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:polar"
,
&
z
))
return
NULL
;
PyFPE_START_PROTECT
(
"polar function"
,
return
0
)
phi
=
c_atan2
(
z
);
/* should not cause any exception */
r
=
_Py_c_abs
(
z
);
/* sets errno to ERANGE on overflow; otherwise 0 */
...
...
@@ -951,11 +997,6 @@ cmath_polar(PyObject *self, PyObject *args)
return
Py_BuildValue
(
"dd"
,
r
,
phi
);
}
PyDoc_STRVAR
(
cmath_polar_doc
,
"polar(z) -> r: float, phi: float
\n\n
\
Convert a complex from rectangular coordinates to polar coordinates. r is
\n
\
the distance from 0 and phi the phase angle."
);
/*
rect() isn't covered by the C99 standard, but it's not too hard to
figure out 'spirit of C99' rules for special value handing:
...
...
@@ -969,13 +1010,21 @@ the distance from 0 and phi the phase angle.");
static
Py_complex
rect_special_values
[
7
][
7
];
/*[clinic input]
cmath.rect
r: double
phi: double
/
Convert from polar coordinates to rectangular coordinates.
[clinic start generated code]*/
static
PyObject
*
cmath_rect
(
PyObject
*
self
,
PyObject
*
args
)
cmath_rect_impl
(
PyModuleDef
*
module
,
double
r
,
double
phi
)
/*[clinic end generated code: output=d97a8749bd63e9d5 input=24c5646d147efd69]*/
{
Py_complex
z
;
double
r
,
phi
;
if
(
!
PyArg_ParseTuple
(
args
,
"dd:rect"
,
&
r
,
&
phi
))
return
NULL
;
errno
=
0
;
PyFPE_START_PROTECT
(
"rect function"
,
return
0
)
...
...
@@ -1026,78 +1075,74 @@ cmath_rect(PyObject *self, PyObject *args)
return
PyComplex_FromCComplex
(
z
);
}
PyDoc_STRVAR
(
cmath_rect_doc
,
"rect(r, phi) -> z: complex
\n\n
\
Convert from polar coordinates to rectangular coordinates."
);
/*[clinic input]
cmath.isfinite = cmath.polar
Return True if both the real and imaginary parts of z are finite, else False.
[clinic start generated code]*/
static
PyObject
*
cmath_isfinite
(
PyObject
*
self
,
PyObject
*
args
)
cmath_isfinite_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=8f6682fa93de45d6 input=848e7ee701895815]*/
{
Py_complex
z
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:isfinite"
,
&
z
))
return
NULL
;
return
PyBool_FromLong
(
Py_IS_FINITE
(
z
.
real
)
&&
Py_IS_FINITE
(
z
.
imag
));
}
PyDoc_STRVAR
(
cmath_isfinite_doc
,
"isfinite(z) -> bool
\n
\
Return True if both the real and imaginary parts of z are finite, else False."
);
/*[clinic input]
cmath.isnan = cmath.polar
Checks if the real or imaginary part of z not a number (NaN).
[clinic start generated code]*/
static
PyObject
*
cmath_isnan
(
PyObject
*
self
,
PyObject
*
args
)
cmath_isnan_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=b85fe8c2047718ee input=71799f5d284c9baf]*/
{
Py_complex
z
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:isnan"
,
&
z
))
return
NULL
;
return
PyBool_FromLong
(
Py_IS_NAN
(
z
.
real
)
||
Py_IS_NAN
(
z
.
imag
));
}
PyDoc_STRVAR
(
cmath_isnan_doc
,
"isnan(z) -> bool
\n
\
Checks if the real or imaginary part of z not a number (NaN)"
);
/*[clinic input]
cmath.isinf = cmath.polar
Checks if the real or imaginary part of z is infinite.
[clinic start generated code]*/
static
PyObject
*
cmath_isinf
(
PyObject
*
self
,
PyObject
*
args
)
cmath_isinf_impl
(
PyModuleDef
*
module
,
Py_complex
z
)
/*[clinic end generated code: output=8ca9c6109e468bf4 input=363df155c7181329]*/
{
Py_complex
z
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:isinf"
,
&
z
))
return
NULL
;
return
PyBool_FromLong
(
Py_IS_INFINITY
(
z
.
real
)
||
Py_IS_INFINITY
(
z
.
imag
));
}
PyDoc_STRVAR
(
cmath_isinf_doc
,
"isinf(z) -> bool
\n
\
Checks if the real or imaginary part of z is infinite."
);
PyDoc_STRVAR
(
module_doc
,
"This module is always available. It provides access to mathematical
\n
"
"functions for complex numbers."
);
static
PyMethodDef
cmath_methods
[]
=
{
{
"acos"
,
cmath_acos
,
METH_VARARGS
,
c_acos_doc
},
{
"acosh"
,
cmath_acosh
,
METH_VARARGS
,
c_acosh_doc
},
{
"asin"
,
cmath_asin
,
METH_VARARGS
,
c_asin_doc
},
{
"asinh"
,
cmath_asinh
,
METH_VARARGS
,
c_asinh_doc
},
{
"atan"
,
cmath_atan
,
METH_VARARGS
,
c_atan_doc
},
{
"atanh"
,
cmath_atanh
,
METH_VARARGS
,
c_atanh_doc
},
{
"cos"
,
cmath_cos
,
METH_VARARGS
,
c_cos_doc
},
{
"cosh"
,
cmath_cosh
,
METH_VARARGS
,
c_cosh_doc
},
{
"exp"
,
cmath_exp
,
METH_VARARGS
,
c_exp_doc
},
{
"isfinite"
,
cmath_isfinite
,
METH_VARARGS
,
cmath_isfinite_doc
},
{
"isinf"
,
cmath_isinf
,
METH_VARARGS
,
cmath_isinf_doc
},
{
"isnan"
,
cmath_isnan
,
METH_VARARGS
,
cmath_isnan_doc
},
{
"log"
,
cmath_log
,
METH_VARARGS
,
cmath_log_doc
},
{
"log10"
,
cmath_log10
,
METH_VARARGS
,
c_log10_doc
},
{
"phase"
,
cmath_phase
,
METH_VARARGS
,
cmath_phase_doc
},
{
"polar"
,
cmath_polar
,
METH_VARARGS
,
cmath_polar_doc
},
{
"rect"
,
cmath_rect
,
METH_VARARGS
,
cmath_rect_doc
},
{
"sin"
,
cmath_sin
,
METH_VARARGS
,
c_sin_doc
},
{
"sinh"
,
cmath_sinh
,
METH_VARARGS
,
c_sinh_doc
},
{
"sqrt"
,
cmath_sqrt
,
METH_VARARGS
,
c_sqrt_doc
},
{
"tan"
,
cmath_tan
,
METH_VARARGS
,
c_tan_doc
},
{
"tanh"
,
cmath_tanh
,
METH_VARARGS
,
c_tanh_doc
},
CMATH_ACOS_METHODDEF
CMATH_ACOSH_METHODDEF
CMATH_ASIN_METHODDEF
CMATH_ASINH_METHODDEF
CMATH_ATAN_METHODDEF
CMATH_ATANH_METHODDEF
CMATH_COS_METHODDEF
CMATH_COSH_METHODDEF
CMATH_EXP_METHODDEF
CMATH_ISFINITE_METHODDEF
CMATH_ISINF_METHODDEF
CMATH_ISNAN_METHODDEF
CMATH_LOG_METHODDEF
CMATH_LOG10_METHODDEF
CMATH_PHASE_METHODDEF
CMATH_POLAR_METHODDEF
CMATH_RECT_METHODDEF
CMATH_SIN_METHODDEF
CMATH_SINH_METHODDEF
CMATH_SQRT_METHODDEF
CMATH_TAN_METHODDEF
CMATH_TANH_METHODDEF
{
NULL
,
NULL
}
/* sentinel */
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment