complexobject.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Complex number structure */
  2. #ifndef Py_COMPLEXOBJECT_H
  3. #define Py_COMPLEXOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef struct {
  8. double real;
  9. double imag;
  10. } Py_complex;
  11. /* Operations on complex numbers from complexmodule.c */
  12. #define c_sum _Py_c_sum
  13. #define c_diff _Py_c_diff
  14. #define c_neg _Py_c_neg
  15. #define c_prod _Py_c_prod
  16. #define c_quot _Py_c_quot
  17. #define c_pow _Py_c_pow
  18. #define c_abs _Py_c_abs
  19. PyAPI_FUNC(Py_complex) c_sum(Py_complex, Py_complex);
  20. PyAPI_FUNC(Py_complex) c_diff(Py_complex, Py_complex);
  21. PyAPI_FUNC(Py_complex) c_neg(Py_complex);
  22. PyAPI_FUNC(Py_complex) c_prod(Py_complex, Py_complex);
  23. PyAPI_FUNC(Py_complex) c_quot(Py_complex, Py_complex);
  24. PyAPI_FUNC(Py_complex) c_pow(Py_complex, Py_complex);
  25. PyAPI_FUNC(double) c_abs(Py_complex);
  26. /* Complex object interface */
  27. /*
  28. PyComplexObject represents a complex number with double-precision
  29. real and imaginary parts.
  30. */
  31. typedef struct {
  32. PyObject_HEAD
  33. Py_complex cval;
  34. } PyComplexObject;
  35. PyAPI_DATA(PyTypeObject) PyComplex_Type;
  36. #define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type)
  37. #define PyComplex_CheckExact(op) (Py_TYPE(op) == &PyComplex_Type)
  38. PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);
  39. PyAPI_FUNC(PyObject *) PyComplex_FromDoubles(double real, double imag);
  40. PyAPI_FUNC(double) PyComplex_RealAsDouble(PyObject *op);
  41. PyAPI_FUNC(double) PyComplex_ImagAsDouble(PyObject *op);
  42. PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op);
  43. /* Format the object based on the format_spec, as defined in PEP 3101
  44. (Advanced String Formatting). */
  45. PyAPI_FUNC(PyObject *) _PyComplex_FormatAdvanced(PyObject *obj,
  46. char *format_spec,
  47. Py_ssize_t format_spec_len);
  48. #ifdef __cplusplus
  49. }
  50. #endif
  51. #endif /* !Py_COMPLEXOBJECT_H */