xref: /third_party/python/Include/floatobject.h (revision 7db96d56)
1
2/* Float object interface */
3
4/*
5PyFloatObject represents a (double precision) floating point number.
6*/
7
8#ifndef Py_FLOATOBJECT_H
9#define Py_FLOATOBJECT_H
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14PyAPI_DATA(PyTypeObject) PyFloat_Type;
15
16#define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type)
17#define PyFloat_CheckExact(op) Py_IS_TYPE(op, &PyFloat_Type)
18
19#define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN)
20
21#define Py_RETURN_INF(sign)                          \
22    do {                                             \
23        if (copysign(1., sign) == 1.) {              \
24            return PyFloat_FromDouble(Py_HUGE_VAL);  \
25        }                                            \
26        else {                                       \
27            return PyFloat_FromDouble(-Py_HUGE_VAL); \
28        }                                            \
29    } while(0)
30
31PyAPI_FUNC(double) PyFloat_GetMax(void);
32PyAPI_FUNC(double) PyFloat_GetMin(void);
33PyAPI_FUNC(PyObject*) PyFloat_GetInfo(void);
34
35/* Return Python float from string PyObject. */
36PyAPI_FUNC(PyObject*) PyFloat_FromString(PyObject*);
37
38/* Return Python float from C double. */
39PyAPI_FUNC(PyObject*) PyFloat_FromDouble(double);
40
41/* Extract C double from Python float.  The macro version trades safety for
42   speed. */
43PyAPI_FUNC(double) PyFloat_AsDouble(PyObject*);
44
45#ifndef Py_LIMITED_API
46#  define Py_CPYTHON_FLOATOBJECT_H
47#  include "cpython/floatobject.h"
48#  undef Py_CPYTHON_FLOATOBJECT_H
49#endif
50
51#ifdef __cplusplus
52}
53#endif
54#endif /* !Py_FLOATOBJECT_H */
55