blob: cb8c52c580085444313fc6aee36401be638ffd3e [file] [log] [blame]
Fred Drakeea9cb5a2000-07-09 00:20:36 +00001/* Complex number structure */
2
Neal Norwitz638437f2002-10-04 12:43:02 +00003#ifndef Py_COMPLEXOBJECT_H
4#define Py_COMPLEXOBJECT_H
Guido van Rossumf9fca921996-01-12 00:47:05 +00005#ifdef __cplusplus
6extern "C" {
7#endif
8
Martin v. Löwis4d0d4712010-12-03 20:14:31 +00009#ifndef Py_LIMITED_API
Guido van Rossumf9fca921996-01-12 00:47:05 +000010typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000011 double real;
12 double imag;
Guido van Rossum519b4331996-07-21 02:24:22 +000013} Py_complex;
Guido van Rossumf9fca921996-01-12 00:47:05 +000014
15/* Operations on complex numbers from complexmodule.c */
16
Antoine Pitrou1eee8e52014-07-07 18:49:30 -040017PyAPI_FUNC(Py_complex) _Py_c_sum(Py_complex, Py_complex);
18PyAPI_FUNC(Py_complex) _Py_c_diff(Py_complex, Py_complex);
19PyAPI_FUNC(Py_complex) _Py_c_neg(Py_complex);
20PyAPI_FUNC(Py_complex) _Py_c_prod(Py_complex, Py_complex);
21PyAPI_FUNC(Py_complex) _Py_c_quot(Py_complex, Py_complex);
22PyAPI_FUNC(Py_complex) _Py_c_pow(Py_complex, Py_complex);
23PyAPI_FUNC(double) _Py_c_abs(Py_complex);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000024#endif
Guido van Rossumf9fca921996-01-12 00:47:05 +000025
26/* Complex object interface */
27
28/*
29PyComplexObject represents a complex number with double-precision
30real and imaginary parts.
31*/
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000032#ifndef Py_LIMITED_API
Guido van Rossumf9fca921996-01-12 00:47:05 +000033typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000034 PyObject_HEAD
35 Py_complex cval;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000036} PyComplexObject;
37#endif
Guido van Rossumf9fca921996-01-12 00:47:05 +000038
Mark Hammond91a681d2002-08-12 07:21:58 +000039PyAPI_DATA(PyTypeObject) PyComplex_Type;
Guido van Rossumf9fca921996-01-12 00:47:05 +000040
Guido van Rossumc16fcdf2001-08-29 15:45:32 +000041#define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type)
Christian Heimes90aa7642007-12-19 02:45:37 +000042#define PyComplex_CheckExact(op) (Py_TYPE(op) == &PyComplex_Type)
Guido van Rossumf9fca921996-01-12 00:47:05 +000043
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000044#ifndef Py_LIMITED_API
Mark Hammond91a681d2002-08-12 07:21:58 +000045PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000046#endif
Mark Hammond91a681d2002-08-12 07:21:58 +000047PyAPI_FUNC(PyObject *) PyComplex_FromDoubles(double real, double imag);
Guido van Rossumf9fca921996-01-12 00:47:05 +000048
Mark Hammond91a681d2002-08-12 07:21:58 +000049PyAPI_FUNC(double) PyComplex_RealAsDouble(PyObject *op);
50PyAPI_FUNC(double) PyComplex_ImagAsDouble(PyObject *op);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000051#ifndef Py_LIMITED_API
Mark Hammond91a681d2002-08-12 07:21:58 +000052PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000053#endif
Guido van Rossumf9fca921996-01-12 00:47:05 +000054
Eric Smith58a42242009-04-30 01:00:33 +000055/* Format the object based on the format_spec, as defined in PEP 3101
56 (Advanced String Formatting). */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000057#ifndef Py_LIMITED_API
Victor Stinnerd3f08822012-05-29 12:57:52 +020058PyAPI_FUNC(int) _PyComplex_FormatAdvancedWriter(
59 _PyUnicodeWriter *writer,
60 PyObject *obj,
61 PyObject *format_spec,
62 Py_ssize_t start,
63 Py_ssize_t end);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000064#endif
Eric Smith58a42242009-04-30 01:00:33 +000065
Guido van Rossumf9fca921996-01-12 00:47:05 +000066#ifdef __cplusplus
67}
68#endif
Neal Norwitz638437f2002-10-04 12:43:02 +000069#endif /* !Py_COMPLEXOBJECT_H */