python27_sys/
floatobject.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use libc::{c_char, c_double, c_int};

use crate::object::*;
use crate::pyport::Py_ssize_t;

#[repr(C)]
#[derive(Copy, Clone)]
struct PyFloatObject {
    #[cfg(py_sys_config = "Py_TRACE_REFS")]
    pub _ob_next: *mut PyObject,
    #[cfg(py_sys_config = "Py_TRACE_REFS")]
    pub _ob_prev: *mut PyObject,
    pub ob_refcnt: Py_ssize_t,
    pub ob_type: *mut PyTypeObject,
    pub ob_fval: c_double,
}

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
    pub static mut PyFloat_Type: PyTypeObject;
}

#[inline(always)]
pub unsafe fn PyFloat_Check(op: *mut PyObject) -> c_int {
    PyObject_TypeCheck(op, &mut PyFloat_Type)
}

#[inline(always)]
pub unsafe fn PyFloat_CheckExact(op: *mut PyObject) -> c_int {
    let u: *mut PyTypeObject = &mut PyFloat_Type;
    (Py_TYPE(op) == u) as c_int
}

pub const PyFloat_STR_PRECISION: c_int = 12;

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
    pub fn PyFloat_FromString(str: *mut PyObject, pend: *mut *mut c_char) -> *mut PyObject;
    pub fn PyFloat_FromDouble(v: c_double) -> *mut PyObject;
    pub fn PyFloat_AsDouble(pyfloat: *mut PyObject) -> c_double;
    pub fn PyFloat_GetInfo() -> *mut PyObject;

    pub fn PyFloat_GetMax() -> c_double;
    pub fn PyFloat_GetMin() -> c_double;
    pub fn PyFloat_ClearFreeList() -> c_int;
}

pub unsafe fn PyFloat_AS_DOUBLE(pyfloat: *mut PyObject) -> c_double {
    (*(pyfloat as *mut PyFloatObject)).ob_fval
}