| 1 |
#include "parts.h" |
| 2 |
#include "util.h" |
| 3 |
|
| 4 |
|
| 5 |
static PyObject * |
| 6 |
complex_check(PyObject *Py_UNUSED(module), PyObject *obj) |
| 7 |
{ |
| 8 |
NULLABLE(obj); |
| 9 |
return PyLong_FromLong(PyComplex_Check(obj)); |
| 10 |
} |
| 11 |
|
| 12 |
static PyObject * |
| 13 |
complex_checkexact(PyObject *Py_UNUSED(module), PyObject *obj) |
| 14 |
{ |
| 15 |
NULLABLE(obj); |
| 16 |
return PyLong_FromLong(PyComplex_CheckExact(obj)); |
| 17 |
} |
| 18 |
|
| 19 |
static PyObject * |
| 20 |
complex_fromdoubles(PyObject *Py_UNUSED(module), PyObject *args) |
| 21 |
{ |
| 22 |
double real, imag; |
| 23 |
|
| 24 |
if (!PyArg_ParseTuple(args, "dd", &real, &imag)) { |
| 25 |
return NULL; |
| 26 |
} |
| 27 |
|
| 28 |
return PyComplex_FromDoubles(real, imag); |
| 29 |
} |
| 30 |
|
| 31 |
static PyObject * |
| 32 |
complex_realasdouble(PyObject *Py_UNUSED(module), PyObject *obj) |
| 33 |
{ |
| 34 |
double real; |
| 35 |
|
| 36 |
NULLABLE(obj); |
| 37 |
real = PyComplex_RealAsDouble(obj); |
| 38 |
|
| 39 |
if (real == -1. && PyErr_Occurred()) { |
| 40 |
return NULL; |
| 41 |
} |
| 42 |
|
| 43 |
return PyFloat_FromDouble(real); |
| 44 |
} |
| 45 |
|
| 46 |
static PyObject * |
| 47 |
complex_imagasdouble(PyObject *Py_UNUSED(module), PyObject *obj) |
| 48 |
{ |
| 49 |
double imag; |
| 50 |
|
| 51 |
NULLABLE(obj); |
| 52 |
imag = PyComplex_ImagAsDouble(obj); |
| 53 |
|
| 54 |
if (imag == -1. && PyErr_Occurred()) { |
| 55 |
return NULL; |
| 56 |
} |
| 57 |
|
| 58 |
return PyFloat_FromDouble(imag); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
static PyMethodDef test_methods[] = { |
| 63 |
{"complex_check", complex_check, METH_O}, |
| 64 |
{"complex_checkexact", complex_checkexact, METH_O}, |
| 65 |
{"complex_fromdoubles", complex_fromdoubles, METH_VARARGS}, |
| 66 |
{"complex_realasdouble", complex_realasdouble, METH_O}, |
| 67 |
{"complex_imagasdouble", complex_imagasdouble, METH_O}, |
| 68 |
{NULL}, |
| 69 |
}; |
| 70 |
|
| 71 |
int |
| 72 |
_PyTestLimitedCAPI_Init_Complex(PyObject *mod) |
| 73 |
{ |
| 74 |
if (PyModule_AddFunctions(mod, test_methods) < 0) { |
| 75 |
return -1; |
| 76 |
} |
| 77 |
|
| 78 |
return 0; |
| 79 |
} |