File: complex.c

package info (click to toggle)
python3.14 3.14.0~rc1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 126,824 kB
  • sloc: python: 745,274; ansic: 713,752; xml: 31,250; sh: 5,822; cpp: 4,063; makefile: 1,988; objc: 787; lisp: 502; javascript: 136; asm: 75; csh: 12
file content (66 lines) | stat: -rw-r--r-- 2,608 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "parts.h"
#include "../_testcapi/util.h"

#define Py_BUILD_CORE
#include "pycore_complexobject.h"


#define _PY_CR_FUNC2(suffix)                                     \
    static PyObject *                                            \
    _py_cr_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
    {                                                            \
        Py_complex a, res;                                       \
        double b;                                                \
                                                                 \
        if (!PyArg_ParseTuple(args, "Dd", &a, &b)) {             \
            return NULL;                                         \
        }                                                        \
                                                                 \
        errno = 0;                                               \
        res = _Py_cr_##suffix(a, b);                             \
        return Py_BuildValue("Di", &res, errno);                 \
    };

#define _PY_RC_FUNC2(suffix)                                     \
    static PyObject *                                            \
    _py_rc_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
    {                                                            \
        Py_complex b, res;                                       \
        double a;                                                \
                                                                 \
        if (!PyArg_ParseTuple(args, "dD", &a, &b)) {             \
            return NULL;                                         \
        }                                                        \
                                                                 \
        errno = 0;                                               \
        res = _Py_rc_##suffix(a, b);                             \
        return Py_BuildValue("Di", &res, errno);                 \
    };

_PY_CR_FUNC2(sum)
_PY_CR_FUNC2(diff)
_PY_RC_FUNC2(diff)
_PY_CR_FUNC2(prod)
_PY_CR_FUNC2(quot)
_PY_RC_FUNC2(quot)


static PyMethodDef test_methods[] = {
    {"_py_cr_sum", _py_cr_sum, METH_VARARGS},
    {"_py_cr_diff", _py_cr_diff, METH_VARARGS},
    {"_py_rc_diff", _py_rc_diff, METH_VARARGS},
    {"_py_cr_prod", _py_cr_prod, METH_VARARGS},
    {"_py_cr_quot", _py_cr_quot, METH_VARARGS},
    {"_py_rc_quot", _py_rc_quot, METH_VARARGS},
    {NULL},
};

int
_PyTestInternalCapi_Init_Complex(PyObject *mod)
{
    if (PyModule_AddFunctions(mod, test_methods) < 0) {
        return -1;
    }

    return 0;
}