1use crate::object::*;
2use std::os::raw::{c_double, c_int};
3use std::ptr::addr_of_mut;
4
5#[repr(C)]
6#[derive(Copy, Clone)]
7// non-limited
8pub struct Py_complex {
9 pub real: c_double,
10 pub imag: c_double,
11}
12
13#[cfg(not(Py_LIMITED_API))]
14extern "C" {
15 pub fn _Py_c_sum(left: Py_complex, right: Py_complex) -> Py_complex;
16 pub fn _Py_c_diff(left: Py_complex, right: Py_complex) -> Py_complex;
17 pub fn _Py_c_neg(complex: Py_complex) -> Py_complex;
18 pub fn _Py_c_prod(left: Py_complex, right: Py_complex) -> Py_complex;
19 pub fn _Py_c_quot(dividend: Py_complex, divisor: Py_complex) -> Py_complex;
20 pub fn _Py_c_pow(num: Py_complex, exp: Py_complex) -> Py_complex;
21 pub fn _Py_c_abs(arg: Py_complex) -> c_double;
22 #[cfg_attr(PyPy, link_name = "PyPyComplex_FromCComplex")]
23 pub fn PyComplex_FromCComplex(v: Py_complex) -> *mut PyObject;
24 #[cfg_attr(PyPy, link_name = "PyPyComplex_AsCComplex")]
25 pub fn PyComplex_AsCComplex(op: *mut PyObject) -> Py_complex;
26}
27
28#[repr(C)]
29#[derive(Copy, Clone)]
30// non-limited
31pub struct PyComplexObject {
32 pub ob_base: PyObject,
33 pub cval: Py_complex,
34}
35
36#[cfg_attr(windows, link(name = "pythonXY"))]
37extern "C" {
38 #[cfg_attr(PyPy, link_name = "PyPyComplex_Type")]
39 pub static mut PyComplex_Type: PyTypeObject;
40}
41
42#[inline]
43pub unsafe fn PyComplex_Check(op: *mut PyObject) -> c_int {
44 PyObject_TypeCheck(ob:op, tp:addr_of_mut!(PyComplex_Type))
45}
46
47#[inline]
48pub unsafe fn PyComplex_CheckExact(op: *mut PyObject) -> c_int {
49 (Py_TYPE(ob:op) == addr_of_mut!(PyComplex_Type)) as c_int
50}
51
52extern "C" {
53 // skipped non-limited PyComplex_FromCComplex
54 #[cfg_attr(PyPy, link_name = "PyPyComplex_FromDoubles")]
55 pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject;
56 #[cfg_attr(PyPy, link_name = "PyPyComplex_RealAsDouble")]
57 pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double;
58 #[cfg_attr(PyPy, link_name = "PyPyComplex_ImagAsDouble")]
59 pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double;
60 // skipped non-limited PyComplex_AsCComplex
61 // skipped non-limited _PyComplex_FormatAdvancedWriter
62}
63