blob: 1934f3b3807819de2241fa0dcdcf5bdb6215f364 [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
Guido van Rossum652f1081996-05-24 21:01:36 +000017#define c_sum _Py_c_sum
18#define c_diff _Py_c_diff
19#define c_neg _Py_c_neg
20#define c_prod _Py_c_prod
21#define c_quot _Py_c_quot
22#define c_pow _Py_c_pow
Christian Heimes53876d92008-04-19 00:31:39 +000023#define c_abs _Py_c_abs
Guido van Rossum652f1081996-05-24 21:01:36 +000024
Mark Hammond91a681d2002-08-12 07:21:58 +000025PyAPI_FUNC(Py_complex) c_sum(Py_complex, Py_complex);
26PyAPI_FUNC(Py_complex) c_diff(Py_complex, Py_complex);
27PyAPI_FUNC(Py_complex) c_neg(Py_complex);
28PyAPI_FUNC(Py_complex) c_prod(Py_complex, Py_complex);
29PyAPI_FUNC(Py_complex) c_quot(Py_complex, Py_complex);
30PyAPI_FUNC(Py_complex) c_pow(Py_complex, Py_complex);
Christian Heimes53876d92008-04-19 00:31:39 +000031PyAPI_FUNC(double) c_abs(Py_complex);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000032#endif
Guido van Rossumf9fca921996-01-12 00:47:05 +000033
34/* Complex object interface */
35
36/*
37PyComplexObject represents a complex number with double-precision
38real and imaginary parts.
39*/
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000040#ifndef Py_LIMITED_API
Guido van Rossumf9fca921996-01-12 00:47:05 +000041typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000042 PyObject_HEAD
43 Py_complex cval;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000044} PyComplexObject;
45#endif
Guido van Rossumf9fca921996-01-12 00:47:05 +000046
Mark Hammond91a681d2002-08-12 07:21:58 +000047PyAPI_DATA(PyTypeObject) PyComplex_Type;
Guido van Rossumf9fca921996-01-12 00:47:05 +000048
Guido van Rossumc16fcdf2001-08-29 15:45:32 +000049#define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type)
Christian Heimes90aa7642007-12-19 02:45:37 +000050#define PyComplex_CheckExact(op) (Py_TYPE(op) == &PyComplex_Type)
Guido van Rossumf9fca921996-01-12 00:47:05 +000051
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000052#ifndef Py_LIMITED_API
Mark Hammond91a681d2002-08-12 07:21:58 +000053PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000054#endif
Mark Hammond91a681d2002-08-12 07:21:58 +000055PyAPI_FUNC(PyObject *) PyComplex_FromDoubles(double real, double imag);
Guido van Rossumf9fca921996-01-12 00:47:05 +000056
Mark Hammond91a681d2002-08-12 07:21:58 +000057PyAPI_FUNC(double) PyComplex_RealAsDouble(PyObject *op);
58PyAPI_FUNC(double) PyComplex_ImagAsDouble(PyObject *op);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000059#ifndef Py_LIMITED_API
Mark Hammond91a681d2002-08-12 07:21:58 +000060PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000061#endif
Guido van Rossumf9fca921996-01-12 00:47:05 +000062
Eric Smith58a42242009-04-30 01:00:33 +000063/* Format the object based on the format_spec, as defined in PEP 3101
64 (Advanced String Formatting). */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000065#ifndef Py_LIMITED_API
Victor Stinnerd3f08822012-05-29 12:57:52 +020066PyAPI_FUNC(int) _PyComplex_FormatAdvancedWriter(
67 _PyUnicodeWriter *writer,
68 PyObject *obj,
69 PyObject *format_spec,
70 Py_ssize_t start,
71 Py_ssize_t end);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000072#endif
Eric Smith58a42242009-04-30 01:00:33 +000073
Guido van Rossumf9fca921996-01-12 00:47:05 +000074#ifdef __cplusplus
75}
76#endif
Neal Norwitz638437f2002-10-04 12:43:02 +000077#endif /* !Py_COMPLEXOBJECT_H */