本文整理汇总了C++中PyComplex_FromCComplex函数的典型用法代码示例。如果您正苦于以下问题:C++ PyComplex_FromCComplex函数的具体用法?C++ PyComplex_FromCComplex怎么用?C++ PyComplex_FromCComplex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyComplex_FromCComplex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: complex_sub
static PyObject *
complex_sub(PyComplexObject *v, PyComplexObject *w)
{
Py_complex result;
PyFPE_START_PROTECT("complex_sub", return 0)
result = c_diff(v->cval,w->cval);
PyFPE_END_PROTECT(result)
return PyComplex_FromCComplex(result);
}
示例2: complex_pos
static PyObject *
complex_pos(PyComplexObject *v)
{
if (PyComplex_CheckExact(v)) {
Py_INCREF(v);
return (PyObject *)v;
}
else
return PyComplex_FromCComplex(v->cval);
}
示例3: complex_conjugate
static PyObject *
complex_conjugate(PyObject *self, PyObject *args)
{
Py_complex c;
if (!PyArg_ParseTuple(args, ":conjugate"))
return NULL;
c = ((PyComplexObject *)self)->cval;
c.imag = -c.imag;
return PyComplex_FromCComplex(c);
}
示例4: complex_mul
static PyObject *
complex_mul(PyObject *v, PyObject *w)
{
Py_complex result;
Py_complex a, b;
TO_COMPLEX(v, a);
TO_COMPLEX(w, b);
PyFPE_START_PROTECT("complex_mul", return 0)
result = _Py_c_prod(a, b);
PyFPE_END_PROTECT(result)
return PyComplex_FromCComplex(result);
}
示例5: complex_divmod
static PyObject *
complex_divmod(PyComplexObject *v, PyComplexObject *w)
{
Py_complex div, mod;
PyObject *d, *m, *z;
errno = 0;
div = c_quot(v->cval,w->cval); /* The raw divisor value. */
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError, "complex divmod()");
return NULL;
}
div.real = floor(div.real); /* Use the floor of the real part. */
div.imag = 0.0;
mod = c_diff(v->cval, c_prod(w->cval, div));
d = PyComplex_FromCComplex(div);
m = PyComplex_FromCComplex(mod);
z = Py_BuildValue("(OO)", d, m);
Py_XDECREF(d);
Py_XDECREF(m);
return z;
}
示例6: complex_sub
static PyObject *
complex_sub(PyObject *v, PyObject *w)
{
Py_complex result;
Py_complex a, b;
TO_COMPLEX(v, a);
TO_COMPLEX(w, b);;
PyFPE_START_PROTECT("complex_sub", return 0)
result = c_diff(a, b);
PyFPE_END_PROTECT(result)
return PyComplex_FromCComplex(result);
}
示例7: complex_div
static PyObject *
complex_div(PyComplexObject *v, PyComplexObject *w)
{
Py_complex quot;
PyFPE_START_PROTECT("complex_div", return 0)
errno = 0;
quot = c_quot(v->cval,w->cval);
PyFPE_END_PROTECT(quot)
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError, "complex division");
return NULL;
}
return PyComplex_FromCComplex(quot);
}
示例8: math_1
static PyObject *
math_1(PyObject *args, Py_complex (*func)(Py_complex))
{
Py_complex x;
if (!PyArg_ParseTuple(args, "D", &x))
return NULL;
errno = 0;
PyFPE_START_PROTECT("complex function", return 0)
x = (*func)(x);
PyFPE_END_PROTECT(x)
Py_ADJUST_ERANGE2(x.real, x.imag);
if (errno != 0)
return math_error();
else
return PyComplex_FromCComplex(x);
}
示例9: complex_remainder
static PyObject *
complex_remainder(PyComplexObject *v, PyComplexObject *w)
{
Py_complex div, mod;
errno = 0;
div = c_quot(v->cval,w->cval); /* The raw divisor value. */
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError, "complex remainder");
return NULL;
}
div.real = floor(div.real); /* Use the floor of the real part. */
div.imag = 0.0;
mod = c_diff(v->cval, c_prod(w->cval, div));
return PyComplex_FromCComplex(mod);
}
示例10: complex_div
static PyObject *
complex_div(PyObject *v, PyObject *w)
{
Py_complex quot;
Py_complex a, b;
TO_COMPLEX(v, a);
TO_COMPLEX(w, b);
PyFPE_START_PROTECT("complex_div", return 0)
errno = 0;
quot = _Py_c_quot(a, b);
PyFPE_END_PROTECT(quot)
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError, "complex division by zero");
return NULL;
}
return PyComplex_FromCComplex(quot);
}
示例11: complex_classic_div
static PyObject *
complex_classic_div(PyComplexObject *v, PyComplexObject *w)
{
Py_complex quot;
if (Py_DivisionWarningFlag >= 2 &&
PyErr_Warn(PyExc_DeprecationWarning,
"classic complex division") < 0)
return NULL;
PyFPE_START_PROTECT("complex_classic_div", return 0)
errno = 0;
quot = c_quot(v->cval,w->cval);
PyFPE_END_PROTECT(quot)
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError, "complex division");
return NULL;
}
return PyComplex_FromCComplex(quot);
}
示例12: cmath_log
static PyObject *
cmath_log(PyObject *self, PyObject *args)
{
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)
x = c_quot(x, c_log(y));
PyFPE_END_PROTECT(x)
if (errno != 0)
return math_error();
Py_ADJUST_ERANGE2(x.real, x.imag);
return PyComplex_FromCComplex(x);
}
示例13: complex_remainder
static PyObject *
complex_remainder(PyObject *v, PyObject *w)
{
Py_complex div, mod;
Py_complex a, b;
TO_COMPLEX(v, a);
TO_COMPLEX(w, b);
if (PyErr_Warn(PyExc_DeprecationWarning,
"complex divmod(), // and % are deprecated") < 0)
return NULL;
errno = 0;
div = c_quot(a, b); /* The raw divisor value. */
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError, "complex remainder");
return NULL;
}
div.real = floor(div.real); /* Use the floor of the real part. */
div.imag = 0.0;
mod = c_diff(a, c_prod(b, div));
return PyComplex_FromCComplex(mod);
}
示例14: complex_pow
static PyObject *
complex_pow(PyObject *v, PyObject *w, PyObject *z)
{
Py_complex p;
Py_complex exponent;
long int_exponent;
Py_complex a, b;
TO_COMPLEX(v, a);
TO_COMPLEX(w, b);
if (z!=Py_None) {
PyErr_SetString(PyExc_ValueError, "complex modulo");
return NULL;
}
PyFPE_START_PROTECT("complex_pow", return 0)
errno = 0;
exponent = b;
int_exponent = (long)exponent.real;
if (exponent.imag == 0. && exponent.real == int_exponent)
p = c_powi(a,int_exponent);
else
p = c_pow(a,exponent);
PyFPE_END_PROTECT(p)
Py_ADJUST_ERANGE2(p.real, p.imag);
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError,
"0.0 to a negative or complex power");
return NULL;
}
else if (errno == ERANGE) {
PyErr_SetString(PyExc_OverflowError,
"complex exponentiation");
return NULL;
}
return PyComplex_FromCComplex(p);
}
示例15: complex_to_python
PyObject* complex_to_python(const std::complex<T>& sc) {
Py_complex pcc;
pcc.real = sc.real();
pcc.imag = sc.imag();
return PyComplex_FromCComplex(pcc);
}