mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
"Generally, mixed-mode arithmetic combining real and complex variables should be performed directly, not by first coercing the real to complex, lest the sign of zero be rendered uninformative; the same goes for combinations of pure imaginary quantities with complex variables." (c) Kahan, W: Branch cuts for complex elementary functions. This patch implements mixed-mode arithmetic rules, combining real and complex variables as specified by C standards since C99 (in particular, there is no special version for the true division with real lhs operand). Most C compilers implementing C99+ Annex G have only these special rules (without support for imaginary type, which is going to be deprecated in C2y).
39 lines
1.2 KiB
C
39 lines
1.2 KiB
C
#ifndef Py_CPYTHON_COMPLEXOBJECT_H
|
|
# error "this header file must not be included directly"
|
|
#endif
|
|
|
|
typedef struct {
|
|
double real;
|
|
double imag;
|
|
} Py_complex;
|
|
|
|
// Operations on complex numbers.
|
|
PyAPI_FUNC(Py_complex) _Py_c_sum(Py_complex, Py_complex);
|
|
PyAPI_FUNC(Py_complex) _Py_cr_sum(Py_complex, double);
|
|
PyAPI_FUNC(Py_complex) _Py_c_diff(Py_complex, Py_complex);
|
|
PyAPI_FUNC(Py_complex) _Py_cr_diff(Py_complex, double);
|
|
PyAPI_FUNC(Py_complex) _Py_rc_diff(double, Py_complex);
|
|
PyAPI_FUNC(Py_complex) _Py_c_neg(Py_complex);
|
|
PyAPI_FUNC(Py_complex) _Py_c_prod(Py_complex, Py_complex);
|
|
PyAPI_FUNC(Py_complex) _Py_cr_prod(Py_complex, double);
|
|
PyAPI_FUNC(Py_complex) _Py_c_quot(Py_complex, Py_complex);
|
|
PyAPI_FUNC(Py_complex) _Py_cr_quot(Py_complex, double);
|
|
PyAPI_FUNC(Py_complex) _Py_rc_quot(double, Py_complex);
|
|
PyAPI_FUNC(Py_complex) _Py_c_pow(Py_complex, Py_complex);
|
|
PyAPI_FUNC(double) _Py_c_abs(Py_complex);
|
|
|
|
|
|
/* Complex object interface */
|
|
|
|
/*
|
|
PyComplexObject represents a complex number with double-precision
|
|
real and imaginary parts.
|
|
*/
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
Py_complex cval;
|
|
} PyComplexObject;
|
|
|
|
PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);
|
|
|
|
PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op);
|